【问题标题】:How to clear the grid in Extjs如何在 Extjs 中清除网格
【发布时间】:2013-07-24 11:17:10
【问题描述】:

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

提前感谢您的帮助。

【问题讨论】:

  • 我不会在视图中使用 forceFit 选项。建议在网格本身上使用 flex。 (与您的问题无关,但这是一个建议)

标签: extjs4 extjs4.1 extjs4.2


【解决方案1】:

确保您正在使用:

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

如果要删除所有项目,请执行以下操作:

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

但要小心!这将删除所有内容!

【讨论】:

  • 清除存储时不要忘记刷新网格。如果你不这样做,可能会发生奇怪的行为。 grid.view.refresh()
【解决方案2】:

这对我有用:

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

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多