Scroller extension doesn't trigger 'page' event?
Scroller extension doesn't trigger 'page' event?
sapot
Posts: 14Questions: 8Answers: 0
I'm using Scroller extension with server side processing and when I scroll down and more data is retrieved from the server, I want to catch an event and do some processing. I was expecting this to trigger the page event as Scroller says it uses the paging functionalities of datatables but it seems it is not triggered?
- Is the page event triggered and I'm doing something wrong?
- In case of negative, should it be triggered and this is a bug?
- In double negative case, is there any other event I can catch representing this? I know about draw and other events but I need a specific one representing when we want to get a new 'page'.
This question has an accepted answers - jump to answer
Answers
The Scroller uses a buffer to load the data. The buffer is larger than the number of rows displayed. The buffer size, controlled by
scroller.displayBuffer
, defaults to 9 pages of data loaded at a time.As you mentioned I don't believe the
page
event is fired by the scroller. The docs state this:It would seem the Scroller doesn't cause any of these conditions.
One option to differentiate scrolling causing a new
draw
event versus searching or sorting might be to use a flag to tell thedraw
event if searching or sorting took place. For example:https://live.datatables.net/cozosiko/2/edit
If this doesn't help then please provide more details of what you are wanting to use the
page
event for. Maybe we can provide a better solution.Kevin
I've got to admit, I'm a little surprised that
page
doesn't trigger as well!Scroller uses paging in the background - it is just completely hidden from the end user. I suspect (I'd need to check my code) that the page event actually comes from the pagination control, rather than the paging implementation in the draw routine of DataTables which is why it isn't happening in this case.
However, as Kevin says, you'd be better using
draw
I suspect anyway.Allan
@allan my understanding is exactly that, the page event is only triggered in the controls code: https://github.com/DataTables/DataTablesSrc/blob/1a157e26e07b798dc72c6bffaf753e09f1863352/js/core/core.page.js#L69
It is not being done inside draw but on the controls processing code.
Should I report it as a bug report?
Or should I report a bug on Scroller to add the trigger of page event? It should be pretty easy to add it before this: but I don't know about it, probably it's not a good separation of concerns having an extension triggering events associated with the core Datatables?
@kthorngren that example is perfect. What I want is exactly to set some variables when a draw comes from paging or when a draw comes from something else. I'm not sure if covering just search and order will cover all sources where I can call draw() but it's a matter of testing.
Either that or I add a custom event on the mentioned line of scroller extension.
Its probably a bug in DataTables core. I saw this bug was filed earlier, which would also resolve this.
Allan