I have written a following code for my datatables which fills up the table with contents from my DB like this:
if (datatable != null)
datatable.destroy();
datatable = $('#tableProducts').DataTable({
"pageLength": 50,
"bLengthChange": false,
"processing": true,
"serverSide": true,
"filter": true,
"orderMulti": false,
"bSort": false,
"ajax": {
"url": "/Bulk/LoadData/",
"type": "POST",
"data": {
"username": $(".sellerInput").val(),
"drange": $(".select2").val()
},
success: function (data) {
}
},
"columns": [
{
"targets": -1,
"data": "ImageURL",
"name": "Title",
"render": function (data, type, row) {
return '<td><img src=' + data + '></td>';
},
"autoWidth": true
},
{
"data": "Sales",
"name": "QuantitySold",
"render": function (data, type, row) {
return '<td>' + data + '</td>'
},
},
{
"data": "CurrentPrice",
"name": "CurrenctPrice",
"render": function (data, type, row) {
return '<td> <b>$ ' + data + '</b></td>'
},
}
]
});
And this works just fine if I don't specify the success callback. If I specify the success callback like this ( also shown in code above):
"ajax": {
"url": "/Bulk/LoadData/",
"type": "POST",
"data": {
"username": $(".sellerInput").val(),
"drange": $(".select2").val()
},
success: function (data) {
// some custom code here and + filling up datatable with data from my DB...
}
},
The problem here is if I specify the success callback and then update other parts of my HTML page, then the datatable doesn't loads up the data in DB..
My question is, how can I manually specify the data source for datatable if I override the datatable's success callback function in order to update more parts of my HTML page insteade of just the datatable itself?
Can someone help me out ?
From the docs :
So simply use
instead.
You can use
dataSrc
instead ofsuccess
to get the response dataTry this:
Note: Also you are trying to send extra param's as
username
anddrange
, so in DataTable we should use"data":function(d){
as function to send extra paramOfficial Documentation