Is there any way to programmatically change the number of rows shown without having to manually select from the dropdown?
I know how to change the default number of rows already. When the table first loads, I want it to load all the rows, and then "refresh" the table to maybe only show the first 10 rows. But I want to refresh the table programmitcally instead of having to select a number from the dropdown.
My issue is that if the default number of rows is less than the total number of rows, then when the hidden rows are shown after changing the dropdown number or by paging through the rows, those rows do not have all the css nor js functionality that I attributed to all the rows. For some reason only the default shown rows have all the functionality, and rows later showed do not.
I figure the simplest way to fix this with the least amount of code is to just load all rows by default and then programmitically change how many rows are being showed to only show the first 10 or so.
Thanks for any help.
At first you should set datatables as variable:
var oTable = $('#some_selector').dataTable({
//some properties
})
and then you can set settings on the fly:
var oSettings = oTable.fnSettings();
oSettings._iDisplayLength = 5;
and simply redraw your datatables with new settings:
oTable.fnDraw();
previous answer did not work for me, could be that I'm using a newer version of DT. to set displayLength to 20 this worked for me:
table.context["0"]._iDisplayLength = "20";
table.draw();
I'm using datatables 1.10.10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With