Select the data grid row based on id field

I have a datagrid with some columns including id, client etc
data grid

The container and grid is created from code like this
comtainer and grid

Now when I select some rows and the respective ids are saved in a list
Now when i go to next page and come back to previous page i need to select the rows based on the id list. Basically how can i maintain the selection during pagination

Tried dataGrid.setSelected and thrown IllegalStateException: Datasource doesn’t contain items error

Hi,

When a page is changed it means that a new set of entities is loaded, so DataGrid “forgets” about previous ones. If you store all selected entities and tries to revert selection when navigation though different pages, then you need to filter what you’re passing to setSelected by checking if current data container items (container.getItems()) contains a value.

Regards,
Gleb

Hi,
Here in loaddata method i am getting the whole 50 rows of List OF KeyValueEntity
And in keyvalue entity i have an id.
So each time i loaddata(Basically when page changes) i am fetching loadData and i am filtering this using the ids i have maintained globally and then i set the filtered list ( List of KeyValueEntity) using setSelected()
This is exactly i am doing and i am recieving thrown IllegalStateException: Datasource doesn’t contain items error

Is any thing wrong i am doing

Without investigating your code, I can’t give any suggestions. Could you please attach a small demo project that reproduces the issue?

I found one observation
dataGrid.setSelected(List of Some jmix entities) it will work i tested and confirmed
But when we try dataGrid.setSelected(List of KeyValueEntity) it will not work

I tried to create a demo. But its taking time.
I need to confirm this one. Wether selected() is supported for KeyValueEntity or list of KeyValueEntity