Extjs4 如何在Extjs中清除网格

Extjs4 如何在Extjs中清除网格,extjs4,extjs4.1,extjs4.2,Extjs4,Extjs4.1,Extjs4.2,我在Extjs中有一个GridStore,它可以存储具有两个网格列的记录。当网格中存在一条记录时,我遇到了一个问题,如果我删除了网格,它在服务器端已被成功删除,但该记录仍然存在于网格中 示例代码: xtype: 'grid', store: 'SampleStore', border: false, width : 542, ref: '../sampleGrid', id: 'sampleGrid', columns: [

我在Extjs中有一个GridStore,它可以存储具有两个网格列的记录。当网格中存在一条记录时,我遇到了一个问题,如果我删除了网格,它在服务器端已被成功删除,但该记录仍然存在于网格中

示例代码:

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

提前感谢您的帮助。

请确保您正在使用:

grid.getStore().remove(record); //remove record from grid
grid.getStore().sync(); //sync with server
如果要删除所有项目,请执行以下操作:

grid.getStore().removeAll();
grid.getStore().sync();
但是要小心!这将删除所有内容

这对我很有用:

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

希望有帮助。

我不会在视图中使用forceFit选项。建议在网格本身上使用flex。(与您的问题无关,但这是一个建议)当存储被清除时,不要忘记刷新网格。如果你不这样做,可能会发生奇怪的行为。grid.view.refresh()