2012-06-12 17 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