如何在浮动表单面板中刷新网格面板的商店?

Posted

技术标签:

【中文标题】如何在浮动表单面板中刷新网格面板的商店?【英文标题】:How to refresh grid panel's store within a floating form panel? 【发布时间】:2013-07-19 19:58:35 【问题描述】:

我正在开发这个 ExtJS 4 应用程序,我在其中负责管理应用程序用户。

表单像窗口一样弹出floating: true

var user_grid_form = Ext.create('Ext.form.Panel',

    xtype       : 'form-grid',
    frame       : true,
    title       : 'User Information',
    floating    : true,
    draggable   : true,
    closable    : true,
    closeAction : 'hide',
    bodyPadding : 5,
    layout      : 'column',
    closeAction : 'destroy',
    width       : 532,
    items       : 
    [
        user_grid,
        user_textfield
    ],
    buttons :
    [
       
            text    : 'Save Edits',
            icon    : 'images/save.png',
            handler : handleUpdates
       ,
       
            text    : 'Delete User',
            icon    : 'images/delete.png',
            handler : handleDeletes
       
    ]
).show();  

user_grid 是我的窗口面板中显示usernames 的网格

现在,问题是当我选择用户名时,就像jhony 并按Delete User 我的handleDeletes 通过Ajax 更新数据库。但后来我尝试刷新user_grid,但它不起作用。 删除后,用户应该会从user_grid消失

这是我在handleDeletes里面尝试做的:

user_store.splice(ind, 1);      // I removed `jhony` from `user_store` 
                                // which is the `store` for `user_grid`             
user_grid.getView().refresh();  // Now trying to refresh and NO ERRORS NO ACTIONS

感谢任何线索。

【问题讨论】:

【参考方案1】:

其实你想做的是:

user_grid.getStore().remove(yourRecord); //remove record from the store and also from the grid view
user_grid.getStore().sync(); //send changes to the server

【讨论】:

【参考方案2】:

代替

user_grid.getView().refresh(); 

试试

user_grid.store.load();

如果在服务器端执行删除,则无需在存储上执行任何其他操作(拼接)。

【讨论】:

【参考方案3】:

感谢您的回答dbrin,但没有奏效。

我认为没有必要触摸user_grid 网格面板。我只需要更新它是store。 商店有data,一旦我这样做,一切正常:

user_store.splice(ind, 1);  
u_store.load(user_store);
// u_store is the store that has user_store data

【讨论】:

以上是关于如何在浮动表单面板中刷新网格面板的商店?的主要内容,如果未能解决你的问题,请参考以下文章

如何在表单面板中添加网格面板?

ExtJS:过滤网格面板,但不是商店?

Extjs - 在添加带有商店数据的网格面板时获取“类型错误:名称未定义”

重新配置 extjs 4.1 中未刷新商店

ExtJs Gridpanel 存储刷新

ExtJs 编辑器网格面板的问题