0

Following is the code found in data table website in order to remove the paging.

    $(document).ready(function() {
    $('#example').DataTable( {
        "paging":   false
    } );
} );

My question is how to enable and disable paging on button click.

as when i call DataTable function second time to same table. It shows error that data table is already initiated and im calling it second time.

2
  • 1
    simply recreate the dataTable using destroy: true and paging: <new value> - despite the suggestions / answers below the lack of a working fiddle tells its own story. Commented Aug 31, 2015 at 12:22
  • thanks , kindly post it answer i will accept it. other answers and either not working or from old libraries Commented Aug 31, 2015 at 21:13

4 Answers 4

1

simply recreate the dataTable using destroy: true and paging:

Sign up to request clarification or add additional context in comments.

Comments

1

I wanted to show only the first 10 rows of the table, but still be able to sort the whole table. But I also wanted the ability to click a link and show the whole table.

Here's what I did: (my table is "ka_ad")

First, turn on paging

table_ad = $('#ka_ad').DataTable({	
	paging: true,
});

Second (optional: I didn't want to display the datatable pagination links and element, so I hid them with css

#ka_ad_length{display: none;}
#ka_ad_paginate{display: none;}     

Lastly, toggle the bPaginate setting (I have a button with an ID of "test"):

$('#test').click( function () {
     //console.log(mytable.settings()[0]['oFeatures']['bPaginate'] ); 
   if(table_ad.settings()[0]['oFeatures']['bPaginate'] == false)
        {
              table_ad.settings()[0]['oFeatures']['bPaginate'] = true;
             $('#test').html('Show All Rows');
        }
   else
        {
              table_ad.settings()[0]['oFeatures']['bPaginate'] = false;
              $('#test').html('Show Fewer Rows');
        }
     table_ad.draw(); 
});

Comments

0

Try like this.

var oTable;
 $(document).ready(function() {
   oTable =  $('#example').DataTable( {
        "paging":   false
    } );

       $('.btn').click( function () {
        oTable.paging= false;
        oTable.fnDraw();
    });

} );

1 Comment

there is no paging method present in the new library. fnDraw is changed to draw().
0

try this:(but i don't guarantee, because, i haven't tested)

var oTable = $('#example').dataTable();

// get settings object after table is initialized
var oSettings = oTable.fnSettings();
oSettings.paging = false;

$(".button").click(function(){
    oSettings.paging = !oSettings.paging;
});

https://www.datatables.net/forums/discussion/16373/enable-disable-features-after-initializing-the-table

1 Comment

the example or function u have shown is from old api. The latest data tables provide settings() function but there is no paging available

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.