2013-07-24 39 views
6

我在Extjs中有一個GridStore,它可以存儲具有兩個網格列的記錄。當網格中存在一條記錄時,如果我刪除了已在服務器端成功刪除的網格,但網格中仍然存在該網格,則存在問題。如何清除Extjs中的網格

示例代碼:

xtype: 'grid', 
    store: 'SampleStore', 
    border: false, 
    width : 542, 
    ref: '../sampleGrid', 
    id: 'sampleGrid', 
    columns: [ 
     { 
     xtype: 'gridcolumn', 
     dataIndex: 'name', 
     header: 'Name', 
     sortable: true, 
    ............. 
    view: new Ext.grid.GridView({ 
    forceFit: true 
    }) 

感謝提前的幫助。

+0

我不會在視圖中使用forceFit選項。建議在網格上使用flex。 (與您的問題無關,但是這是一個建議) – VDP

回答

9

確保您使用的是:

grid.getStore().remove(record); //remove record from grid 
grid.getStore().sync(); //sync with server 

如果你想刪除的所有項目,這樣做:

grid.getStore().removeAll(); 
grid.getStore().sync(); 

但要小心!這將刪除一切!

+0

當存儲被清除時,不要忘記刷新網格。如果你不這樣做,可能會發生奇怪的行爲。 grid.view.refresh() – monstergold

0

這爲我工作:

Ext.ComponentQuery.query('#yourGrid')[0].getStore().removeAll(); 

希望它能幫助。