最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to refresh dojo gridx after the memory store has changed? - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited Jul 3, 2013 at 15:23 Cjxcz Odjcayrwl asked Jul 3, 2013 at 14:39 Cjxcz OdjcayrwlCjxcz Odjcayrwl 22.9k42 gold badges149 silver badges230 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

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.

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()
发布评论

评论列表(0)

  1. 暂无评论