Fix erroneous offset/start behavior #264
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changes ajax-datatables-rails to use the passed in
start
parameter for the SQLOFFSET
value, rather than basing the offset on the calculated page number. I think this is the correct behavior, and mirrors what DataTable's own server side example does.If the start value wasn't an exact multiple of the limit, then previously the database query would not acknowledge intermediate offset values. So, for example, if a request with
start=20&limit=100
was made, ajax-datatables-rails would perform aLIMIT 100 OFFSET 0
query, instead ofLIMIT 100 OFFSET 20
(which is what is believe should happen).I suspect you wouldn't see this issue if you were using explicit page-based pagination where
start
was always a multiple oflimit
. However, if you're using DataTables with infinite scrolling pagination, then the start value might be fairly random. With the previous behavior, infinite scrolling would appear to do strange things, since new requests likestart=20&limit=100
andstart=55&limit=100
might be made, but the responses would continue to contain the same identical 1-100 results.I think I've adjusted the Oracle tests appropriately, but since these don't seem to be passing on Travis CI currently, I'm not entirely sure. But the other databases all seem to be passing.