Datatables pagination using server side

Datatables pagination using server side

adamtarshisadamtarshis Posts: 9Questions: 0Answers: 0
edited December 2012 in Plug-ins
I am trying to implement datatable server side pagination.

My table initialization:
oTable = $jq("#conflicts").dataTable(
{
"sScrollY": "400px",
//"bScrollCollapse": true,
"sAjaxSource": "/conflicts/conflictsRest/fetchConflicts",
//"iDisplayLength": 100,
//"sPaginationType": "scrolling",
"sPaginationType": "full_numbers",
"sScrollX" : "100%",
"sScrollXInner" : "1200",
"bPaginate": true,
"bAutoWidth": false,
"bJQueryUI": true,
"bProcessing" : true,
"bStateSave" : true,
"bSortable": false,
//"bRetrieve" : true,
"bServerSide" : true,
//"bFilter" : true,
//"sDom": 'TW<"clear">lfrtip',
"oTableTools": {
"sSwfPath": "../uiframework/jQuery-js/dataTable/copy_csv_xls.swf"
},
"oColumnFilterWidgets": {
"aiExclude": [ 0, 1,4,5,6,9,10,11,12,13,15,16,17,18, 19, 21, 22,23, 24,25 ]
},
"aoColumnDefs": [{ "bVisible": false, "aTargets": [5,6, 15, 16, 17,18, 19, 21,22,24,25] }],
"aoColumns": [
{"sWidth" : "0px"},
{"sWidth" : "0px"},
{"sWidth" : "0px"},
{"sWidth" : "0px"},
{"sWidth" : "100px"},
{"sWidth" : "0px"},
{"sWidth" : "0px"},
{"sWidth" : "100px"},
{"sWidth" : "100px"},
{"sWidth" : "100px"},
{"sWidth" : "200px"},
{"sWidth" : "150px"},
{"sWidth" : "100px"},
{"sWidth" : "50px"},
{"sWidth" : "100px"},
{"sWidth" : "0px"},
{"sWidth" : "0px"},
{"sWidth" : "0px"},
{"sWidth" : "0px"},
{"sWidth" : "0px"},
{"sWidth" : "100px"},
{"sWidth" : "0px"},
{"sWidth" : "0px"},
{"sWidth" : "100px"},
{"sWidth" : "0px"},
{"sWidth" : "0px"}
],
"fnInitComplete": function(oSettings, json) {
// this.fnAdjustColumnSizing();
// this.fnDraw();
},
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push({ "name": "dealId", "value": dealId });
$jq.ajax( {"dataType": 'json',
"type": "POST",
"async": false,
"url": sSource,
"data": aoData,
"success": addToTable} );
}
}
);

The initial call is going thru fine but the subsequent pagination calls are firing the server request continuously without waiting for user action. Also idislaystart value always starts with 0 every time the request get fired. Is there any way to handle it better?

Thanks

Replies

  • adamtarshisadamtarshis Posts: 9Questions: 0Answers: 0
    If i remove the ajax req from fnServerData and use SAjaxSource (GET request), then pagination is working properly. Am i doing something wrong using fnServerData?
  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    You aren't calling the callback function ( `fnCallback` in your code). That much be called so DataTables can perform the actions it needs to once the new data has been loaded.

    Allan
  • adamtarshisadamtarshis Posts: 9Questions: 0Answers: 0
    Thanks Allen, i got it only after seeing the api..Its really cool feature...
    Also whenever i call fndraw it is firing a server request as bServerSide is true. Is there a way to just redraw the table without calling server side using the same config on datatable?

    Do i need to manipulate fnSettings to handle the same?
This discussion has been closed.