Sometimes we need to do a gird, but Gird's column name is changing, we need to find out the column name from the database, that is to say we want to implement a dynamic gird.
The following code is the way I implement dynamic gird, simple but powerful, the data is a read JSON file, the actual use can be in the background to the data in the map and then into the JSON format of the string, JSON format to conform to the format I gave.
The first is JSON data:
{" data": [ { "number": "1", "field1": "A", " field2": "B", "field3": "C" }, { " Number ":" 2 "," field1 ":" D "," field2 ":" E ", " field3 ":" F " }, { " number ":" 3 ", " Field1 ":" G "," field2 ":" H ", " field3 ":" I " } ], " Columnmodle ": [ { " text ":" Ordinal ", " dataindex": "Number", "width": +, "locked": True }, { "text": "Field 1", " Dataindex ":" Field1 " }, { " text ":" Field 2 ", " Dataindex ":" Field2 " }, { " text ":" Field 3 ", " Dataindex ":" Field3 " } ], " fieldsnames ": [ { " name ":" Number " }, { " name": "Field1" }, {" name": "Field2" }, { "name": "Field3" } ]}
Then the JS file:
Ext.onready (function () {Ext.Ajax.request ({url: "Page/data/test1.json", params: {},success:function (response, config {json = Ext.util.JSON.decode (response.responsetext); var store = new Ext.data.JsonStore ({Data:json.data,fields:json. Fieldsnames}); var column_ = Json.columnmodle;var Grid = new Ext.grid.Panel ({title: ' Dynamic Table ', Region: ' Center ', xtype: ' Locking-grid ', //Type lock table Split:true,renderto:ext.getbody (), Height:300,width:1200,columns:column_,store: Store});},failure:function () {}});
To serve:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
ExtJS dynamic gird "column name Dynamic creation"