Extjs4 生成动态grid

需求:grid的header不确定,可进行灵活配置
解决方法:从后台传递grid  header数据
示例:
Ext.onReady(function(){
	Ext.Ajax.request({
		url: extPath+'/center!autoGrid.action',
		params : {
		action : "query"
		},
		method : 'POST',
		success : function(response) {
		var json = Ext.JSON.decode(response.responseText); //获得后台传递json

		var store = Ext.create('Ext.data.Store', {
		fields : json.fieldsNames,//把json的fieldsNames赋给fields
		data : json.data          //把json的data赋给data
		}); 
		Ext.getCmp("configGrid").reconfigure(store, json.columModle);  //定义grid的store和column
		Ext.getCmp("configGrid").render();



		}
		});
	 
	    Ext.create("Ext.grid.Panel",{
	    	id : 'configGrid',
			name : 'configGrid',
//			selModel : selModel,
//			store : store1, // 这是另外一个store,不这样就会报错,因为真正的stroe还没有生成
			columns : [],
			displayInfo : true,
			emptyMsg : "没有数据显示",
			items : [],
			renderTo:'grid'
	    });
	   
 
})


通过这种方式即可动态获得grid的header

你可能感兴趣的:(extjs4)