Skip to content

Add convenient API to set items from the DataView #15978

@jcgueriaud1

Description

@jcgueriaud1

Describe your motivation

I would like an easy access to replace my items in the AbstractListDataView.

Describe the solution you'd like

I would like this method:

    @Override
    public AbstractListDataView<T> setItems(Collection<T> items) {
        Objects.requireNonNull(items, NULL_COLLECTION_ERROR_MESSAGE);
        final ListDataProvider<T> dataProvider = getDataProvider();
        dataProvider.getItems().clear();
        dataProvider.getItems().addAll(items);
        dataProvider.refreshAll();
        return this;
    }

Describe alternatives you've considered

First I wanted to do:

grid.setItems(items);

But you are losing all the listener on the dataprovider/dataview.
I also tried:

GridListDataView<XX> dataView = subsidyRequestGrid.setItems(dataProvider);
...
dataView.removeItems(oldItems);
dataView.addItems(newItems);

But the performance is really bad (since it checks if the item is in the dataprovider).

My current solution is:

dataProvider.getItems().clear();
dataProvider.getItems().addAll(subsidyRequests);
dataProvider.refreshAll();

But it requires a bit of knowledge (refreshAll, where to find the items) and the AbstractListDataView is hiding this complexity into convenient methods.

Additional context

Few other improvements:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions