0

I've been trying to implement a sever-side pagination for my project using Spring and Thymeleaf, I was able to read things about how I can make this posible, one is through the use of dandelion datatables wherein I was able to make the integration successful but only in the client side. The second one i tried is using an example I found at http://www.opencodez.com/java/datatable-with-spring-boot.html which was successful but was a bit complicated. Other examples I find are from this and other sites are old, I need a recent example on how I could implement server-side pagination in Spring using thymeleaf and JPA. It would also a big help if it would involve the use of JQuery datatables because of its features.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • Link does not work. – SirKometa May 28 '17 at 20:08
  • oh here- http://www.opencodez.com/java/datatable-with-spring-boot.htm – Emilio Gumayagay May 28 '17 at 20:10
  • Whats wrong with the opencodez example you provided? While you might find it a bit complicated it does showcase the necessary pieces and given you said it was successful it would seem like it answers your question – Sean Carroll May 28 '17 at 20:10
  • I also uploaded the sample that I was able to create here https://github.com/ergumayagay/datatables-server-side.git – Emilio Gumayagay May 28 '17 at 20:11
  • @SeanCarroll I'm looking for something much simpler, something with less code, given I'm quite new to Spring development. I'm also looking for suggestions for other things I could try. – Emilio Gumayagay May 28 '17 at 20:18
  • Most of the code in that link is taking the request that comes from dataTables and building a representation of it on the server to then do a query. You can't really get around that when doing server side processing with datatables. You will find something similar in the dandelion codebase. When I've implemented this in the past I personally preferred to put the code in an argument resolver but that code still needs to exist somewhere – Sean Carroll May 28 '17 at 20:28
  • @SeanCarroll maybe your solution is less complex? can you give me at least a sample – Emilio Gumayagay May 28 '17 at 20:36
  • I dont have a public sample at the moment but it might be something I can throw up github, assuming no one else provides an example. I would also consider looking at the dandelion code (https://github.com/dandelion/dandelion-datatables). Primary code is found in DatatablesCriterias and they provide a argument resolver as well DatatablesCriteriasMethodArgumentResolver. – Sean Carroll May 28 '17 at 20:46
  • @SeanCarroll Oh it looks partly the same with the example provided by opencodez, based on the answer on this https://stackoverflow.com/questions/30363646/spring-jpa-repositories-generic-find-with-dandelion-datatablecriterias question I could use Spring's JPARepository to ease the integration with dandelion datatables, do you have any idea on how I could make this work? I'm looking forward for the sample. Thanks in advance – Emilio Gumayagay May 28 '17 at 21:00
  • The sample in that stackoverflow questions looks like it might come from https://github.com/dandelion/dandelion-datatables-samples/tree/master/datatables-thymeleaf-ajax – Sean Carroll May 28 '17 at 21:19
  • @SeanCarroll I'm actually about to try the sample, the answers though seem pointing out the use of Spring data repository instead of the JPA repository provided by the sample. – Emilio Gumayagay May 28 '17 at 21:37
  • I've used spring data jpa with datatables and it's similar – Sean Carroll May 28 '17 at 23:03
  • @SeanCarroll can you provide me with the right things to read to help me further? – Emilio Gumayagay May 28 '17 at 23:11
  • related: https://stackoverflow.com/questions/18490820/spring-thymeleaf-how-to-implement-pagination-for-a-list – Andrei Epure May 29 '17 at 09:47
  • related: https://www.javacodegeeks.com/2013/03/implement-bootstrap-pagination-with-spring-data-and-thymeleaf.html . Did you try to follow this tutorial? – Andrei Epure May 29 '17 at 09:49
  • related: http://www.baeldung.com/jpa-pagination – Andrei Epure May 29 '17 at 09:50

1 Answers1

1

I was able to do this with Spring-Data's pagination and the Thymeleaf dialect here https://github.com/jpenren/thymeleaf-spring-data-dialect/

Should do exactly what you want I think.

N4zroth
  • 1,334
  • 2
  • 10
  • 25