Cjxcz Odjcayrwl
Cjxcz Odjcayrwl

Reputation: 22847

How to refresh dojo gridx after the memory store has changed?

I'm using dojo 1.9 and gridx. The grid is initialized with memory store. But when the data have changed, I update the store but I see no changes applied to grid. It has no refresh() method (like dgrid). However, I've found the following sequence:

            grid.model.clearCache();
            grid.model.setStore(store)
            grid.body.refresh()

It causes the grid to display Loading... message, but nothing more happens.

However, paginator shows the correct number of pages, only the grid container is not rendering the rows.

The example with filters /gridx/tests/test_grid_filter.html from the gridx sources has the same problem: Loading... message, but no data.

So the first question is, is it a bug? If it's not a bug, how should I then tell the grid that the data has changed and it should be reloaded?

Upvotes: 3

Views: 9953

Answers (2)

Cjxcz Odjcayrwl
Cjxcz Odjcayrwl

Reputation: 22847

My previous answer works, and judging from upvotes it was useful for other, but I've found much simpler way, that doesn't require to re-create the store:

grid.model.clearCache();
grid.model.store.setData(items)
grid.body.refresh()

The key operations is clearing the cache, setting new items, and forcing the refresh of browser.

The confusing thing is, that GridX has 'store' property, but it is not the object that is used to present the data. The actual object is the store that is set on the model, so this is the object you need to modify.

Upvotes: 4

Cjxcz Odjcayrwl
Cjxcz Odjcayrwl

Reputation: 22847

The Loading... message was caused by the way I've declared the Grid. I've specified the columns property, the structure needs to be declared, in first line.

The refresh sequence is too short. You need also to re-creade the data store:

var storeData = {
    identifier: 'id',
    items: response.items
};
grid.model.clearCache();
storeData.items = data.result
store = new Memory({data: storeData});
grid.model.setStore(store)
grid.body.refresh()

Upvotes: 2

Related Questions