flow icon indicating copy to clipboard operation
flow copied to clipboard

Access to Data Provider data from outside

Open TatuLund opened this issue 8 years ago • 16 comments

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.

TatuLund avatar Aug 10 '18 10:08 TatuLund

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

unkis avatar Sep 01 '18 07:09 unkis

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].

ttsanton avatar Jan 15 '19 13:01 ttsanton

The method makes another query to the backend, so please what is the reason for the usage of this method ? @TatuLund @ttsanton

  1. is it to be able to make any type of query to the backend similarly as the component would ?
  2. 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 DataProvider that provides in the event the latest used Query and related data (if any additional data)
  • having a listener + event in DataProvider that 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.

pleku avatar Jan 16 '19 07:01 pleku

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.

TatuLund avatar Jan 16 '19 13:01 TatuLund

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.

ttsanton avatar Apr 17 '19 12:04 ttsanton

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)); });

ekocbiyik avatar Aug 08 '19 19:08 ekocbiyik

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
  2. Show a sum, count or similar in a grid footer cell, based on the column data

Are there more?

Artur- avatar Oct 02 '19 09:10 Artur-

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
  2. 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.

fhaman avatar Dec 12 '19 15:12 fhaman

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 avatar Mar 03 '20 11:03 rmuller

@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 ?

jorndp avatar Apr 10 '20 14:04 jorndp

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?

mehdi-vaadin avatar May 20 '20 11:05 mehdi-vaadin

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

pleku avatar Jul 06 '20 16:07 pleku

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 avatar Dec 16 '20 11:12 garaei

@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.

pleku avatar Dec 16 '20 11:12 pleku

Was this backported to 14 LTS?

mthome avatar Jul 26 '21 18:07 mthome

@pleku I'm on 14.9.x, but I cannot find the grid.getLazyDataView() method? Was it not backported?

rolfwoll avatar Aug 22 '23 13:08 rolfwoll