darrachequesne / spring-data-jpa-datatables

Spring Data JPA extension to work with the great jQuery plugin DataTables (https://datatables.net/)
Apache License 2.0
440 stars 174 forks source link

How can I use Pagination? #117

Closed sebasira closed 4 years ago

sebasira commented 4 years ago

I've been using this for a long time and really love it. I'd like to reduce the rendering/request time when loading a big list of data.

I've notice that from the server side I'm returning EVERY registry from DB and pass it to the DataTable.

I've never use Pagination / Pageable and I'd like to. Can you guide me on how to achive it using this library? I don't know if I should do it in the server or is there a way to instruct spring-data-jpa-datatables to page the results.

Thanks!

darrachequesne commented 4 years ago

@sebasira hi! the number of results returned by the server is based on the length property in the input here.

I think, in your case, the length must be -1, so every record is fetched, is that the case?

sebasira commented 4 years ago

@darrachequesne thanks for your reply! I've check this because I didn't know what that length was. And after debugging I found it very useful along with the start property. I didn't know about them and I think they would be what I need to use to achieve the pagination.

The problem on my program is that I'm always returning the full list of entities, according to this code:

dataTablesOutput = dataTableRepository.findAll(dataTablesInput);

As you can see the findAll maybe the problem.

I've never use pagination, so I don't know how to implement it in my side. Can you guide me on how can I change my code to make use of those properties? Thank you and please excuse my lack of knowledge.

EDIT

I can confirm that the dataTablesInput has the correct properties of start and length of the requested page and length selected. For example if I choose 25 items per page, the value lenght is 25 and also the start property has the value of the page number selected

sebasira commented 4 years ago

I try to change the findAll method use another one, but the only options I had where findAll and findOne.

This is the code of my Repository:

@Repository
public interface UsuarioDataTableRepository extends DataTablesRepository<Usuario, String> {
}
sebasira commented 4 years ago

Please DISMISS this issue... It's already working paginated I just did not realize that. After exploring and understanding size and start, I started debugging a see that the size of the data attribute is the specified length.

I was confused by recordsTotal and recordsFiltered which shows the whole size of the Table