I am currently working in a Spring project and I am using jquery datatables for tables. I am able to bring the data to tables but I am not able to paginate it. The first page has records 1-10 and second page bring record 101-110. Here is the code I have used
Service layer code:
How do I paginate using PagingandSorting repository?
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
--- Martin Fowler
Partheban Udayakumar wrote:I didn't know what to do so I hard coded it to 0. So we will have to retrieve the page number and pass it to the method is it?
When you're not sure, don't hardcode anything. In fact, stop all coding and think logically. These are computers - they follow a logical sequence. Think like them, and the pieces fall into place.
Forget about jquery, datatables, spring and PagingAndSortingRepository, and start thinking about the sequence:
Only way for server to know current page number is for client to pass it. If you hardcode that to 0 on server side, it's bound to always return the first page of results!