Access to Data Provider data from outside
In Flow DataCommunicator.fetchFromProvider(..) method is protected. In Vaadin 8 the equivalent method DataCommunicator.fetchItemsWithRange(..) is public. This is not logical. Moreover, in Vaadin 8 this method has proven to be useful in many use cases. Hence it should be public in Flow also.
this its the important to can do this.
Vaadin Flow Grid. How to select one row programmatically? https://stackoverflow.com/questions/51708773/vaadin-flow-grid-how-to-select-one-row-programmatically/51710518?noredirect=1#comment90522957_51710518
Having this back into this Grid component would be helpful.
My example might be anecdotal, but I have a project that I am migrating from Vaadin 7 to 10+ that used a Grid where a Modal pop-up would appear upon a Row double click. Inside the pop-up, buttons can be found indicating the previous/next row of the Grid. If the Grid was filtered, the pop-up needs to know the current order of the filtered items to stay accurate.
For example, if my grid, normally with rows for [1, 2, 3, 4, 5], is filtered to show only items [1, 3, 5]: If I select [1], the popup should provide a "Next" button that will give me information for [3]. [3] will give me a "Previous" button for [1] and a "Next" button for [5].
The method makes another query to the backend, so please what is the reason for the usage of this method ? @TatuLund @ttsanton
- is it to be able to make any type of query to the backend similarly as the component would ?
- is it to be able to know outside of the component the changed items for the component, e.g. in the case where another component needs the same data ?
It seems to me this method is quite internal and should not be exposed as public regardless of having it so in Vaadin 8 for the wrong reasons. I can think of alterenatives:
- having a listener + event in
DataProviderthat provides in the event the latest usedQueryand related data (if any additional data) - having a listener + event in
DataProviderthat can provide in the event the latest fetched items that were the result of the query
DataCommunicator is quite internal and not even used by all components that support DataProviders. To my understanding things were designed so that it would not be exposed outside of the component implementation.
I agree, that this is not a necessity to access this API via DataCommunicator, if similar API is added to DataProvider that is equally useful. The most common use case is to get list or stream of items matching currently used sorting and filters in UI. I.e. get them in same order as well. For example data export.
One thing that needs also to double checked is the API symmetry related issues. In Vaadin 8 some API return rowIndex, and that produces need to get nth item from data (with same ordering and filtering), you can find example here: https://github.com/TatuLund/GridFastNavigation/blob/vaadin8/GridFastNavigation-addon/src/main/java/org/vaadin/patrik/FastNavigation.java#L193 If similar need exists with Vaadin 10+, similarly also in addition of getting list or stream of items, it can be this.
I'm in agreement with @TatuLund about the helpfulness of bringing in a similar API available if having the method set back to public is the wrong way forward. Having a data export of the filtered set would be helpful for other parts of our application since we have users filtering though grids containing lots of data.
Hi,
I also need an advice for this problem. I found a way. but I think, this way not useful in a large data.
here is my solution @TatuLund
Label itemSize = new Label(invoiceDataProvider.getItems().size() + "");
invoiceGrid.appendFooterRow().getCell(invoiceGrid.getColumns().get(0)).setComponent(itemSize);
invoiceGrid.getDataProvider().addDataProviderListener(e -> {
int size = invoiceGrid.getDataProvider().withConfigurableFilter().fetch(new Query<>()).collect(Collectors.toList()).size();
itemSize.setText(String.valueOf(size));
});
It would be useful to understand the use cases here instead of a proposed solution to change an API method. As I understand from the discussion the cases are:
- Export the data currently shown in a grid, taking into account filtering and sorting
- Show a sum, count or similar in a grid footer cell, based on the column data
Are there more?
It would be useful to understand the use cases here instead of a proposed solution to change an API method. As I understand from the discussion the cases are:
- Export the data currently shown in a grid, taking into account filtering and sorting
- Show a sum, count or similar in a grid footer cell, based on the column data
Are there more?
Being in detail view (viewing an item), scroll to next/prevous item.
It would be useful to understand the use cases here instead of a proposed solution to change an API method. As I understand from the discussion the cases are:
1. Export the data currently shown in a grid, taking into account filtering and sorting
This is a very important use-case in our practice.
Notice there is another one: when a grid is loaded and you want set select one (normally the first one), for instance to show a detail panel of the selected row. Similar to what fhaman said.
@rmuller Exactly that use case : I have a page with a grid and a detailpanel of the selected item. On page load (with a lazy loaded dataprovider) I want to automatically select the first row and show the corresponding details of the item in the detailpanel.
I am now tearing my hear out to accomplish this and get the first item of the dataprovider.
Can i upvote it in the backlog ?
I'm trying to make sure that I correctly understand the exact use case of fetching the next/previous item in a detail-view/popup. Do you expect that after showing the next/previous item in detail-view/popup, the item after/before the currently selected item in the Grid is selected? In other words, should the detail-view/popup be always synced with the Grid?
To be available in Flow 4.0.0.alpha1 and Vaadin 17.0.0.alpha6 by using the data view depending on the data type
grid.getListDataView(); // for in-memory data
grid.getLazyDataView(); // for data fetched lazily from backend
grid.getGenericDataView(); // in case data type not known - limited API
Getting the size of the filtered data and a list of filtered items is such an obvious need, it doesn't need a user vote? Please do something.
@garaei this is possible but for now you need to use Vaadin 18. It will be backported for LTS for 14.5 or 14.6.
Was this backported to 14 LTS?
@pleku I'm on 14.9.x, but I cannot find the grid.getLazyDataView() method? Was it not backported?