--- In [email protected], "Amy" <[EMAIL PROTECTED]> wrote:
>
> --- In [email protected], Adrian Williams <adrianw@>
> wrote:
> >
> > All,
> >
> > I discovered a frustrating feature of the ADG when using
> > groupings...the ADG automatically sorts the displayed data by the
> field
> > you are grouping on. I really, really need the ability to
disable
> this
> > as I am incorporating a displayOrder option for my users to
define
> what
> > order they want the groupings to appear in. The data is coming
> from my
> > webservice based on the displayOrder but once it gets populated
in
> my
> > ADG, it's re-ordered by the grouping.
> >
> > So for example, I have 10 groups....named Group 1 through
Group
> 10.
> > And each of the groups displayOrder is set to the same as the
> name...so
> > the displayOrder for Group 1 == 1, Group 2 == 2, ... , Group 10
==
> 10.
> > But when the ADG is rendered, it sorts them by the group names,
> which
> > are strings, and puts them out of the expected order...I get
Group
> 1,
> > Group 10, Group 2, etc.
> >
> > This is a critical aspect for us and I really hope to find a
> > solution to this.
>
> I am not sure, but I think Grouping and GroupingField have a
> groupingObjectFunction, and it may be that you can separate what
gets
> shown on the screen from whatever is causing the reordering.
> Possibly you could also apply a sort to the GroupingCollection.
>
> That being said, I am using a groupingFunction to group a bunch of
> dates by month, and, at least internally in the GroupingCollection,
> it stays in the same order as the dates are in the flat
> ArrayCollection. These are not being displayed in an ADG, since
I'm
> looking more at how a GroupingCollection can be used to allow for
> better data management in general, not just with ADG. So it may be
> that the ADG itself is imposing the ordering.
Looks like I was misunderstanding what I was seeing. Here are some
snippets of what I did to ensure that my dates all wound up in the
right collections in the right order. If I've left out anything
critical to understanding this, please let me know...
MXML GroupingCollection:
<!--thisYearCollection is an ArrayCollection of custom objects
that contain a date object for each date in the current year-->
<mx:GroupingCollection id="monthsGC" source="{thisYearColl}">
<mx:grouping>
<mx:Grouping compareFunction="monthCompare">
<mx:GroupingField name="date"
groupingFunction="labelMonths" />
</mx:Grouping>
</mx:grouping>
</mx:GroupingCollection>
I have a const collection that allows a lookup of months:
private const months:Array=
['January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October',
'November', 'December'];
These are my helper functions:
private function labelMonths(item:CalendarDate,
field:GroupingField):String{
//I'm hardcoding the field on item, since
that's the only
//field it would work on anyway
return months[item.date.month];
}
private function monthCompare(a:CalendarDate,
b:CalendarDate, fields:Array=null):int{
//if the month is the same, then the dates
are the same
//for grouping purposes
if (a.date.month==b.date.month) return 0;
//if the months are not the same, then
//sort by the actual date
if (a.date > b.date) {
return 1;
} else {
return -1;
}
}
Pretty easy, once you know the right direction. But the docs aren't
too helpful on that ;-).
HTH;
Amy