Datatables pagination using server side
Datatables pagination using server side
adamtarshis
Posts: 9Questions: 0Answers: 0
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
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
This discussion has been closed.
Replies
Allan
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?