Alert the page no. on jQuery dataTables page change event
Asked Answered
A

1

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

Antefix answered 14/8, 2014 at 10:23 Comment(0)
T
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/

Thyroid answered 14/8, 2014 at 10:47 Comment(3)
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.Ames
@ivanacorovic, "but does not check checkboxes" (?) I dont quite follow you. Perhaps you could create a new question for this issue?Thyroid
I already did, and solved it in the meantime, thanks. #32562159Ames

© 2022 - 2024 — McMap. All rights reserved.