怎么动态加载gridPanel中的列
推荐于2016-05-22 · 知道合伙人互联网行家
关注
展开全部
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();
});
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();
});
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询