On page change

Trying to run a function on each change of a datatable page (dynamic loading).

onDataRequest will run when data is pulled from the server, but not when going back to a previous page (i.e. data has already been loaded).

onAfterRender is closest - it runs every time the page is changed, however it runs twice (or even more than twice if sorting) whenever data is pulled from server.

How best to capture (just once) when the page is changed?

It is not easy actually, as there is no straight event handler for such action. We will add the onChange event to the pager, so it will be easier in the next update.

If you have a support subscription, please contact us directly, we will provide the updated build ASAP

OK, onChange event will be most welcome. I have been trying onAfterRender for now and noticing a lot of strange behavior. Thank you

Checking back on this - has the event been added to the pager?

Try to use

pager.attachEvent("onAfterPageChange", function(page){
   //do something
});

There is also onBeforePageChange event.

Ups, it seems the latest build somehow misses this patch.

Please PM me if you need a fixed build ASAP

If you could make sure it gets into 4.2 that would be good.

I may PM you if I come back around to this piece of work before 4.2 is out.

Thanks Maksim

Yep, the fix is in the 4.2 branch for sure now.