<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:AdvancedDataGrid x="238" y="99" width="549" height="196" dataProvider="{dp}" sortExpertMode="true"> <mx:columns> <mx:AdvancedDataGridColumn headerText="name" dataField="name"/> <mx:AdvancedDataGridColumn headerText="money" dataField="money" sortCompareFunction="mySortFunction" itemRenderer="DataRender"/> </mx:columns> </mx:AdvancedDataGrid> <mx:Script> <!--[CDATA[ import mx.controls.Alert; import mx.collections.ArrayCollection; [Bindable] private var dp:ArrayCollection=new ArrayCollection( [{name:"chen",money:5500},{name:"kite",money:1500}, {name:"chen",money:2500},{name:"simth",money:9500}, {name:"youh",money:1500},{name:"zhang",money:3500}]); //排序回调函数 两个参数 1在2上面 返回-1 反之 private function mySortFunction(Obj1:Object,Obj2:Object):Number { var value1:Number=Obj1.money; var value2:Number=Obj2.money; if(value1<value2) {return -1} if(value1>value2) {return 1} else{ return 0; } } private function applyFilter():void { if(this.dp.filterFunction==null) { this.dp.filterFunction=this.filterNames; } this.dp.refresh(); } private function filterNames(item:Object):Boolean { var math:Boolean=true; if(filterText.text!="") { var name:String=item["name"]; var filter:String=this.filterText.text; if(!name||name.toLowerCase().indexOf(filter.toLowerCase())<0) { math=false; } } return math; } ]]--> </mx:Script> <mx:Form x="296" y="305" width="439" height="77"> <mx:FormItem label="name"> <mx:TextInput id="filterText" change="applyFilter()"/> </mx:FormItem> </mx:Form> </mx:Application>