-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DataTablesRepositoryImpl.findAll(...) sometimes not returns the requested rows #23
Comments
What's happening is that your request from 749 to 829 does not match an actual page, in Spring Data terms. The (quite fancy) behaviour of the Scroller plugin (the |
Yes this behavior is exactely the problem! :-( However, even with a "normal" pagination, the
Fortunately, in the case of "normal" pagination with server-side processing, DataTables is always requesting the full length of the page, even if the last page contains less remaining items. :-) At this point, I see 2 solutions to make spring-data-jpa-datatables working with the Scroller plugin:
package org.springframework.data.jpa.datatables.domain;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
public class DataTablesPageRequest implements Pageable {
private int offset;
private int limit;
private Sort sort;
/**
* Constructor for DataTablesPageRequest.
*
* @param limit
* maximum number of results
* @param offset
* index of first result
* @param sort
* sort option
*/
public DataTablesPageRequest(final int offset, final int limit, final Sort sort) {
this.offset = offset;
this.limit = limit;
this.sort = sort;
}
@Override
public int getPageSize() {
return limit;
}
public void setLimit(final int limit) {
this.limit = limit;
}
public int getLimit() {
return limit;
}
public void setOffset(final int offset) {
this.offset = offset;
}
@Override
public int getOffset() {
return offset;
}
public void setSort(final Sort sort) {
this.sort = sort;
}
@Override
public Sort getSort() {
return sort;
}
@Override
public Pageable next() {
throw new RuntimeException("Method not available in this implementation.");
}
@Override
public Pageable previousOrFirst() {
throw new RuntimeException("Method not available in this implementation.");
}
@Override
public Pageable first() {
throw new RuntimeException("Method not available in this implementation.");
}
@Override
public boolean hasPrevious() {
throw new RuntimeException("Method not available in this implementation.");
}
@Override
public int getPageNumber() {
throw new RuntimeException("Method not available in this implementation.");
}
} (note that the 5 last overloaded methods should never be called in our context). What do you think about that? |
Thanks for the detailed analysis! I've just published v2.5 with your suggested change, could you try it and tell me if I got something wrong? |
I've just tested the new version 2.5 and it works very well with the Scroller plugin. :-) |
This method does not returns enough rows in some cases:
For example: I use the jQuery DataTables with the Scroller plugin for displaying a list of 830 items. The scrolling zone has a dynamic height, thus a dynamic number of displayed rows. When I scroll down to the very bottom of the list, this request is sent to the server:
in which we notice these parameters:
so the web client should receive the last 81 results, from indexes 749 to 829 (=749+81-1, because the first result's index is 0). Actually, it receives 81 results, but from indexes 729 to 810 ! Therefore, the displayed items are incorrect.
This bug seems to be located in the DataTablesUtils.getPageable method, at this row:
The text was updated successfully, but these errors were encountered: