我需要一个函数来添加/删除ExtJS 4网格中的列.网格是用Extjs 4编写的.在我谷歌之后,我发现了以下代码.
function reconfigure(store, columns) {
// debugger;
var me = grid;
if (me.lockable) {
me.reconfigureLockable(store, columns);
return;
}
if (columns) {
me.headerCt.removeAll();
me.headerCt.add(columns);
}
if (store) {
store = Ext.StoreManager.lookup(store);
me.bindStore(store);
// me.getView().refresh();
} else {
me.getView().refresh();
}
}
Run Code Online (Sandbox Code Playgroud)
我调用此函数的代码
var store = grid.getStore();
reconfigure(store, fields);
Run Code Online (Sandbox Code Playgroud)
它取代了标题行,但不会刷新数据.我正在使用ExtJs 4.0
小智 5
创造功能
GetProductsGetStore: function(fiels) {
var ret = Ext.create('Ext.data.Store', {
autoLoad: false,
proxy: {
type: 'ajax',
url: '/index.php/ajax/ProductsGet',
reader: {
type: 'json'
},
extraParams: {
currency: '0'
}
},
fields: fiels
});
return ret;
}
Run Code Online (Sandbox Code Playgroud)
和没有商店的gridpanel
this.Product = Ext.create('Ext.grid.Panel', {
width: '100%',
height: 154,
border: 0,
multiSelect: true,
allowDeselect: true,
columns: [
{
text: 'article',
dataIndex: 'article',
flex: 2
},
{
text: 'name',
dataIndex: 'name',
flex: 2
},
{
text: 'price',
dataIndex: 'price',
flex: 1
}
]
});
Run Code Online (Sandbox Code Playgroud)
动态编辑网格
var fields = [
'id',
'name',
'checked',
'price',
'currency',
'src'
];
this.Product.reconfigure(th.GetProductsGetStore(fields));
this.Product.store.load();
Run Code Online (Sandbox Code Playgroud)