2012-01-20 66 views
2

我開發使用ExtJS的電網分頁複選框網格列表。在執行頁面導航時,我需要記住所選記錄。EXTJS 3.3.3電網

詳細說明: 1)轉到頁:1和選定的行1,2和3 2)現在導航頁面:2 3)回到頁:1 4)的行1,2和作爲選擇

有沒有在網格中的任何API,它處理這種功能,已經選定3應該顯示?

在此先感謝。

回答

2

感謝您的答覆。通過實現一個插件來實現我的設計。該插件看起來,

Ext.namespace('Ext.ux.plugins'); 

Ext.ux.plugins.CheckBoxMemory = Ext.extend(Object, 
{ 
    constructor: function(config) 
    { 
     if (!config) 
     config = {}; 

     this.prefix = 'id_'; 
     this.items = {}; 
     this.idProperty = config.idProperty || 'id'; 
    }, 

    init: function(grid) 
    { 
     this.view = grid.getView() 
     this.store = grid.getStore(); 
     this.sm = grid.getSelectionModel(); 
     this.sm.on('rowselect', this.onSelect, this); 
     this.sm.on('rowdeselect', this.onDeselect, this); 
     this.store.on('clear', this.onClear, this); 
     this.view.on('refresh', this.restoreState, this); 
    }, 

    onSelect: function(sm, idx, rec) 
    { 
     this.items[this.getId(rec)] = true; 
    }, 

    onDeselect: function(sm, idx, rec) 
    { 
     delete this.items[this.getId(rec)]; 
    }, 

    restoreState: function() 
    { 
     var i = 0; 
     var sel = []; 
     this.store.each(function(rec) 
     { 
     var id = this.getId(rec); 
     if (this.items[id] === true) 
      sel.push(i); 

     ++i; 
     }, this); 
     if (sel.length > 0) 
     this.sm.selectRows(sel); 
    }, 

    onClear: function() 
    { 
     var sel = []; 
     this.items = {}; 
    }, 

    getId: function(rec) 
    { 
     return rec.get(this.idProperty); 
    } 
}); 

這個插件被稱爲從束腰爲,

Ext.grid.Gridpanel({ 
store: 'someStore', 
plugins: [new Ext.ux.plugins.CheckBoxMemory({idProperty: "recordID"})] 

}); 

希望這有助於一些之一。

+0

2007年4月,sencha.com/forums上的用戶evant實現完全相同。這裏是鏈接:https://www.sencha.com/forum/showthread.php?45723-problem-in-grid-pagination&highlight=getselectionmodel – JosefMadrid

1

我不覺得有什麼。您需要將選定記錄的ID存儲在某個單獨的存儲/陣列中,並在頁面更改時使用它重新應用選擇。

+0

我想,在earlierby陣列中存儲所選擇的行,並使用selectRows(陣列)我強調的記錄。但這裏有一個問題。假設如果在頁面:1中選擇具有ID 1,2和3的行並且移動到頁面:2,則選擇頁面2中的行1,2和3。所以我不認爲在分頁網格中存儲行ID不適合。 – AJJ

+1

這就是我談論記錄ID而不是行ID的原因。有些東西可以無形地指示要突出顯示的記錄,例如數據庫中的主鍵。 – Mchl

+0

謝謝Mchl。我有你的答案,它的作品! – AJJ

0

你可以把一個MixedCollection對象在全球範圍內跟蹤這些記錄。這將允許您存儲不同對象類型的全局設置。