在DataGrid初始化时进行排序

Categories: Flex; Tagged with: ; @ October 14th, 2008 10:45

在很多情况下, 需要DataGrid初始化结束后立即进行排序.以下分别使用MXML与AS实现:
MXML实现:

mx:DataGridColumn headerText=Price Ranges; sortCompareFunction = "sortRanges">

sortRange代码:

            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;
                }
            }

AS:

	 	var localizationItemsView:ListCollectionView = new ListCollectionView(LocalizationItem.localizationItemAC);
	 	
	 	localizationItemsView.sort = new Sort();
	 	localizationItemsView.sort.fields = [new SortField("locale")];
	 	localizationItemsView.refresh();
	 	
	 	_datagrid.dataProvider = localizationItemsView;

效果:

image

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.