nthawkins1971
asked on
datagrid column sorting incorrect
Hi, on the datagrid I have using AS3 when the column is selected as a sort critria it gets this incorrect based onb its values it goes -39, -4, -41, -47, -5, -55... etc please see the screen shot attached for a clearer picture of whats going on... is it because it onyl sorts by the first character? anyway I hope someone can help? many thanks
column-sort.jpg
column-sort.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oh gawd sorry dodgy copy and paste there.
ASKER
no prob... quick one, how come if I add a percentage sign it creates the same problem...
AHDiscount:Math.round(AHTradesXML.tbl_DATA_AHShareNWAX[j].xDiscount*100) + "%"
hey as soon as you add your "%" you're converting it to a string again.
you will need to create a custom sort function.
(i'm assuming your percentage values are whole numbers ie. 5%, not 5.2%);
try this
you will need to create a custom sort function.
(i'm assuming your percentage values are whole numbers ie. 5%, not 5.2%);
try this
AHDiscount.sortCompareFunction = sortPercentage;
function sortPercentage(itemA:Object, itemB:Object):int {
if (toNumber(itemA.AHDiscount) > toNumber(itemB.AHDiscount)) {
return -1;
} else if (toNumber(itemA.AHDiscount) < toNumber(itemB.AHDiscount)) {
return 1;
} else {
return 0;
}
}
function toNumber(element:String):Number{
return Number(element.split("%").join(""));
}
ASKER
Thanks a lot blue-genie, works a treat!
ASKER
Open in new window