Hello,
considering the following example code:
Grid<Integer> grid = new Grid<>();
grid.setPageSize(20);
grid.addColumn(i -> i).setHeader("value");
CallbackDataProvider<Integer, Boolean> dataProvider = DataProvider.<Integer, Boolean>fromFilteringCallbacks(
query -> {
AtomicInteger value = new AtomicInteger(query.getOffset());
System.out.printf("offset: %s, limit: %s%n", query.getOffset(), query.getLimit());
return Stream.generate(value::getAndIncrement).limit(query.getLimit());
},
query -> 10_000);
grid.setDataProvider(dataProvider);
I am getting the following output when scrolling fast in the grid:
offset: 0, limit: 20
offset: 20, limit: 40
offset: 660, limit: 80
offset: 1840, limit: 80
offset: 2520, limit: 100
offset: 5120, limit: 100
offset: 5260, limit: 100
offset: 5360, limit: 20
My expectation was, that limit is ALWAYS as high as determined via setPageSize-Method of the grid (so 20 in this example). But on fast scrolling the limit is bigger. Vaadin also seems to not accept less elements (fixing the limit of my stream to 20 will result in IndexOutOfBoundsException)
Considering I have an API which allows max. 20 elements to be fetched I would need to combine multiple api-calls for a single fetching call.
My assumption seems to be confirmed by documentation of [Grid.setPageSize]
(https://vaadin.com/api/platform/14.1.27/com/vaadin/flow/component/grid/Grid.html#setPageSize-int-) and note in this [example]
(https://vaadin.com/docs/flow/binding-data/tutorial-flow-data-provider.html):
The number of items that need to be fetched, query.getLimit(), is set by the component that uses the DataProvider. For example, in Grid component the default number is 50. This number can be changed via its constructor, like Grid grid = new Grid<>(20);, or via its setPageSize method, like grid.setPageSize(20);.
Could anybody please enlighten me if this is a bug or if simply my assumption is wrong?
Best Regards
Olli