Specify Sort Functions for DataGrid Columns : DataGridColumn « Grid « Flex






Specify Sort Functions for DataGrid Columns

        


<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">

    <mx:HTTPService id="srv" url="data.xml" resultFormat="object" result="onResult(event)"/>

    <mx:DataGrid id="grid" width="100%" height="100%" dataProvider="{homesForSale}">
        <mx:columns>
            <mx:DataGridColumn headerText="Total No." dataField="total"/>
            <mx:DataGridColumn headerText="Price Ranges [&lt;350K] [350K -600K] [&gt;600K]" 
                dataField="range"
                sortCompareFunction="sortRanges"/>
        </mx:columns>
    </mx:DataGrid>
    <mx:Script>
        
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;

            [Bindable]
            private var homesForSale:ArrayCollection;

            private function initApp():void {
                this.srv.send();
            }

            private function onResult(evt:ResultEvent):void {
                this.homesForSale = evt.result.data.region;
            }

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

      
    </mx:Script>
</mx:Application>
    

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.Link Object attribute with DataGridColumnLink Object attribute with DataGridColumn
2.Set DataGridColumn to not editableSet DataGridColumn to not editable
3.Set header text for DataGridColumnSet header text for DataGridColumn
4.Toggle the visibility for a DataGridColumnToggle the visibility for a DataGridColumn
5.Hide DataGridColumn by setting visible to falseHide DataGridColumn by setting visible to false
6.Using DataGridColumn to control column titlesUsing DataGridColumn to control column titles
7.Using a label function to support a multicolumn DataGridUsing a label function to support a multicolumn DataGrid
8.DataGrid column with an inline item rendererDataGrid column with an inline item renderer
9.Set Column width for DataGridSet Column width for DataGrid
10.Set an Array element to the child tag of the tagSet an Array element to the <mx:columns> child tag of the <mx:DataGrid> tag
11.Hiding and displaying DataGrid columnsHiding and displaying DataGrid columns
12.Sorting a DataGrid on multiple columnsSorting a DataGrid on multiple columns
13.Resizable DataGridColumnResizable DataGridColumn
14.DataGridColumn Header TextDataGridColumn Header Text
15.DataGridColumn editorDataFieldDataGridColumn editorDataField
16.Reference data from ArrayCollection from DataGridColumnReference data from ArrayCollection from DataGridColumn
17.DataGrid with DataGridColumnDataGrid with DataGridColumn
18.DataGrid and DataGridColumnDataGrid and DataGridColumn
19.Use to set optionsUse <mx:DataGridColumn> to set options
20.DataGrid Default Columns
21.DataGrid Explicit Columns
22.Use Labels from ArrayCollection as the column title for DataGridUse Labels from ArrayCollection as the column title for DataGrid
23.Specify an Array element to the child tag of the tagSpecify an Array element to the <mx:columns> child tag of the <mx:DataGrid> tag
24.DataGrid Visible ColumnDataGrid Visible Column
25.Handling a user interaction and passing only data to a function
26.Item renderer that renders an image in a column
27.Use item editorsUse item editors