Ext 动态添加grid 列数
Ext 动态添加grid 列数
在做报表的时候,需要将grid的列数做成活的,列数有数据库里的字段确定,这据需要将grid的列数做成动态的,经过多次实验已成,如下:后台返回的json:
{'action':true,'message':'error!','data':[
{'number':'1','text1': '3','info1': '4','special1': '5'}
],'columModle':[
{'header': '序号','dataIndex': 'number','width':40},
{'header': '编码','dataIndex': 'text1'},
{'header': '名称','dataIndex': 'info1'},
{'header': '金额','dataIndex': 'special1'}
],'fieldsNames':[{name: 'number'},
{name: 'text1'}, {name: 'info1'},
{name: 'special1'}]}
var cm = new Ext.grid.ColumnModel(json.columModle);
var ds = new Ext.data.JsonStore({
data:json.data,
fields:json.fieldsNames
});
var grid = new Ext.grid.GridPanel({
region: 'center',
split: true,
border:false,
cm:cm,
ds:ds
});
grid.render(document.body);
new Ext.Viewport({
layout: 'border',
split: true,
items: [grid]
});