On-the-fly change of option
On-the-fly change of option
Hi,
I'd like to be able to enable / disable pagination displayed in the browser on-the-fly.
I've attempted this by toggling the 'paging' option, then clearing & re-drawing the table. The table re-draw is intended to achieve the drawing of all data rows when paging=false.
api = $('.dataTable').dataTable()
api.init().paging = !api.init().paging // toggle paging option
console.log( api.init().paging )
api.clear()
api.rows.add(rows).draw();
The console shows the paging-option is changed, the re-draw works ok, but does not remove the pagination controls.
Am I using the wrong method to toggle the option, or is something else needed to re-draw pagination controls?
Answers
There is no option to enable and disable features in DataTables on-the-fly at this time. You would need to destroy the table and then recreate it if that is what you want.
You may also wish to look into this plug-in which can show and hide the paging control when there are multiple pages or not.
Allan
The most convenient way to achieve this I found is to store the complete datatables options set passed to the constructor in a variable, setting destroy to true and wrapping the DataTables constructor call in a function. To toggle paging (or any other option), change it in the options var before calling the constructor wrapper again.