Grid - Custom identifier provider?

Hi folks,

What’s the best way to provide a custom key / for a grid with a list of items? I initially thought that Grid.getListDataView().setIdentifierProvider(EntryVO::getUuid); would work, but whatever the identifier provider is set is later overriden by Grid.setItems(List) or Grid.setItems(GridListDataView).

I’d like to be able to refresh an item it is not the same object, but has the same key by calling

grid.getListDataView().refreshItem(entryVO);

TIA,

Slava

setItems returns the provider it has added → there you could apply the identifier or instead of adding a List, you could also set a list data provider yourself using setItems.

1 Like

I do it with grid.setUniqueKeyProvider(EntryVO::getUuid);.
This will not get overridden by later calls of grid.setItems(list);

1 Like

@knoobie I understand changing the generator would cause a refresh on existing data. The list data provider .id() method just returns the item itself if I’m not mistaken.

@Kaspar4 I tried and it didn’t help.

What I’m trying to accomplish is to be able to refresh an item it is not the same object, but has the same key by calling

grid.getListDataView().refreshItem(entryVO);

For the record, after 2 days of trying to make it work, I ended up overriding the getId() of the ListDataProvider. It’s not as elegant as I was hoping to make it, but it works:


      entryListGrid.setItems(new ListDataProvider<>(entryVOs) {

         @Override
         public Object getId(final EntryVO item) {

            return item.getUuid();
         }
      });