Alert the page no. on jQuery dataTables page change event

sajju217 picture sajju217 · Aug 14, 2014 · Viewed 10.7k times · Source

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

Answer

davidkonrad picture davidkonrad · Aug 14, 2014

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/