Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect page change on DataTable

With DataTable I can order, list, do pagination but I want to detect when the pagination changes, I've seen the API but the only one I can do is change the page but no detect this change.

like image 345
Felix Avatar asked Sep 13 '11 19:09

Felix


2 Answers

You may use fnDrawCallback or fnInfoCallback to detect changes, when next is clicked both of them are fired.

But beware, page changes are not the only source that can fire those callbacks.

For DataTables 1.10.0+

The option is now drawCallback

like image 171
nimcap Avatar answered Sep 17 '22 14:09

nimcap


Paging events are handled in this way,

 $(document).ready(function() {      $('#example')         .on( 'order.dt',  function () { console.log('Order' ); } )         .on( 'search.dt', function () {console.log('Search' ); } )         .on( 'page.dt',   function () { console.log('Page' ); } )         .dataTable(); } ); 

documented in the official website, here http://www.datatables.net/examples/advanced_init/dt_events.html

The length.dt event is fired whenever the table's page length is changed

$('#example').dataTable();  $('#example').on( 'length.dt', function ( e, settings, len ) {     console.log( 'New page length: '+len ); } ); 

http://datatables.net/reference/event/length

More events here

datatables.net/reference/event/

like image 39
duvanjamid Avatar answered Sep 17 '22 14:09

duvanjamid