Scroller: Option to paginate?
Scroller: Option to paginate?
The server software I'm using to generate the AJAX response for scroller uses pagination (page_number and items_per_page) rather than a simple offset / limit, which is what scroller requests.
So my script now makes 2 ajax calls, merges the results, then sends back the slice. Is there any way to adjust the scroller requests to be a page number and items per page instead of offset/length?
Obviously, I've also been trying to rework the server software (https://github.com/api-platform/core/issues/4672).
An example: if scroller requests 100 items starting at 340, I make a request of page 3 with items_per_page=100. Then I make another request of page 4, merge the results and then slice the array to return the result. It works, but it's very inefficient.
Thanks.
Answers
Scroller is probably just using the
serverSide
protocol, as shown in this example. That would be the way to go, to support that.For server-side processing, enable
serverSide
. The protocol is discussed here. Also see examples here. If you download the DataTables repo, there are examples of the server-side scripts in/examples/server_side/scripts
,Cheers,
Colin
Yes, it's using that protocol, but it's sending a request that is an offset and a count, and my server is looking for a page and page length. So I'm trying to figure out how to override the method that buffers the results to use that strategy.
With
serverSide
processing the Datatables client sends the parameterslength
andstart
notoffset
andcount
. The page number can be calculated by withstart / length
. You can do this in your server script or you can useajax.data
as a function (see the examples in the docs) and calculate it there and add that as a parameter that is sent. Something like this example.Kevin
The issue is that scroller is different -- it buffers data when the user scrolls near the of the list loaded in memory, or uses the handles to scroll to a different part of the list.
My server only handles page number and items_per_page, not start/length. Of course I can figure out the start page, but I want to avoid making 2 calls to the server.
Scroller would use the same protocol for server-side processing - you can see that in the example here.
I think you either need to conform to the protocol I posted above, or continue with those steps you're doing to circumvent it.
Colin
Perhaps the author of scroller has some ideas. Obviously, it'd be better if the server offered this option.
The server offers the
serverSide
processing option - there's no value in supporting multiple protocols. You could modify the Scroller code to suit your needs, it's open source, then it could comply with your request method.Colin