ExtJS dynamic gird "column name Dynamic creation"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.