2

I'm trying to implement pagination with Grid component. I may be wrong, but unfortunately I'm unable to find a pagination component for Grid in the official Vaadin documentation https://vaadin.com/docs/latest/components/grid. Is there any particular reason why Vaadin Grid component doesn't have a pagination component? I'm only able to see the laze load. But what in case I have 1000k rows, and I'd like to move to the page #100 without scrolling to it though the data set? How to properly implement it with Vaadin Grid?

Another question regarding the com.vaadin.flow.data.provider.DataProvider Looks like I have to implement two different methods in order to return the count and the actual content. But my business service method already returns Page object which contains size and content. How to properly implement DataProvider in such case? I'd like to avoid the second call to database for performance purpose.

alexanoid
  • 24,051
  • 54
  • 210
  • 410
  • Vaadin Grid is paging by scrolling. The question is why you want to scroll to page 100? This is literally the same as using the scrollbar. – Simon Martinelli Aug 03 '22 at 06:14
  • You don't need to provide a count. You can use setItems with just the FetchCallback. The difference is: that without count the scrollbar may shrink during scrolling with count the scrollbar will have the right size from start. You could also set the number of items if you can guess the size. – Simon Martinelli Aug 03 '22 at 06:16
  • https://github.com/vaadin/web-components/issues/2047 – Rolf Aug 03 '22 at 06:24
  • 1
    In theory pagination would be a filter (which then is available in the data providers impl to read). How much this is battling with the page-size of the grid and thus the dataprovider is another question. IMHO a X-Y problem, and bending grid to your will might just be alot work - maybe you are better off picking another component to list your items. – cfrick Aug 03 '22 at 08:22
  • Thanks for your answers. What other options I have in Vaadin component library? Even StackOverflow uses pagination for questions https://stackoverflow.com/questions – alexanoid Aug 03 '22 at 09:21
  • 1
    Please advise if the following solution will work properly with grid - I'll add my own pagination buttons under the grid component. I'll manage the state of pagination outside of the Grid. Inside the button ClickListener I'l simply update the Grid each time the button is clicked with `grid.setItems(page.getContent());` method. Should it work? – alexanoid Aug 03 '22 at 09:48
  • 1
    validated - works fine. – alexanoid Aug 03 '22 at 12:31

0 Answers0