How to catch an event on pagination buttons next/p

2019-02-17 08:42发布

问题:

Can anybody show me an example of how to catch the events on pagination buttons next/previous of datatables? In particular I'm interested for the "next" button. It would really help me if you have an example of how to catch the event of a particular pagination button.

I have searched and in datatable and found that to catch an event you should use this :

$('#example').on('page.dt', function ()).DataTable();

But this catches the events for all the pagination buttons. I want to know how to do it for a particular one("next" in my case).

Thanks in advance

回答1:

Use the code below to attach click event handler to "Next" pagination button.

var table = $('#example').DataTable({
   drawCallback: function(){
      $('.paginate_button.next:not(.disabled)', this.api().table().container())          
         .on('click', function(){
            alert('next');
         });       
   }
});   

See this jsFiddle for code and demonstration.