如何动态添加gridPanel的列
展开全部
Ext.onReady(function() { var sm=new Ext.grid.CheckboxSelectionModel(); var cm=[new Ext.grid.RowNumberer(),sm, {header:"编号", dataIndex:"id", width:65,hidden : true}, {header:"名称", dataIndex:"name", width:65}, {header:"路径", dataIndex:"url", width:65} ] var fd = ["id", "name", "url"]; var store=new Ext.data.JsonStore({ fields:fd }) var data=[{ id:1,name:"xiao",url:"sssssssssss",sex:"male" }] var grid=new Ext.grid.GridPanel({ sm:sm, columns:cm, store:store, width:500, height:400, tbar:[{ text:"生成", icon:"images/icons/add.png", cls:"x-btn-text-icon", handler:function(){ var res = {fields:[{name:"sex"}],columns:[{header:'性别',dataIndex:"sex",width:65}]}; var columns = res.columns; var fields = res.fields; for (var i = 0; i < fields.length; i++) { fd.push(fields[i].name); cm.push(columns[i]); } //重新绑定store及column ss=new Ext.data.JsonStore({ fields:fd }); grid.reconfigure(ss,new Ext.grid.ColumnModel(cm)); ss.loadData(data) } }] }) var win=new Ext.Window({ title:"sssssss", width:700, height:500, layout:"fit", closable:true, items:[grid] }) win.show(); });
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询