网格重新加载后删除的行会重新出现

发布于 2024-10-04 15:18:19 字数 1436 浏览 7 评论 0原文

当我按下网格的删除按钮时,该行会从网格中消失,但是当重新加载网格时,该行会重新出现。我尝试了很多命令都没有结果。请帮忙! 提前致谢。

这是创建网格的函数:

// 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

御弟哥哥 2024-10-11 15:18:19

当您使用 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.

摘星┃星的人 2024-10-11 15:18:19

我找到了解决方案,如何从 mydata 中删除例如:myData.splice (1,1);

I found the solution, how to delete from mydata for ex: myData.splice (1,1);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文