How to use one ajax datasource with multiple JQuery Datatables
How to use one ajax datasource with multiple JQuery Datatables
sdyson3
Posts: 4Questions: 3Answers: 0
There are two datatables on the same page and both have different columns.
Is there a way to use the same ajax datasource to draw multiple tables? I am trying avoid multiple calls to database.
$('#gvData').DataTable({
"processing": true,
//"serverSide": true,
"bPaginate": false,
"bFilter": false,
"bInfo": false,
"scrollY": "300px",
"scrollCollapse": true,
"bDestroy": true,
"ajax": {
"dataType": 'json',
"contentType": "application/json",
"type": "POST",
"url": "myform.aspx/GetData",
"data": function (d) {
return "{ regDate: '" + regDate + "', cmdName: '" + command + "'}";
},
"dataSrc": function (json) {
adata = json;
return $.parseJSON(json);
}
},
"columns": [{
"data": "Source_Name"
},
{
"data": "Record_Count",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("<a href='" + oData.Record_Count + "' id= '" + iRow + "' style='color: black; text-decoration: none;' onclick='return GetSelectedRow(this, 'completed');' >" + oData.Record_Count + "</a>");
}
}
]
});
This discussion has been closed.
Answers
Use jQuery ajax() to fetch the data then in the
success
function populate the Datatables, as required, usingrows.add()
.Kevin