日期:2014-05-16  浏览次数:20376 次

Extjs动态Grid,JsonStore动态绑定fields问题
项目需求要用ext实现完全动态的Grid,即表头、数据都是可变的,不同业务实体数据可在同一模板页面上实现增删改查功能。参考了网上很多资料,似乎都是先请求得到json格式的fields和data,然后去newGrid及window,这种方式的问题是想刷新数据的话,必须刷新整个页面,也就是重建GridPanel和Window。而我希望的效果是,点击刷新按钮时,只是重新载入数据,就像固定field情况下调用store.load()的效果。测试了好久,发现JsonStore的fields属性似乎必须先定义好,有没有办法在JsonStore中请求后台得到动态的fields数组?
Extjs Grid 动态

------解决方案--------------------
reconfigure( Ext.data.Store store, Ext.grid.ColumnModel colModel ) : void
Reconfigures the grid to use a different Store and Column Model and fires the 'reconfigure' event. The View will be bound to the new objects and refreshed.
Be aware that upon reconfiguring a GridPanel, certain existing settings may become invalidated. For example the configured autoExpandColumn may no longer exist in the new ColumnModel. Also, an existing PagingToolbar will still be bound to the old Store, and will need rebinding. Any plugins might also need reconfiguring with the new data.
Parameters:
store : Ext.data.Store
The new Ext.data.Store object
colModel : Ext.grid.ColumnModel
The new Ext.grid.ColumnModel object
Returns:
void
------解决方案--------------------
那就整个表新建