如何重新过滤 dojo DataGrid?
我有一个已经使用 grid.filter(query, rerender) 进行过滤的 DataGrid。如果我添加另一个项目,在调用 save() 后,我会在网格中看到新项目,即使它由于过滤器而不应显示。我在想“好吧,当商店完成保存时,我会再次过滤它。但是在使用相同的查询调用 grid.filter 后,所有行都消失了。有什么想法我可能做错了吗?
过滤网格的代码:
var filterQuery = dijit.byId("filterTextbox").attr("value");
var grid = dijit.byId("grid");
var queryValue = "*";
if(filterQuery != ""){
queryValue += filterQuery + "*";
}
grid.filter({name: queryValue}, true);
将新项目添加到网格的代码
function addItemToGrid(newItemName){
var newItem = {name: newItemName};
var grid = dijit.byId("grid");
var store = grid.store;
store.addItem(newItem);
store.save();
}
I have a DataGrid that I already filtered using grid.filter(query, rerender). If I add another item, after calling save() I see the new item in the grid even though it shouldn't display because of the filter. I'm thinking "ok, I'll just filter it again when the store finishes saving. But after calling grid.filter with the same query all the rows disappear. Any ideas what I might be doing wrong?
Code to filter the grid:
var filterQuery = dijit.byId("filterTextbox").attr("value");
var grid = dijit.byId("grid");
var queryValue = "*";
if(filterQuery != ""){
queryValue += filterQuery + "*";
}
grid.filter({name: queryValue}, true);
Code to add new items to the grid
function addItemToGrid(newItemName){
var newItem = {name: newItemName};
var grid = dijit.byId("grid");
var store = grid.store;
store.addItem(newItem);
store.save();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用:
而不是 store.addItem(newItem);
(addItem 不是将商品添加到商店的标准方法)
Try to use:
instead of store.addItem(newItem);
(addItem is not a standard method to add items into store)
在 addItemToGrid 函数内部,尝试将 onComplete 侦听器添加到您的 save 方法中,并在 onComplete 函数中对网格进行排序或过滤
Inside of your addItemToGrid function, try adding an onComplete listener to your save method and sort or filter the grid in the onComplete function
我遇到了同样的问题,只能通过运行来修复它借助一些 jQuery,网格过滤器会在后台定期进行过滤。这是一些示例代码;希望这可以帮助其他遇到此问题的人。
。
。
。
。
I had the same problem and only managed to fix it by running the grid filter periodically in the background with the help of some jQuery. Here is some sample code; hope this helps someone else having problems with this.
.
.
.
.