7

The following is working for me:

$('#datatable').on('page.dt', function() {
    alert("changed");
});

Whenever I am changing the page,the alert is shown.But if I want to alert the page no. which is clicked then what's the way

davidkonrad
  • 83,997
  • 17
  • 205
  • 265
sajju217
  • 447
  • 3
  • 7
  • 19

1 Answers1

10

table.page.info() returns the current pagination information. That is current page, number of pages, recordsDisplay, recordsTotal and more.

var table = $('#datatable').DataTable();

$('#datatable').on('page.dt', function() {
    var info = table.page.info();
    var page = info.page+1;
    alert('changed - page '+page+' out of '+info.pages+' is clicked');
});

see demo -> http://jsfiddle.net/qpLtLfaz/

davidkonrad
  • 83,997
  • 17
  • 205
  • 265
  • I have some trouble with page.dt. It happens so that it does execute alerts, but does not check checkboxes, at least not until I visit that page again. – ivanacorovic Sep 14 '15 at 11:08
  • @ivanacorovic, "_but does not check checkboxes_" (?) I dont quite follow you. Perhaps you could create a new question for this issue? – davidkonrad Sep 14 '15 at 11:59
  • I already did, and solved it in the meantime, thanks. http://stackoverflow.com/questions/32561659/select-all-rows-while-using-pagination – ivanacorovic Sep 14 '15 at 12:04