-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting item's index through DataView/DataProvider API #18088
Comments
New `getItemIndex` method in `DataView` affects `ListDataView` and `LazyDataView` implementations. `LazyDataView` introduces in addition a new method `setItemIndexProvider(ItemIndexProvider)`. With `ListDataView`, `getItemIndex` works out-of-the-box with the in-memory data. With `LazyDataView`, it's required to set item index provider first with `setItemIndexProvider(ItemIndexProvider)`. Otherwise `getItemIndex` will throw `UnsupportedOperationException`. Provider can be implemented to fetch correct item index using item and `Query` parameters. `Query` object is set up to fetch all items with sorting and filter. Fixes: #18088
To fix that, I'll make another PR for better support for wrappers with |
…tDataView Adds in `AbstractDataView` a better support for wrapper data providers that implements `DataProviderWrapper`. `AbstractDataView` won't throw exception anymore if wrapped data container is supported by the data view implementation. Adds public `getWrappedDataProvider` method in `DataProviderWrapper`. Related-to: #18088
Adds in `AbstractDataView` a better support for wrapper data providers that implements `DataProviderWrapper`. `AbstractDataView` won't throw exception anymore if wrapped data container is supported by the data view implementation. Adds public `getWrappedDataProvider` method in `DataProviderWrapper`. Related-to: #18088
* feat: support DataProviderWrapper better in AbstractDataView Adds in `AbstractDataView` a better support for wrapper data providers that implements `DataProviderWrapper`. `AbstractDataView` won't throw exception anymore if wrapped data container is supported by the data view implementation. Adds public `getWrappedDataProvider` method in `DataProviderWrapper`. Related-to: #18088 * chore: changed getWrappedDataProvider to package-private
Document how to make callback for an item index with lazy data binding. Related-to: vaadin/flow#18088
* feat: add getItemIndex to DataView New `getItemIndex` method in `DataView` affects `ListDataView` and `LazyDataView` implementations. `LazyDataView` introduces in addition a new method `setItemIndexProvider(ItemIndexProvider)`. With `ListDataView`, `getItemIndex` works out-of-the-box with the in-memory data. With `LazyDataView`, it's required to set item index provider first with `setItemIndexProvider(ItemIndexProvider)`. Otherwise `getItemIndex` will throw `UnsupportedOperationException`. Provider can be implemented to fetch correct item index using item and `Query` parameters. `Query` object is set up to fetch all items with sorting and filter. Fixes: #18088 * chore: moved ItemIndexProvider to component from DataCommunicator * chore: added JavaDoc * chore: pass correct filter for item index provider * chore: update javadoc * chore: added since 24.4 * chore: changed to return Optional<Integer> * Update flow-data/src/main/java/com/vaadin/flow/data/provider/ItemIndexProvider.java Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com> * chore: fixed formatting --------- Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
* docs: update data-provider article for item index provider Document how to make callback for an item index with lazy data binding. Related-to: vaadin/flow#18088 * docs: fix vale findings * First pass at editing. * Vale fix * Second full pass at editing. --------- Co-authored-by: Russell J.T. Dyer <6652767+russelljtdyer@users.noreply.github.com> Co-authored-by: Russell JT Dyer <russelljtdyer@users.noreply.github.com> Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
* docs: update data-provider article for item index provider Document how to make callback for an item index with lazy data binding. Related-to: vaadin/flow#18088 * docs: fix vale findings * First pass at editing. * Vale fix * Second full pass at editing. --------- Co-authored-by: Russell J.T. Dyer <6652767+russelljtdyer@users.noreply.github.com> Co-authored-by: Russell JT Dyer <russelljtdyer@users.noreply.github.com> Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
This ticket/PR has been released with Vaadin 24.4.0.alpha1 and is also targeting the upcoming stable 24.4.0 version. |
…3117) * docs: update data-provider article for item index provider Document how to make callback for an item index with lazy data binding. Related-to: vaadin/flow#18088 * docs: fix vale findings * First pass at editing. * Vale fix * Second full pass at editing. --------- Co-authored-by: Russell J.T. Dyer <6652767+russelljtdyer@users.noreply.github.com> Co-authored-by: Russell JT Dyer <russelljtdyer@users.noreply.github.com> Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
* feat: support DataProviderWrapper better in AbstractDataView Adds in `AbstractDataView` a better support for wrapper data providers that implements `DataProviderWrapper`. `AbstractDataView` won't throw exception anymore if wrapped data container is supported by the data view implementation. Adds public `getWrappedDataProvider` method in `DataProviderWrapper`. Related-to: #18088 * chore: changed getWrappedDataProvider to package-private
* feat: add getItemIndex to DataView New `getItemIndex` method in `DataView` affects `ListDataView` and `LazyDataView` implementations. `LazyDataView` introduces in addition a new method `setItemIndexProvider(ItemIndexProvider)`. With `ListDataView`, `getItemIndex` works out-of-the-box with the in-memory data. With `LazyDataView`, it's required to set item index provider first with `setItemIndexProvider(ItemIndexProvider)`. Otherwise `getItemIndex` will throw `UnsupportedOperationException`. Provider can be implemented to fetch correct item index using item and `Query` parameters. `Query` object is set up to fetch all items with sorting and filter. Fixes: #18088 * chore: moved ItemIndexProvider to component from DataCommunicator * chore: added JavaDoc * chore: pass correct filter for item index provider * chore: update javadoc * chore: added since 24.4 * chore: changed to return Optional<Integer> * Update flow-data/src/main/java/com/vaadin/flow/data/provider/ItemIndexProvider.java Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com> * chore: fixed formatting --------- Co-authored-by: Mikhail Shabarov <61410877+mshabarov@users.noreply.github.com>
Describe your motivation
Vaadin components with listed items can be scrolled to item by index. This isn't always possible, because index of an item might be unknown (e.g. depends on the sorting and filtering).
Thus, an API to get the index by item would be helpful for such uses cases.
Describe the solution you'd like
Proposed solution is to have a new method in
DataView
API for this.Acceptance criteria:
DataView
interface has a methodint getItemIndex(T item)
(or with a similar name) that takes items object and return the index of this item.ListDataView
reuses the existing private methodgetItemIndex
.LazyDataView
has a new method for applying a callback for getting an index from backend:and this callback, if being set by developer, contains a logic for project's backend/database.
This callback is a more convenient way of customising data view, than extending data view class, because then developer would need to create it's own data view class, find a proper data view base class, set up it to component and so on.
If no callback was given,
LazyDataView
throws anUnsupportedOperationException
or similar and highlights that it needs a callback to properly fetch the index.For point 4, a practical example is provided showing how this callback can be implemented, for instance, for relational database.
Additional context
References:
The text was updated successfully, but these errors were encountered: