Question : Flash advanced Datagird sorting

am trying to learn how to sort custom data for certain column for example :-

i have column called "multiP" and this column will contain data as the following :-

list form small to large :-

20/40
100/200
500/1K
2K/4K
5K/10K
100K/200K
400K/800K
1M/2M
5M/10M
100M/200M
400M/800M
800M/2B
800M/10B

please tell me how to sort them correctly from large to small etc..

Thanks

Answer : Flash advanced Datagird sorting

there may be some better options to this but on quicker note I would suggest as below:

----------------
1. In your dataprovider for "multiP" column, add the numeric base value of your list items)
for e.g. (first column is just a placeholder for example, 2nd is say your column "price");
var dp:DataProvider = new DataProvider();
dp.addItem({col1:"Col1_1", price:20});
dp.addItem({col1:"Col1_2", price:100});
dp.addItem({col1:"Col1_3", price:500});
...
...
...

dp.addItem({col1:"Col1_12", price:800000000});

grid.dataProvider = dp;
--------------------

---------------------
2. Create a separate array which will contain the label values against the String key of your numbers added in step 1
for e.g:

var labeldata:Array = new Array();
labeldata["20"] = "20/40";
labeldata["100"] = "100/200";
..
..
..
labeldata["800000000"] = "800M/2B";
-------------------

-----------------------
3. Use the label function for multiP column to show the label values in the format you said, and apply the sortOptions as Numeric because in actual dataProvider you have the values in number :)

//multiP is your column
multiP.headerText = "Price:";
multiP.labelFunction = myLabelFunction;
multiP.sortOptions = Array.NUMERIC;

function myLabelFunction(item:Object):String
{
    return labeldata[String(item.price)];
}
---------------

Hope you'll find it useful.
Random Solutions  
 
programming4us programming4us