<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> <mx:Style> AdvancedDataGrid { alternatingItemColors: #ffffff, #ffffcc; headerColors: #99ccff, #e6eeee; border-width:10px 2px 5px; corner-radius:30px 30px; } </mx:Style> <mx:AdvancedDataGrid x="25" y="10" id="ad" designViewDataType="flat" width="90%" height="60%" fontSize="12" selectionMode="multipleRows" selectable="true" headerSortSeparatorSkin="mx.skins.ProgrammaticSkin" creationComplete="gc.refresh();" itemClick="showValue(event)" styleFunction="myStyle"> <mx:dataProvider> <mx:GroupingCollection id="gc" source="{arr}"> <mx:Grouping> <mx:GroupingField name="year"> <mx:summaries> <mx:SummaryRow summaryPlacement="last group"> <mx:fields> <mx:SummaryField dataField="total" operation="SUM" label="total"/> <mx:SummaryField dataField="year" operation="MAX" label="year"/> </mx:fields> </mx:SummaryRow> </mx:summaries> </mx:GroupingField> </mx:Grouping> </mx:GroupingCollection> </mx:dataProvider> <mx:groupedColumns> <mx:AdvancedDataGridColumnGroup headerText="国家"> <mx:AdvancedDataGridColumnGroup headerText="省-市"> <mx:AdvancedDataGridColumn headerText="城市" dataField="city"/> <mx:AdvancedDataGridColumn headerText="省份" dataField="provice"/> </mx:AdvancedDataGridColumnGroup> <mx:AdvancedDataGridColumn headerText="数量" dataField="total"/> <mx:AdvancedDataGridColumn headerText="年度" dataField="year"> <mx:itemRenderer> <mx:Component> <mx:CheckBox label="{data.year}"/> </mx:Component> </mx:itemRenderer> </mx:AdvancedDataGridColumn> </mx:AdvancedDataGridColumnGroup> </mx:groupedColumns> </mx:AdvancedDataGrid> <mx:Script> <!--[CDATA[ import mx.controls.DataGrid; import mx.collections.SummaryObject; import mx.events.AdvancedDataGridEvent; import mx.events.ListEvent; import mx.collections.GroupingField; import mx.controls.Alert; import mx.collections.ArrayCollection; var arr:ArrayCollection=new ArrayCollection([{year:2009,city:"Shanghai",provice:"上海",total:580000},{year:2009,city:"Beijing",provice:"河北省",total:7852020},{year:2009,city:"Nanjing",provice:"江苏省",total:895145}, {year:2009,city:"Hangzhou",provice:"浙江省",total:4132415},{year:2008,city:"Shanghai",provice:"上海",total:12345},{year:2008,city:"Beijing",provice:"河北省",total:7852020},{year:2008,city:"Nanjing",provice:"江苏省",total:18524}, {year:2008,city:"Hangzhou",provice:"浙江省",total:4132415}]); //AD表格的样式 private function myStyle(data:Object,column:AdvancedDataGridColumn):Object { var output:Object; if(data.children!=null){ output={color:"red",fontWeight:"bold"}; } return output; } // private function summaryFun():SummaryObject{ // // } /*===============右键菜单=================*/ private var meunu1:ContextMenuItem; private var meunu2:ContextMenuItem; public function init():void { meunu1=new ContextMenuItem("最大化"); meunu2=new ContextMenuItem("还原",true); meunu1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuHandle); meunu2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuHandle); var menu:ContextMenu=new ContextMenu(); menu.hideBuiltInItems(); menu.customItems.push(meunu1); menu.customItems.push(meunu2); this.ad.contextMenu=menu; } /*===============右键菜单事件=================*/ private function menuHandle(e:ContextMenuEvent):void { switch(e.target.caption) { case "最大化": this.ad.percentWidth=100; this.ad.percentHeight=100; break; case "还原": this.ad.percentHeight=60; this.ad.percentWidth=60; break; } } /*================选择的值===================*/ private function showValue(event:ListEvent):void { //Alert.show(ad.selectedItem.city+" 省份-"+ad.selectedItem.provice); var arr:Array=ad.selectedItems; txtA.text=""; for(var i=0;i<arr.length;i++) { txtA.text+="城市:"+arr[i].city+"/n省份:"+arr[i].provice+"/n数量:"+arr[i].total+"/n"; txtA.text+="---------------"+"/n" } } ]]--> </mx:Script> <mx:TextArea x="24" y="{this.ad.height+20}" width="300" height="200" id="txtA" fontSize="12"/> </mx:Application>