Adobe Dreamweaver Forums



Last 10 THreads :         Opening a file in navpane from toolbar (Last Post : ChrisRousset - Replies : 0 - Views : 1 )           »          Help importing PNG sequence (Last Post : []MULISH - Replies : 0 - Views : 1 )           »          Problems importing PNG sequence (Last Post : []MULISH - Replies : 0 - Views : 1 )           »          Flash CS4 grey Icons in the Tool Panels are hard to see (Last Post : rnfw - Replies : 0 - Views : 1 )           »          Strip EXIF camera data from PSD files? (Last Post : Russell_Proulx@adobeforums.com - Replies : 2 - Views : 3 )           »          CSH Calls for Merged CHM's (Last Post : TrentSnake - Replies : 0 - Views : 1 )           »          Image Replacement (Last Post : WhatNow - Replies : 0 - Views : 1 )           »          Embedding Flash SWF Skin in External Site (Last Post : QADesign - Replies : 0 - Views : 1 )           »          Compatible issue with ie6 (Last Post : zhtjlong - Replies : 0 - Views : 1 )           »          Re: Photoshop CS4 is a disaster (Last Post : Paulo_Skylar@adobeforums.com - Replies : 0 - Views : 1 )           »         


User Info Statistics
Go Back   Adobe Dreamweaver Forums > Macromedia Software > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 11-03-2008, 04:38 AM
matecito
 
Posts: n/a
Diggs:
Default Sorting datagrid columns numerically...

Howdy,

Pretty new to AS3, but thought I'd see if you can help me out here.

I have a datagrid with some numeric columns. I created an item itemRenderer to
add commas to those columns. But now the columns won't sort numerically. I
saw some code that I have attached, the problem is, the code references the
columns by name "testvalue." and I need it to work generically, no matter what
column I am sorting.

Help?

<?xml version=?1.0? encoding=?utf-8??>
<mx:Application xmlns:mx=?http://www.adobe.com/2006/mxml? layout=?absolute?>
<mx:XMLList id=?testdata?>
<testdata> <name>a</name> <testvalue>1</testvalue> </testdata>
<testdata> <name>aa</name> <testvalue>11</testvalue> </testdata>
<testdata> <name>ab</name> <testvalue>12</testvalue> </testdata>
<testdata> <name>b</name> <testvalue>2</testvalue> </testdata>
<testdata> <name>ba</name> <testvalue>21</testvalue> </testdata>
<testdata> <name>bb</name> <testvalue>22</testvalue> </testdata>
<testdata> <name>c</name> <testvalue>3</testvalue> </testdata>
<testdata> <name>d</name> <testvalue>4</testvalue> </testdata>
<testdata> <name>e</name> <testvalue>5</testvalue> </testdata>
<testdata> <name>f</name> <testvalue>6</testvalue> </testdata>
<testdata> <name>g</name> <testvalue>7</testvalue> </testdata>
</mx:XMLList>

<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.SortField;
import mx.collections.Sort;

private function sortNumeric(obj1:Object, obj2:Object):int {
var value1:Number = (obj1.testvalue == '' || obj1.testvalue == null) ? null :
new Number(obj1.testvalue);
var value2:Number = (obj2.testvalue == '' || obj2.testvalue == null) ? null :
new Number(obj2.testvalue);

if (value1 < value2) {
return -1;
} else if (value1 > value2) {
return 1;
} else {
return 0;
}
}
]]>
</mx:Script>

<mxataGrid x=?10? y=?10? dataProvider=?{testdata}? id=?dgTest? width=?400?
height=?300?>
<mx:columns>
<mxataGridColumn headerText=?text? dataField=?name? />
<mxataGridColumn headerText=?number as text? dataField=?testvalue? />
<mxataGridColumn headerText=?number as number? dataField=?testvalue?
sortCompareFunction=?sortNumeric? />
</mx:columns>
</mxataGrid>
</mx:Application>



Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 04:14 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk