我创建了dojox.grid.datagrid,并像页面上的最后一个示例一样从数组中填充内容。随着时间的推移,我在代码中更改了该数组的值。如何刷新该网格的内容?如何从更改后的数组加载新数据?
我创建了dojox.grid.datagrid,并像页面上的最后一个示例一样从数组中填充内容。随着时间的推移,我在代码中更改了该数组的值。如何刷新该网格的内容?如何从更改后的数组加载新数据?
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);
}
}});
var newStore = new dojo.data.ItemFileReadStore({data: {... some new data ...});
var grid = dijit.byId("gridId");
grid.setStore(newStore);
编辑:
Dogo数据表格参考指南(添加/删除行示例,更新表格数据示例)
我想你已经有一个可用的网格,并且想要完全更改网格的存储。
Create a new datastore with your new value :
dataStore = new ObjectStore({ objectStore:new Memory({ data: data.items }) });
(data is the reponse from an ajax request for me)
Change your grid's store with the new one :
grid.store = dataStore;
Render :
grid.render();
这将在最新版本的Dojo 1.9中更新网格存储并刷新网格视图。
grid.store = store;
grid._refresh();
grid.setFilter(grid.getFilter());
使用这个,我可以更新指定的行。这个例子是针对一个树形表格的。
var idx = this.treeGrid.getItemIndex(item);
if(typeof idx == "string"){
this.treeGrid.updateRow(idx.split('/')[0]);
}else if(idx > -1){
this.treeGrid.updateRow(idx);
}