Model listeners in a grid

Hi,

sorry, if I should be able to find to extract this information from the docs, but I am really not.

I have a Grid with a CallbackDataProvider, that is backed by a model. The model has the ability to create, update, or delete users, and I can detect these events using listeners.

Right now, I do a dataProvider.refreshAll() in these events, but that doesn’t seem right.
In terms of code, let me describe this as follows:

// Called, if an existing item has been updated.
public void itemUpdated(Item pItem) {
dataProvider.refreshAll();
// I’d hope for something like
// dataProvider.itemUpdated(pItem)
// Likewise for itemAdded, and/or itemDeleted.
}

For an update, you have refreshItem. But for the rest ( delete/ add) you need to call refreshAll to refresh the grid.

As you have a lazy dataprovider and you have paging and sorting it must call the database when adding or removing rows

@Jean-Christophe.1 I can call refreshItem always, not bothering about current visibility of the item?

@SimonMartinelli I can see that in the case of add. However, in the case of delete, I don’t.

For the delete, if you have a page size of 50 and you delete one row then there is a row missing and it must be fetched from the database. And this addional row would also depend on the sorting or filtering.

@Jean-Christophe.1 I can call refreshItem always, not bothering about current visibility of the item?

It will send the updated data to the client if it’s visible or cached (I’m not sure about the technical implementation).

But in short, you can’t know what is visible on the client side. The Grid will manage it for you.

The only thing you have to care is that your old object and your updated object need be equals (in 90% of the time the you can check the id of your row). The dataprovider is relying on equals to update the correct row.