Updating the "Showing 1 to x of x entries" on server-side reload
Updating the "Showing 1 to x of x entries" on server-side reload
My datatable is being initiated like so:
table = $('#liDetails-table').DataTable( {
'processing' : true,
'serverSide' : true,
ajax : {
url: 'url.php',
type : 'POST',
data: { a:a, li_row_limit:li_row_limit },
dataSrc : 'aaData',
},
'columns' : columns_list,
'pageLength' : li_row_limit,
});
When the page first loads, li_row_limit
is set. However, I have a dropdown that allows the user to change the number of rows they see:
function recall_liDetails(data) {
li_row_limit = data;
table.ajax.reload(); // attempt 1
table.draw(); //attempt 2
}
I'm attempting to update the li_row_limit
variable before datatables does its POST to my php page, but I'm checking the $_POST on the php side and the variable is not updating.
How do I get this variable to update prior to a refresh, so the user can change the number of rows they see from a server-side processing point of view? I need both the POST as well as the datatables option `pageLength`
to update....
This question has an accepted answers - jump to answer
Answers
I think the purpose of asking questions on forums is to show that you will always, 100% of the time, find the answer to your question immediately after you click the submit button.
In my case, I changed the initial
data: { a:a, li_row_limit:li_row_limit },
to reference a PHP $_SESSION variable on my PHP page instead ($rows = $_SESSION['li_row_limit']
, then made an ajax call to update that session variable in the new function,and included this line to actually redraw the table:
table.page.len( li_row_limit ).draw();
Hah - you'd be surprised how often that does hold true! :-)
Good to hear you've got it working now.
Regards,
Allan