在很多情况下, 需要DataGrid初始化结束后立即进行排序.以下分别使用MXML与AS实现:
MXML实现:
mx:DataGridColumn headerText=Price Ranges; sortCompareFunction = "sortRanges">
private function sortRanges(obj1:Object, obj2:Object):int{ var value1:Number = obj1.range.range1; var value2:Number = obj2.range.range1; if(value1 < value2) { return -1; } else if(value1 > value2){ return 1; } else { return 0; } }
var localizationItemsView:ListCollectionView = new ListCollectionView(LocalizationItem.localizationItemAC); localizationItemsView.sort = new Sort(); localizationItemsView.sort.fields = [new SortField("locale")]; localizationItemsView.refresh(); _datagrid.dataProvider = localizationItemsView;
效果:
FlexBuilder编译参数-keep-generated-actionscript <->
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.