网格重新加载后删除的行会重新出现
当我按下网格的删除按钮时,该行会从网格中消失,但是当重新加载网格时,该行会重新出现。我尝试了很多命令都没有结果。请帮忙! 提前致谢。
这是创建网格的函数:
// create the data store
var store = new Ext.data.Store({
proxy: new Ext.ux.data.PagingMemoryProxy(myData),
remoteSort:true,
sortInfo: {field:'del', direction:'DESC'},
reader: new Ext.data.ArrayReader({
fields: [
{name: 'id'},
{name: 'name'},
{name: 'category'},
{name: 'price', type: 'float'},
{name: 'active', type: 'int'},
{name: 'actions', type:'text'}
]
})
});
这是删除函数:
buttons: [{
text: 'Add',
iconCls: 'silk-add',
handler: this.onAdd
}, '-', {
text: 'Delete',
iconCls: 'silk-delete',
handler: function(sm, rowIdx,r){
var s = grid.getSelectionModel().getSelections();
for(var i = 0, r; r = s[i]; i++){
// store.remove(r);
var index = store.data.indexOf(r);
if(index > -1){
r.join(null);
store.data.removeAt(index);
}
store.modified.remove(r);
if(index > -1){
store.fireEvent('remove', store, r, index);
}
store.destroyRecord(store, r, index);
}
store.reload();
},
}]
When I press a grid's delete button, the row disappears from the grid but when grid is reloaded that row reappears. I tried a lot of commands with no results. Please help!
Thanks in advance.
This is the function that creates the grid:
// create the data store
var store = new Ext.data.Store({
proxy: new Ext.ux.data.PagingMemoryProxy(myData),
remoteSort:true,
sortInfo: {field:'del', direction:'DESC'},
reader: new Ext.data.ArrayReader({
fields: [
{name: 'id'},
{name: 'name'},
{name: 'category'},
{name: 'price', type: 'float'},
{name: 'active', type: 'int'},
{name: 'actions', type:'text'}
]
})
});
And here is the remove function:
buttons: [{
text: 'Add',
iconCls: 'silk-add',
handler: this.onAdd
}, '-', {
text: 'Delete',
iconCls: 'silk-delete',
handler: function(sm, rowIdx,r){
var s = grid.getSelectionModel().getSelections();
for(var i = 0, r; r = s[i]; i++){
// store.remove(r);
var index = store.data.indexOf(r);
if(index > -1){
r.join(null);
store.data.removeAt(index);
}
store.modified.remove(r);
if(index > -1){
store.fireEvent('remove', store, r, index);
}
store.destroyRecord(store, r, index);
}
store.reload();
},
}]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用 grid.store.reload() 方法重新加载网格时,商店将从源重新加载数据,因此在这种情况下,看起来您正在使用本地数据(数组或 json 字符串?)。所以是的,您正在从存储中删除记录,但随后通过调用重新加载您将重新插入这些记录。最好的选择是删除对象“mydata”中的值,然后调用重新加载。这应该会为您清除记录。
When you reload the grid using the grid.store.reload() method the store is going to reload the data from the source, so in this case it looks like you are using local data (an array or json string?). So yes, you are deleting the record from the store, but then by calling reload you are reinserting those records. Your best bet is to do something where you delete the values out of the object "mydata" and then call reload. That should get rid of the records for you.
我找到了解决方案,如何从 mydata 中删除例如:myData.splice (1,1);
I found the solution, how to delete from mydata for ex: myData.splice (1,1);