Ahh yep, my date strings are in format YYYY-MM-DD anyway.

Cheers!
Adam


  ----- Original Message ----- 
  From: iko_knyphausen 
  To: flexcoders@yahoogroups.com 
  Sent: Sunday, March 04, 2007 3:11 AM
  Subject: [flexcoders] Re: simulate datagrid header click, or set default sort 
column



  By dates, I meant, sorting the following

  2/13/2007
  11/13/2007

  If you sort these as strings, November is smaller than February, which
  is obviously wrong. Your sortFunction would have to create date objects
  first and compare those, or pad the strings with leading zeros...

  --- In flexcoders@yahoogroups.com, "Adam Royle" <[EMAIL PROTECTED]> wrote:
  >
  > OK, this was easier than anticipated. I didn't realise the DataGrid
  would detect the sort on the ArrayCollection and update it's sort arrow
  based on this.
  >
  > My code:
  >
  > import mx.collections.Sort;
  > import mx.collections.SortField;
  >
  >
  >
  > var s:Sort = new Sort();
  > s.fields = [new SortField("transaction_date",false,true)];
  > dataProvider.sort = s;
  > dataProvider.refresh();
  >
  >
  > Thanks for your advice. By the way, I don't really understand what you
  mean about sorting dates as strings. When I load my data I create date
  objects from my strings, and the datagrid/sort classes sort it all
  correctly. Although I do understand your labelFunction point.
  >
  > Cheers,
  > Adam
  >
  >
  > ----- Original Message -----
  > From: iko_knyphausen
  > To: flexcoders@yahoogroups.com
  > Sent: Saturday, March 03, 2007 9:52 AM
  > Subject: [flexcoders] Re: simulate datagrid header click, or set
  default sort column
  >
  >
  >
  > Yes, but you should provide for the sorting of these columns too,
  > otherwise your sort competes against the builtin...
  >
  > Alternatively, you could detach your custom sort whenever a different
  > header is clicked (meaning resetting the sort property of the
  > collection) - but I think you can have much more control doing your
  own.
  > Also keep in mind, if you have any columns with calculated fields
  > (meaning the dataField value is different than what is displayed), you
  > may need a custom sort anyway (try sorting dates as strings... and you
  > see what I mean)
  >
  > Iko
  >
  > --- In flexcoders@yahoogroups.com, "Adam Royle" adam@ wrote:
  > >
  > > OK, thanks for your response. Haven't tried this yet, but will do.
  > Just a quick question, if I use do the way you recommend with a custom
  > sort object, can the user still use the headers to change the sort
  > column/direction? This is what I want.
  > >
  > > Thanks,
  > > Adam
  > >
  > > ----- Original Message -----
  > > From: iko_knyphausen
  > > To: flexcoders@yahoogroups.com
  > > Sent: Saturday, March 03, 2007 5:09 AM
  > > Subject: [flexcoders] Re: simulate datagrid header click, or set
  > default sort column
  > >
  > >
  > >
  > > BTW, I also fiddled with dispatching the HEADER_RELEASE event,
  before
  > I
  > > used a custom sort, and one problem is, that its behavior depends on
  > > whether the column to be sorted was the last sorted column or not.
  If
  > it
  > > was the previous sort column a header release event will reverse the
  > > sort order, if it was not the last column, it will reuse the same
  sort
  > > order that it had when it was last used - in some cases you may end
  up
  > > dispatching the header release twice, to get the desired sort order,
  > and
  > > you can see... this is not a good solution ;-)
  > >
  > > --- In flexcoders@yahoogroups.com, "iko_knyphausen" iko@ wrote:
  > > >
  > > >
  > > > I just went through the same exercise, and ended up using the
  > > > "recommended" method, which is creating your own Sort object...
  > > >
  > > > The basic working is to
  > > >
  > > > 1. take a collection (either arraycollection or xmllistcollection)
  > as
  > > > dataprovider
  > > > 2. define a Sort object for it (you do this by creating SortFields
  > and
  > > > putting them into the fields array of the Sort object)
  > > > 3. execute a Refresh on your collection
  > > >
  > > > If you trigger your sort via HeaderRelease events, you should call
  > > > preventDefault() in that handler so that only your sort gets
  > executed.
  > > >
  > > > You can find code samples if you look in the docs (the example I
  > used
  > > > was about sorting multiple columns at the same time)
  > > >
  > > > HTH
  > > > --- In flexcoders@yahoogroups.com, "Robert Chyko" rchyko@ wrote:
  > > > >
  > > > > One thing to look at would be dispatch a HEADER_RELEASE event on
  > the
  > > > > datagrid. Its not the most straightforward fix, and will take a
  > > little
  > > > > tweaking to get to work right, but it is doable.
  > > > >
  > > > >
  > > > >
  > > > >
  > > > > -----Original Message-----
  > > > > From: flexcoders@yahoogroups.com
  > > > > [mailto:[EMAIL PROTECTED] On Behalf Of Adam Royle
  > > > > Sent: Thursday, March 01, 2007 8:09 PM
  > > > > To: flexcoders@yahoogroups.com
  > > > > Subject: [flexcoders] simulate datagrid header click, or set
  > > > > default sort column
  > > > >
  > > > >
  > > > >
  > > > >
  > > > > Hi guys,
  > > > >
  > > > > This came up last week but no working response was given.
  > > > >
  > > > > I have my data sorted in a dataProvider, however whenever I add
  > > > > new data I add it to the end of the ArrayCollection. However
  this
  > > > means
  > > > > the datagrid is no longer sorted correctly.
  > > > >
  > > > > I wish I could execute the private method sortByColumn() that
  > > > > exists in the DataGrid class, but it's private!!
  > > > >
  > > > > Anyone with a solution? I have tried subclassing and also
  > > > > copying code directly, but the sortByColumn method uses private
  > > > > variables, so I'm stuck again.
  > > > >
  > > > > Can anyone suggest a solution to my problem?
  > > > >
  > > > > Cheers,
  > > > > Adam
  > > > >
  > > >
  > >
  >



   

Reply via email to