1 Reply Latest reply on May 26, 2006 10:54 AM by dishmael

    DataGrid Sorting

      Hi everyone, I just started learning Flex and AS 3.0 and I'm having trouble sorting a DataGrid so that its sorted when its displayed (on initialize). I've search around and can't seem to figure it out. I would've expected DataGrid to have a sort() method but no such luck. Can someone provide me an example on how to sort a DataGrid so that its sorted when its shown?
        • 1. Re: DataGrid Sorting
          dishmael Level 1
          I finally figured it out, and to help others, here's how I did it:

          1. Create your service
          <mx:HTTPService id="feed" url=" http://some.host.com/feed.php />

          2. Create an MXML ArrayCollection
          <mx:ArrayCollection id="dgCol" source="{feed.lastResult.root.item}" />

          3. Create a DataGrid
          <mx:DataGrid id="items" dataProvider="{dgCol}" creationComplete="sortGrid();">
          ... your data grid columns go here ...

          4. Create a Script
          function sortGrid():void {
          var dgSort:Sort = new Sort();
          dgSort.fields = [ new SortField( "first column", false, false ) ];
          dgCol.sort = dgSort;