在EditorGridPanel中上下移动行

dub*_*dad 2 grid extjs rows extjs3

有没有人知道/在EditorGridPanel中有一个移动行的工作示例(或者知道它为什么不适合我)?我找到了一些例子,我发现的例子使用了这种方法:

// calculate the new index, then remove the record from the store, and re-insert it at the new index
grid.getStore().remove(record);
grid.getStore().insert(index, record);
Run Code Online (Sandbox Code Playgroud)

在我的情况下,这失败了.它在网格中看起来不错,但实际上有2个DELETE http请求被发送到服务器,而没有PUT.当我重新加载页面时,这变得很明显 - 移动的行实际上已被删除.

他是我店的基本配置:

var remoteJsonStore = new Ext.data.JsonStore({
            storeId: 'colStore',
            autoDestroy: false,
            autoSave: true,
            proxy: new Ext.data.HttpProxy({url:'/exercises/collect/data_rows'}),
            restful: true,
            format: 'json',
            disableCaching: false,
            autoLoad: true,
            writer: new Ext.data.JsonWriter({
              encode: false
            }),
            root: 'data',
            idProperty: 'data_row_id',
            fields: recordFields,
            baseParams:{section_id:GridUtils.properties[gridId]['section_id']},
            listeners:{
              exception:function(misc){
                 // stuff....
              },
              beforewrite:function(store, action, rs, options, arg){
                this.baseParams["position"]=rs.rowIndex;
              },
              beforesave:function(store, data){
                 // stuff....                }
              }
            }
});
Run Code Online (Sandbox Code Playgroud)

小智 6

在实现DnD重新排序视图时,我遇到了类似的问题.问题是商店会将每个remove()d记录标记为删除,即使您重新插入它也是如此.

阅读Ext.data.Store的remove()方法的源代码,我找到了一个解决方案:

remove: function(records, /* private */ isMove) {
Run Code Online (Sandbox Code Playgroud)

看到?我们可以传递第二个布尔文章告诉商店我们正在移动记录!但是,当标记为私有而未记录时,我们应该在升级到新版本的框架时注意.

所以最终的解决方案是:

grid.getStore().remove(record, true); // just moving
grid.getStore().insert(index, record);
Run Code Online (Sandbox Code Playgroud)

ExtJS版本:4.1