• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Spring Data JPA, PagingandSortingRepository JQuery Datatable

 
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

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?
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if there is any problem in the jquery code, so I'll add this post to the Javascript forum too.

Coming to the Spring part:

Why is page number hardcoded to 0? It should be the page number requested by front end.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Karthik,
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?
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Karthik,

I thought of the logic but I don't know how to implement it. so I am searching answers for it. 0 was hard coded as a initial procedure, just to test. I will definitely try and get back here.
 
Partheban Udayakumar
Ranch Hand
Posts: 499
Spring AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Karthik,

I got it. Page number was the key as you said. I resolved it by passing the page number to the repository.
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good you got it working !
Will close this as resolved then.
 
reply
    Bookmark Topic Watch Topic
  • New Topic