如何刷新datagrid [英] How to refresh datagrid

查看:287
本文介绍了如何刷新datagrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了dojox.grid.datagrid,我从数组中填入内容,例如页上的最后一个例子。在时间期间,我改变代码中该数组的值。如何刷新该网格的内容?如何从更改的数组中加载新数据?

I create dojox.grid.datagrid and I fill content from array like on example last example on page. During time, I change value of that array in code. How to refresh content of that grid ? How to load new data from changed array ?

推荐答案

要更改网格中的值,您需要更改网格店网格数据被绑定到存储数据,并且网格将根据需要自动更新。

To change values in the grid, you will need to change the value in the grid's store. The grid data is bound to the store data, and the grid will update itself as needed.

所以关键是要了解Dojo的数据api以及Store在Dojo中的工作原理。而不是直接在网格中操作数据,在商店中操作数据。

So the key is to understand Dojo's data api and how stores work in Dojo. Rather than manipulating the data directly in the grid, manipulate it in the store.

理想情况下,商店是您在应用程序运行时操作的数组,您不应该需要将阵列同步到网格。只需使用ItemFileWriteStore作为数据持有者,除非这是不可能的。

Ideally, the store is your array that you manipulate as the application runs and you should not be needing to sync the array to the grid. Just use the ItemFileWriteStore as your data holder unless thats not possible.

此外,使用dojo数据标识api可以在网格中找到项目非常简单,如果可能的话。假设您知道项目在应用程序中更新,删除或更改时,您应该能够根据需要在操作发生时修改网格存储。这绝对是首选方法。如果你不能这样做,你将不得不做一般的提取,并使用onComplete回调来手动同步你的数组,这将是非常缓慢的,不会扩展得很好,在这种情况下,你也可以创建一个新的商店全部一起使用grid.setStore(myNewStore)将其分配给网格

Also, using the dojo data identity api makes it much simple to find items in the grid if that is possible. Assuming you know when an item is updated, deleted, or changed in your application you should be able to modify the grid store as needed when the action happens. This is definitely the preferred approach. If you can't do that you will have to do a general fetch and use the onComplete callback to manually sync your arrays which will be very slow and won't scale well, in which case you may as well just create a new store all together and assign it to the grid with grid.setStore(myNewStore)

这是一个基本的创建,更新和删除操作的小提琴: http://jsfiddle.net/BC7yT/11/

Here is a fiddle with a basic create, update, and delete operation: http://jsfiddle.net/BC7yT/11/

这些

var store = new dojo.data.ItemFileWriteStore({
    data: {
        identifier : 'planet',
        items: itemList
    }
});

更新现有项目:

//If the store is not in your scope you can get it from the grid
var store = grid.store;
//fetchItemByIdentity would be faster here, but this uses query just to show 
//it is also possible
store.fetch({query : {planet : 'Zoron'},
             onItem : function (item ) {

                  var humans = store.getValue(item, 'humanPop');
                  humans += 200;
                  store.setValue(item, 'humanPop', humans);

              }
        });

插入一个新项目:

store.newItem({planet: 'Endron', humanPop : 40000, alienPop : 9000});
               } catch (e) { 
                  //An item with the same identity already exists
               }

删除一个项目:

store.fetchItemByIdentity({ 'identity' : 'Gaxula',  onItem :  function (item ) {
    if(item == null) {
         //Item does not exist
    } else {
        store.deleteItem(item);
    }
}});

这篇关于如何刷新datagrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆