How to highlight newly added items in Grid?

I have a Vaadin Grid with a lazy data provider. I would like to add a listener that would be called whenever new rows are added. That way I could mark the new rows as “new” so that the user can notice them. I could not find a suitable listener, is there one?

You could mark the record and then use a style Grid | Components | Vaadin Docs

The issue is when do I mark the record?

When I detect the data in the db has changed, I call dataView.refreshAll() , so Vaadin then calls the provider with a new query and updates the UI accordingly. I am pretty sure Vaadin doesn’t just drop and readds all the rows. So it must already compute what rows are new and which ones are unchanged.

I would basically like to listen a hook that would give me that diff.

I don’t think there is a diff and what if the newly created record is not visible?

My solution would be to add a changed date to the database record and create the style based on that

A lazy dataprovider is not loading the entire db so there is no way the grid can know if there is new row or not (since it might be not loaded). You can do it with a timestamp (when the grid has been refreshed the last time and show rows created after) or also if you suppose that the only way to add rows is through the Vaadin application then you can add a new row and push an event row XXX has been added, then you can refresh the other grids (if applicable) and display the new row (highlighted).
The other issue is that the new highlighted row can be hidden and not “new” when the user will scroll down. You could save a timestamp per user with the last time he saw it but I’m pretty sure it’s a bad idea :smile:

I realized the records actually already have a timestamp :man_facepalming:. So I could just highlight all records that have timestamp within the last n seconds.

But I also need to un-highlight them once they become older. I guess I could just check every 5 seconds and change their style if they become older? :thinking:

This will require a refresh of the grid every 5 seconds

Maybe this is too often but you should try

Thank you

At least once you add another record and use refreshAll all records are refreshed, showing the older record as not-highlighted anymore