2012-06-12 63 views
2

有没有人知道在EditorGridPanel中移动行的工作示例(或知道为什么它不适合我)? 我发现几个例子,和那些我发现使用这种方法:在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); 

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

He're我店的基本配置:

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....    } 
       } 
      } 
}); 

回答

6

我实施的DnD重新排序视图时,也有类似的问题。问题是,即使您重新插入,商店也会将每个remove()d记录标记为删除。

阅读Ext.data.Store的remove源()方法中,我发现了一个解决方案:

remove: function(records, /* private */ isMove) { 

看到了吗?我们可以通过第二个布尔商店告诉商店我们正在移动记录!但被标记为私有且未记录在案,我们在升级到新版本框架时应该小心。

所以最终的解决方案是:

grid.getStore().remove(record, true); // just moving 
grid.getStore().insert(index, record); 

ExtJS的版本:4.1