Skip navigation
Currently Being Moderated

How to sort the datagrid or dataprovider by number

Jun 13, 2012 10:24 AM

Tags: #flex

Some how my database got out of order (when viewed visually through phpmyadmin). Sometimes the rows are displayed in the phpmyadmin 3,1,2 instead of 1,2,3. Consequently when I retrieve the rows from the database to php and then to the flex datagrid, the rows are displayed 3,1,2 like the database. I think I may have reset the database and fixed it; However I would like to have a fail-safe way to insure the datagrid always displays the rows numerically in order by the image_no of each row retrieved from the database.

 

I found this to learn from, but am having trouble making it work.

http://www.flexafterdark.com/docs/Flex-CollectionSorting

 

The code below has no effect on the order displayed in the grid. Can someone help me make this work. Thanks.

 

import spark.collections.Sort;

import spark.collections.SortField;

 

private function getImagesResult(event:ResultEvent):void {
   images = event.result.image as ArrayCollection;

 

   var sortField2:SortField = new SortField("image_no");
   sortField2.numeric = true;
   sortField2.descending = true;
   images.sort = new Sort();
   images.sort.fields = [sortField2];
   images.refresh();
}

 

<mx:DataGrid dataProvider="{images.source}">
   <mx:columns>
      <mx:DataGridColumn dataField="image_no" />
      <mx:DataGridColumn dataField="image" />
   </mx:columns>
</mx:DataGridColumn>

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points