?
Solved

datagrid column sorting incorrect

Posted on 2012-09-03
6
Medium Priority
?
535 Views
Last Modified: 2012-09-06
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
0
Comment
Question by:nthawkins1971
  • 3
  • 3
6 Comments
 
LVL 39

Accepted Solution

by:
blue-genie earned 2000 total points
ID: 38362496
the default method is sorted by String, you need to change it to numeric

var yourColumnName:DataGridColumn = new DataGridColumn("whatever");
yourColumnName:DataGridColumn .sortOptions = Array.NUMERIC;
0
 

Author Comment

by:nthawkins1971
ID: 38362513
perfect thanks... slight change to the code and works fine

var AHDiscount:DataGridColumn = new DataGridColumn("AHDiscount");
AHDiscount.sortOptions = Array.NUMERIC;

Open in new window

0
 
LVL 39

Expert Comment

by:blue-genie
ID: 38362763
oh gawd sorry dodgy copy and paste there.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:nthawkins1971
ID: 38362779
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) + "%"

Open in new window

0
 
LVL 39

Expert Comment

by:blue-genie
ID: 38363800
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

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(""));
}

Open in new window

0
 

Author Comment

by:nthawkins1971
ID: 38374578
Thanks a lot blue-genie, works a treat!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question