synaptik synaptik - 7 months ago 37
jQuery Question

Javascript toggle paging on all dataTables

I'm struggling to make a js function that will toggle paging on all the dataTables on my page. What am I doing wrong?

Note: whenever I run

in the Chrome console, I get
as a response.

var globalPaging = true;

function togglePaging() {

globalPaging = !globalPaging;


var oTable = $(this).dataTable();
var oSettings = oTable.fnSettings();
oSettings.aoColumns[1].bPaginate = globalPaging;

var oTableDT = $(this).DataTable();


"bPaginate": globalPaging

Here's a demo:

Update: Here is the solution I went with, derived from Teddy's answer:


The draw() function update your table content only. If you want change other property, maybe you need re-init your table. Draw API:

My example:

    var oTableDT = $(this).DataTable({ 
        "bPaginate": globalPaging,
        "bDestroy": true

This solution has an disadvantage that is you need re-init all your properties.

Note: My FF43 cant run onclick, so I use jquery instead.