In Vaadin 8, The grid functions “edit row” and “scroll to” require the item index. We want to use the functions in a component renderer which contains buttons.
We don’t know how to find the index of the item we want to edit or scrollTo when using a Lazy BackEndDataProvider linked to a DBMS.
There isn’t any automatic way to map indices to items and the other way around. For ListDataProvider, it can be easily done based on the backing list. For BackEndDataProvider it might not be so easy.
One solution is to store the the index for each item in the item itself as a (transient) property.
I’m using a CallbackDataProvider, using rank() over (…) allows me to add an reliable index property to my objects, even if sorting and filtering is used.
still, if I create an new object, save it (insert into …) select it grid.select(Object),
I can’t know it’s index thus can’t call scrollTo(idx).
no click event is triggered on select(), only the select event that has no getRowIndex() method is,
the selected object (getSelectionModel().getFirstSelectedItem() …) returns the new object which doesn’t know about rank,
not the one retrieved by the CallbackDataProvider … painful.
thanks, I saw these 2 but they solve the opposite problem, here we have the object, not the index of the row.
I’ve solved this by capturing the Query object in the lambdas of the CallbackDataProvider constructor,
I can then do use this to make a DB query to retrieve the index of the object, then I can call scrollTo(idx)
int rank = sqlGetRank(item); -> use saved Query object to parametrize the SQL query that uses rank() over (…)
deselectAll();
getDataProvider().refreshAll();
select(object);
if (rank >= 0) scrollTo(rank);
later I thought that if I add a new Item into the DB I should reset the filters before scrolling to it or I might not see it,
I then don’t need to capture the Query object, I simply clear the filters, sqlGetRank(), deselectAll(), refreshAll(), select() and then scrollTo()