fnCallback not able to render Server Side DataTable
fnCallback not able to render Server Side DataTable
I am not able to render server side data in DataTable
My DataTable structure below:
$("#MyTable").DataTable({
"bServerSide": true,
"sAjaxSource": $("#apiUrl").attr("value") + "/myclass/myMethod",
"sAjaxDataProp": "",
"bProcessing": true,
"bVisible": true,
"order": [
[1, "asc"]
],
scrollX: true,
"bAutoWidth": false,
scrollCollapse: true,
"oColReorder": {
"iFixedColumns": 1
},
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": function (msg) {
fnCallback(msg.aaData);
//$("#members").show();
}
} );
},
"columns": [
{ "data": "Id" },
{ "data": "VIN" },
{ "data": "ModelGroupId" },
{ "data": "Mark" }
],
"sPaginationType": "full_numbers",
"bVisible": true
});
I am able to get response from Server as Json, my structure of JSON is given below:
{"aaData":[{"Id":"1","VIN":"VIN345345354345345","ModelGroupId":"10","Mark":"NDE5234"},{"Id":"2","VIN":"VIN345343445345","ModelGroupId":"10","Mark":"NDE5234"},{"Id":"3","VIN":"VIN345343445345","ModelGroupId":"10","Mark":"NDE5234"}],"sEcho":1,"iTotalRecords":3,"iTotalDisplayRecords":3}
But, when I am passing my json data from AJAX success call to fnCallback method, DataTable showing no result, code below
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": function (msg) {
fnCallback(msg);
//$("#members").show();
}
} );
}
Here the problem is that when I am passing json result to fnCallback function as fnCallback(msg), then DataTable showing no result. But when I am passing json data to fnCallback function as fnCallback(msg.aaData) then DataTable able to render 3 records in Table but other information related to paging like Page information from Server is lost as >> sEcho, iTotalRecords, iTotalDisplayRecords are part of msg and not msg.aaData from JSON.
Please, can some one help on this.