Comments (4)
I've just tested the new version 2.5 and it works very well with the Scroller plugin. :-)
Congratulations for sharing your extension of the Spring Data JPA project and for your responsiveness in the implementation of this fix. Merci beaucoup ! ;-)
from spring-data-jpa-datatables.
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 start
is not a multiple of the length
) is indeed not correctly handled.
from spring-data-jpa-datatables.
Yes this behavior is exactely the problem! :-(
However, even with a "normal" pagination, the start
should not supposed to be a multiple of the length
. For example: if you have a total number of 123 items and a page length of 10, the request for the last page could be:
start
=120length
=3 (and not 10 since there's only 3 items on the last page because 123 % 10 = 3)
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:
- Client-side: use the ajax.data option to "correct" the
start
andlength
parameters so thatstart % length == 0
while avoiding loading the full set of data. - Server-side: Adapt the DataTablesUtils.getPageable(...) method so that it instantiate a custom implementation of Pageable, instead of org.springframework.data.domain.PageRequest.
For example:
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?
from spring-data-jpa-datatables.
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?
from spring-data-jpa-datatables.
Related Issues (20)
- Filter by "<column> NOT IN (<input array>)" HOT 2
- how to remove the text - filtered from X total entries HOT 1
- How to Work with UserDTO HOT 2
- Can we search date in data table? HOT 2
- Duplicates items after filtering HOT 2
- Log Exceptions or they are silently lost HOT 4
- Add support for Spring Boot 3.0.0 HOT 3
- Is it possible to use specification for view? HOT 2
- Is it possible to do a regular expression search using ~ in PostgreSQL? HOT 2
- AddOrder doesnt seem to work HOT 2
- Filtering data sometimes throws ORM exception (Hibernate 6.1) HOT 10
- No property 'findAll' found for type 'Class' HOT 4
- Performance issue (suggestions on database indexes) HOT 7
- [question] specifications and counting total records HOT 4
- Show ManyToMany data HOT 1
- enable datatable repositories without using DatatablesJpaRepositoryBean HOT 1
- Order can be null HOT 4
- Specify date format in global/column search when database column is date (Oracle) HOT 4
- Searching for a record with special (national) character "ř" doesn't work HOT 5
- Search Panes Error in Relationship Table HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-data-jpa-datatables.