Ramandeep S
Ramandeep S

Reputation: 345

Pagination and sorting

I am using spring mvc,IOC and hibernate in my project. I am reading the records from the database and displaying them in a grid

I need sorting and pagination on table records

I used jquery tablesorter for sorting. My Problem is that i want to implement server side pagination not client side.So in case of table sorter when somebody will sort some column and click on next page then client side sorting will fail.

Is there library or api for implementing server side pagination and sorting?

Thanks Ramandeep Singh

Upvotes: 0

Views: 1881

Answers (2)

Alan Hay
Alan Hay

Reputation: 23246

If it is an option for you to use Spring Data for your repository layer then this supports server side sort and page out of the box with integrations for your controllers.

http://docs.spring.io/spring-data/jpa/docs/1.4.2.RELEASE/reference/html/repositories.html#web-pagination

I have used it with DisplaTag without any issues but should work with any table component. Configure either the component or Spring Data so the sort/page param names match up.

Also vastly reduces much of the boiler plate code around creating JPA repos. Much of the time all you need do is create an interface and leave the implementation to the library.

Well worth a look.

Upvotes: 1

programsji.com
programsji.com

Reputation: 217

For this purpose, you have to send these values from jsp page to your action method (1)Current Page Number(2) ColumnToSort (3)No of records on page you want to see and you have to apply to some logic on server side to calculate starting and ending record then you can use hibernate query's (1)setFirstResult (2)setMaxResults functions. You can use "order by" in your query for sorting.

Upvotes: 0

Related Questions