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.
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
IF you have a version greater than 1.8, you can use this to hit the page change events:
Hope this helps!
UPDATE:
Some comments have pointed out that using .live() instead of .on() worked for them. Be aware of that you should try both and see which one works best in your particular circumstance! (I believe this may have to do with your version on jQuery, but please comment if you find another reason!)
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.
I've not found anything in the API, but one thing you could do is attach an event handler to the standard paginator and detect if it has changed:
In my case, the 'page.dt' event did not do the trick.
I used 'draw.dt' event instead, and it works!, some code:
'Draw.dt' event is fired everytime the datatable page change by searching, ordering or page changing.
/***** Aditional Info *****/
There are some diferences in the way we can declare the event listener. You can asign it to the 'document' or to a 'html object'. The 'document' listeners will always exist in the page and the 'html object' listener will exist only if the object exist in the DOM in the moment of the declaration. Some code:
//Document event listener
//HTML object event listener
This works form me to scroll to when I click next
An alternative approach would be to register an event handler on the pagination link like so:
Replace "#dataTableID_" with the ID of your table, of course. And I'm using JQuery's ON method as that is the current best practice.