javascript 刷新 Dojo 数据网格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6375052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Refresh Dojo Datagrid
提问by t0mcat
So I am trying to refresh a Datagrid when stores data changes.
所以我试图在存储数据更改时刷新 Datagrid。
//Store for my datagrid
var myStore= new dojo.data.ItemFileWriteStore({ url : '/my/store.html', clearOnClose:true, urlPreventCache:true } );
When I make an ajax call to save/update data for the grid, in callback function of ajax call I call:
当我进行 ajax 调用以保存/更新网格的数据时,在 ajax 调用的回调函数中我调用:
function myCallBack()
{
myStore.close();
Alert("Data Saved Successfully");
}
The function that updates the records in Grid, calls myStore.save()right before exiting. This scenario works fine in FireFox but grid is not refreshing in IE8
更新 Grid 中记录的函数在退出之前调用myStore.save()。 此场景在 FireFox 中运行良好,但网格在 IE8 中无法刷新
Any pointers or help is much appreciated.
非常感谢任何指示或帮助。
回答by t0mcat
回答by Micha Roon
You can also reset the query in order to execute it again. Follow the tutorial in order to set up the page: http://dojotoolkit.org/documentation/tutorials/1.7/store_driven_grid/
您还可以重置查询以再次执行它。按照教程设置页面:http: //dojotoolkit.org/documentation/tutorials/1.7/store_driven_grid/
in the example datagrid with an in memory store:
在具有内存存储的示例数据网格中:
require( ["dojox/grid/DataGrid", "dojo/data/ObjectStore", "dojo/store/Memory", "dojo/domReady!"],
function ( DataGrid, ObjectStore, Memory ) {
var formsList = [
{id:1, name:"Jim", department:"accounting"},
{id:2, name:"Rosenblumentalovitsch", department:"engineering"},
{id:3, name:"Mike", department:"sales"},
{id:4, name:"John", department:"sales"}
];
formStore = new Memory( {data:formsList, idProperty:"id"} );
formGrid = new DataGrid( {
store:dataStore = ObjectStore( {objectStore:formStore} ),
query: {id: "*"} ,
structure:[
{ name:"Form", field:"name", width:"100%" }
]
}, "grid" );
formGrid.startup();
} );
when adding an element to the formStore
the data grid is not automatically refreshed. Here is the addForm function with the refresh:
向formStore
数据网格添加元素时不会自动刷新。这是带有刷新的 addForm 函数:
function addForm( evt ) {
// set the properties for the new item:
var myNewItem = {id:5, name:"Jim 2", department:"accounting"};
// Insert the new item into the store:
formStore.add( myNewItem );
formGrid.setQuery({id: "*"}); //this row executes the query again, thus refreshing the data grid
}