OK, the problem is that we end up executing the formatDate function and sorting those values instead of using your comparator functions on the fields as specified by the actual column.  Here’s a small example that will get you part of the way.  You’ll need to finish it out to get it sorting ascending and descending (for example the headerRelease functionality will need to be made more aware of what header you pressed to know if it should do anything).

 

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns="*" initialize="setup()">

 

            <mx:Script>

            <![CDATA[

            var dFormat:mx.formatters.DateFormatter;

 

            function setup():Void

            {

                        dFormat = new mx.formatters.DateFormatter();

                        var dp:Array = [];

                        for (var i:Number=0; i < 1000; i++)

                        {

                                    dp.push({feedbackCreationDate: new Date(Math.round(Math.random() * 2006), Math.round(Math.random() * 12), Math.round(Math.random() * 31))});       

                        }

                        dg.dataProvider = dp;

            }

           

           

            function sortGrid(a, b) {

                  a = a.feedbackCreationDate.getTime();

                  b = b.feedbackCreationDate.getTime();

                  if (a == b)

                        return 0;

                  else if (a < b)

                        return -1;

                  else

                        return 1;

            }

           

            function formatDate(rowData):String      {

                  return (dFormat.format(rowData.feedbackCreationDate));

            }

           

            ]]>

 

            </mx:Script>

           

            <mx:DataGrid id="dg" headerRelease="dg.dataProvider.sortItems(sortGrid)">

              <mx:columns>

                <mx:Array>

                  <mx:DataGridColumn columnName="feedbackCreationDate" headerText="Date" labelFunction="formatDate" sortOnHeaderRelease="false"

                    />

                </mx:Array>

              </mx:columns>

            </mx:DataGrid>

 

</mx:Application>

 

In answer to your second question there is currently not a way to remove the ordering once you start clicking on headers.  You would need to have a copy of the data in the original order and then re-assign the dataProvider to that copy.

 

Matt

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Nischal Pathania
Sent: Wednesday, October 12, 2005 9:01 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] date sort

 

Everyone:

I have used sortCompareFunction attribute of gridcolumn to resolve date sort issue in my application.

Below is the part of my code

.....
<mx:DataGridColumn headerText="Date" columnName="joinDate" width="100" sortCompareFunction="sortGrid" labelFunction="formatDate" />

.....

function sortGrid(a, b, index) {
      if (a == b)
            return 0;
      else if (a < b)
            return -1;
      else
            return 1;
}
function formatDate(rowData):String      {
      var dFormat = new mx.formatters.DateFormatter();
      return (dFormat.format(rowData.feedbackCreationDate));
}
....


1. But now I'm facing a performance issue. My application is populating 1000 records in the grid and when I click on the header to sort grid on date order then it hangs the application and throw script error "A script in this movie is causing Macromedia Flash Player 8 to run slowly. If continues to run, your computer may become unresponsive. Do you want to abort the script?"

Same script works fine if I populate with less number of records, say 100, in grid but then this takes more then 10 secs to sort data. Do we have any solution to this issue?

Also, if I remove labelFunction then script works fine for 1000 records but takes long time to order all data.

2. Is it possible to remove ordering from the grid and show default order list? Click one will sort data in ascending order, Click two will sort data in descending order and Click three will show the default order or remove ordering from the grid.


Regards,
Nischal Pathania
________________________________________
From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Matt Chotin
Sent: Tuesday, October 11, 2005 20:53
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] date sort

sortCompareFunction is meant for you controlling the sort regardless of whether you had a cell renderer.  You just need the DataGridColumn.  In your case since the data is already formatted using the labelFunction you may want the sortCompareFunction to work on the unformatted value.

________________________________________
From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of [EMAIL PROTECTED]
Sent: Friday, October 07, 2005 2:17 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] date sort


Ya I have tried that but from I understand that only work when the date is from cell renderer. Mine is coming from a java object and is using label to format it.




CONFIDENTIALITY STATEMENT - This message and any files or text attached to it are intended only for the recipients named above, and contain information that may be confidential or privileged.  If you are not an intended recipient, you must not read, copy, use, or disclose this communication.  Please also notify the sender by replying to this message, and then delete all copies of it from your system.  Thank you.
"Matt Chotin" <[EMAIL PROTECTED]>
Sent by: flexcoders@yahoogroups.com
10/05/2005 05:27 PM
Please respond to
flexcoders@yahoogroups.com

To
<flexcoders@yahoogroups.com>
cc

Subject
RE: [flexcoders] date sort







If it's not working by default you may want to look into the sortCompareFunction on DataGridColumn.
 
Matt
 

________________________________________

From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Joe
Sent: Wednesday, October 05, 2005 2:33 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] date sort
 
Is there a way to sort a date field in a data grid that is using a
labelfunction to get the date value. I have read that it can be done
when using a cell renderer, but I do not want to change the code. Can
this be done? Thanks.





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com

SPONSORED LINKS
Web site design development
Computer software development
Software design and development
Macromedia flex
Software development best practice



________________________________________
YAHOO! GROUPS LINKS

*  Visit your group "flexcoders" on the web.
 
*  To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
 
*  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

________________________________________




--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com


SPONSORED LINKS
Web site design development
Computer software development
Software design and development
Macromedia flex
Software development best practice


________________________________________
YAHOO! GROUPS LINKS

*  Visit your group "flexcoders" on the web.
 
*  To unsubscribe from this group, send an email to:
 [EMAIL PROTECTED]
 
*  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

________________________________________



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to