// ActionScript file import mx.controls.AdvancedDataGrid; import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn; import mx.controls.advancedDataGridClasses.AdvancedDataGridColumnGroup; import mx.collections.ArrayCollection; // public var tmpMonthADGDataGrid: AdvancedDataGrid = new AdvancedDataGrid(); public function init():void{ var xml:XML = new XML(); xml = <users> <user> <ID>213001</ID> <name>飞机</name> <courseID>1</courseID> <courseName>computer</courseName> <age>22</age> <adept>computer</adept> </user> <user> <ID>213002</ID> <name>嗨嗨</name> <courseID>2</courseID> <courseName>math</courseName> <age>22</age> <adept>computer</adept> </user> <user> <ID>213003</ID> <name>小强</name> <courseID>3</courseID> <courseName>database</courseName> <age>21</age> <adept>computer</adept> </user> <user> <ID>213004</ID> <name>萧萧</name> <courseID>4</courseID> <courseName>software management</courseName> <age>22</age> <adept>computer</adept> </user> </users> var myadgmonthdata:ArrayCollection =new ArrayCollection(); var tmpGroup:AdvancedDataGridColumnGroup=new AdvancedDataGridColumnGroup(); tmpGroup.headerText = "CourseInfo"; var tmpInfo:AdvancedDataGridColumnGroup = new AdvancedDataGridColumnGroup(); tmpInfo.headerText="Infor"; // myadgmonthdata.addItem(tmpInfo); var tmpqty:AdvancedDataGridColumn=new AdvancedDataGridColumn(); tmpqty.headerText="courseID"; // tmpqty.textAlign="left"; tmpqty.width=60; tmpqty.dataField="courseID"; var tmpcourseName:AdvancedDataGridColumn=new AdvancedDataGridColumn(); tmpcourseName.headerText="courseName"; tmpcourseName.width=60; tmpcourseName.dataField="courseName"; var tmpID:AdvancedDataGridColumn=new AdvancedDataGridColumn(); tmpID.headerText="ID"; tmpID.dataField="ID"; tmpID.width=100; var tmpName:AdvancedDataGridColumn=new AdvancedDataGridColumn("Product"); tmpName.headerText="name"; tmpName.width=100; tmpName.dataField="name"; var tmpAge:AdvancedDataGridColumn=new AdvancedDataGridColumn(); tmpAge.headerText="age"; tmpAge.width=60; tmpAge.dataField="age"; var tmpAdept:AdvancedDataGridColumn=new AdvancedDataGridColumn(); tmpAdept.headerText="adept"; tmpAdept.dataField="adept"; tmpAdept.width=60; tmpGroup.children=tmpGroup.children.concat(tmpqty); tmpGroup.children=tmpGroup.children.concat(tmpcourseName); tmpGroup.children=tmpGroup.children.concat(tmpID); tmpGroup.children=tmpGroup.children.concat(tmpName); tmpGroup.children=tmpGroup.children.concat(tmpAge); tmpGroup.children=tmpGroup.children.concat(tmpAdept); tmpInfo.children = tmpInfo.children.concat(tmpGroup); myadgmonthdata.addItem(tmpInfo); // tmpD.itemRenderer=new ClassFactory(deleteButton); // myadgmonthdata.addItem(tmpID); // myadgmonthdata.addItem(tmpName); // myadgmonthdata.addItem(tmpAge); // myadgmonthdata.addItem(tmpAdept); adg.groupedColumns=myadgmonthdata.toArray(); adg.dataProvider = xml.children(); } 效果图如上图所示 用as实现简单的dataGrid代码如下: import mx.controls.dataGridClasses.DataGridColumn; public var xml:XML = new XML(); public function init():void { xml = <users> <user> <ID>213001</ID> <name>飞机</name> <age>22</age> </user> <user> <ID>213002</ID> <name>嗨嗨</name> <age>22</age> </user> </users>; var dataFields:Array = ["ID","name","age"]; var columns:Array = []; // AdvancedDataGridColumn var column:DataGridColumn = null; for each (var dataField:String in dataFields) { column = new DataGridColumn(); column.dataField = dataField; column.width = 120; //column.headerText = //以后优化时再处理 columns.push(column); } dg.columns = columns; dg.dataProvider = xml.children(); }