Hi,
 
You can use your own sorting method(algorithm) to sort entire grid. Or you
can apply your algorithm on a particualr column.

Look at "DataGrid.sortItems(sortFunc:Function, order):Void" method.
Also look at "DataGridColumn.sortCompareFunction:Function" property
 
DataGrid.sortItems(..) @livedocs:
http://livedocs.macromedia.com/flex/15/asdocs_en/mx/controls/listclasses/Scr
ollSelectList.html#sortItems
DataGrid.sortCompareFunction @livedocs:
http://livedocs.macromedia.com/flex/15/asdocs_en/mx/controls/gridclasses/Dat
aGridColumn.html#sortCompareFunction

 
A quick example to give you an idea..
 
##DataGridSortExample.mxml##
 
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml";
backgroundColor="#FFFFFF">

    <mx:Script>
        <![CDATA[
         
       
          function sortFunc(val1, val2)
          {
           val1 = Number(val1);
           val2 = Number(val2);
        
           if(val1 > val2) {
            return -1;
           }else if(val1 == val2) {
            return 0;
           }else {
             return 1;
           }
          }
          
        
         function getDGDP()
         {
             return [
                        {Artist:"Abdul", Album:"Classical Song",
Price:100.25},
                        {Artist:"Matt", Album:"Classical Song",
Price:200.25},
                        {Artist:"Manish", Album:"Rock", Price:300.33},
                        {Artist:"Sam", Album:"Rock Songs", Price:300.50}    
                            
                     ];
         }
         

  
       ]]>
  
    </mx:Script>
    <mx:Panel title="DataGridColumn Sorting Example" marginTop="10">
        <mx:VBox>
            <mx:DataGrid id="myGrid" width="350" height="100"
creationComplete="event.target.dataProvider = getDGDP();">
                <mx:columns>
                    <mx:Array>
                        <mx:DataGridColumn headerText="Artist"
columnName="Artist"></mx:DataGridColumn>
                        <mx:DataGridColumn headerText="Album"
columnName="Album"></mx:DataGridColumn>
                        <mx:DataGridColumn headerText="Price"
columnName="Price"></mx:DataGridColumn>
                    </mx:Array>
                </mx:columns>
             </mx:DataGrid>
             <mx:Button label="sort grid"
click="myGrid.sortItems(sortFunc);"/>

        </mx:VBox>
    </mx:Panel>
</mx:Application>     

 
hope that helps
 
-abdul


________________________________

From: Matthew Shirey [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 05, 2005 5:20 AM
To: [email protected]
Subject: [flexcoders] Sort Order in a DataGrid


Might someone point me in the right direction for altering the sort order
method(s) for a DataGrid?  It's currently annoying litteral.  I'd like to
alter it so it is case insensitive.  Currently the column orders somewhat
like this:
 
A
B
C
.
.
Z
a
b
c
.
.
.
z
 
while I'd like it to order like:
 
A
a
B
b
C
c
 
etc...
 
I hope someone can throw me in the right direction, thanks!
 
-- Matthew

________________________________

Yahoo! Groups Links


*       To visit your group on the web, go to:
        http://groups.yahoo.com/group/flexcoders/
          
*       To unsubscribe from this group, send an email to:
        [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> 
          
*       Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> . 





 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to