oTable = $('#compounds-list').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": compoundsUrl,
"fnServerData": getCompounds,
"fnInitComplete":addClicks,
});
function addClicks() {
alert(oTable);
//var nodes = oTable.fnGetNodes();
}
oTable = $('#channels').dataTable(
{
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": url,
"fnServerData": getJson,
"fnRowCallback": fnRow,
"sDom": 'tr',
"bAutoWidth": false,
"bSortClasses": false,
"aoColumns":
[
/* SELECT */ { "bSortable": false,
"bSearchable": false},
/* CHAN_NAME */ { "bSortable": false,
"bSearchable": false}
]
})
var oTable_init;
var IntervalID;
function getJson (sSource, aoData, fnCallback)
{
if (this.url.match(/table=2/))
{
if (typeof(oTable_init) != 'undefined') {
clearInterval(IntervalID);
}
else
{
IntervalID = setInterval('oTable2.fnDraw(false)', 1000);
return false;
}
}
$.ajax({
dataType: "json",
type: "POST",
url: sSource,
data: aoData,
success: function (data) {
if (! this.url.match(/table=2/))
oTable_init = data.iTotalDisplayRecords;
fnCallback(data);
},
error: function() {
alert ("Get JSON error");
}
});
}
I.e. I should know number of rows in the first table before XHR of the second table... var cTable = $('#matches').dataTable({
//other properties
"sAjaxSource": //valid reference to a WCF service
"sAjaxDataProp": "ResponseData",
"aoColumns": [
//column-related stuff
],
"fnInitComplete": function () {
var cNodes = cTable.fnGetNodes();
//loop through the nodes and do stuff
}
});
which worked fine. Then, we had to do some user validation between the time we pulled the data and the time we put up the table, so this wouldn't work anymore. I had to use an ajax call and pass the result to the datatable instead, so:
var cTable = $('#matches').dataTable({
//other properties
"aaData": myJson.ResponseData,
"aoColumns": [
//column-related stuff
],
"fnInitComplete": function () {
var cNodes = cTable.fnGetNodes();
//loop through the nodes and do stuff
} //function
}); //datatable
This wouldn't work. I kept getting a "cTable is undefined" error and no data. Once I pulled the fnInitComplete out and ran it afterwards, everything was fine. So, what I'm getting is that you can reference the pointer to the datatable once the initialization is complete, if you are using a direct call to a data source, but if you are passing the result of an ajax call to the datatable you have to wait until the entire datatable sequence executes.
var cTable = $('#matches').dataTable({
"fnInitComplete": function () {
var cNodes = cTable.fnGetNodes();
}
});
var cTable = $('#matches').dataTable({
"fnInitComplete": function () {
var cNodes = this.fnGetNodes();
}
});
It looks like you're new here. If you want to get involved, click one of these buttons!
Get useful and friendly help straight from the source.