Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flash MX DataGrid Custom Sorting

Status
Not open for further replies.

vodius

IS-IT--Management
Sep 13, 2004
2
CA
I'm trying to create datagrid, from XML and then number each record.
But I also need to sort that Datagrid.
E.g. I have:
| ID| FRUIT | COLOR |
=====================================
| 1 | Apple | Green,Red,Yellow |
| 2 | Pear | Green,Yellow |
| 3 | Strawberry | Red |
| 4 | Banana | Yellow |
| 5 | Plum | Black,Blue |
=====================================
I need to sort them by FRUIT in alphabetical order. I can do that:
myGrid.sortItemsBy("FRUIT");
but I need to keep my ID numbers as 1,2,3,4,5. So the final result would look like this:
| ID| FRUIT | COLOR |
=====================================
| 1 | Apple | Green,Red,Yellow |
| 2 | Banana | Yellow |
| 3 | Pear | Green,Yellow |
| 4 | Plum | Black,Blue |
| 5 | Strawberry | Red |
=====================================
Does anybody know how to do that?
Thanks.
 
Solved it myself...
For those who is interested:
after sorting is done,remove that first column and add another column, then add digits from 1 to whatever using loop and setCellData. Here is code:
==================
dp = new Array();
var myColumn = new FGridColumn("Order");
fruitAr = ["apple","strawberry","banana","plum"];
colorAr = ["green", "red", "yellow", "blue"];
for (i=0;i<4;i++){
dp = {ID: i, Fruit: fruitAr, Color: colorAr};
}
myGrid.setDataProvider(dp);
myGrid.sortItemsBy("Fruit");
myGrid.addColumn(myColumn);
for (i=0; i<4; i++){
myGrid.setCellData(i, "Order", i+1);
}
================
Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top