DataTable reDraw but avoid Ajax request
DataTable reDraw but avoid Ajax request
Hello,
I use DataTable to create tables with server side feature through Ajax calls.
At the first page rendering, I use deferLoading to laod my first page and avoid the first Ajax call. This is OK.
But, in my page, I have several DOM manipulations to resize elements and these actions are triggered by the user at his convenience. So, I need to "reDraw" DataTables often to keep a good shape for my tables. And this is the big problem that I cannot solve, at each "reDraw", an Ajax request is sent to the server to refresh the data...
Is there a way to triggered the Ajax request on specific events and avoid to launch requests on all the DataTable Draw ?
Thanks a lot for your support.
DataTable definition :
dataTables[0] = $('#table_num_0').dataTable({scrollY: 600,
scrollX: true,
scrollCollapse: true,
paging: true,
pageLength: 20,
lengthChange: false,
order: [],
searching: false,
info: true,
processing: true,
serverSide: true,
deferLoading: 100,
ajax: {
url: "mvc/models/base/json_admin_sql_request.php",
type: "POST",
data: function (d){
d.sql_request = $('#sql_request').text();
}
}
});
reDraw function :
function adjustDataTables() {
if (typeof dataTables !== "undefined") {
var windowHeight = $(window).height() - 200;
var i = 0;
for (i = 0; i < dataTables.length; i++) {
dataTables[i].fnSettings().oScroll.sY = windowHeight;
dataTables[i].fnAdjustColumnSizing();
dataTables[i].fnDraw();
}
}
}
Replies
Ok, I just notice that I mixed old and new API.
I removed fn* stuff to use :
And I used "vh" unit in the DataTable scrollY definition.
Now the table is OK in all the situation and the Ajax request is only trigger when the user use a real action on the table.
Bye.