Giter Club home page Giter Club logo

Comments (4)

ppermezel-solucom avatar ppermezel-solucom commented on May 25, 2024 1

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.

darrachequesne avatar darrachequesne commented on May 25, 2024

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.

ppermezel-solucom avatar ppermezel-solucom commented on May 25, 2024

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=120
  • length=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:

  1. Client-side: use the ajax.data option to "correct" the start and length parameters so that start % length == 0 while avoiding loading the full set of data.
  2. 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.

darrachequesne avatar darrachequesne commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.