--- In flexcoders@yahoogroups.com, "Ian M. Jones" <[EMAIL PROTECTED]> wrote:
>
> Hi there, hope someone has come across my problem and can point out  
> my mistake...
> 
> I have an ArrayCollection acting as the data provider for an  
> AdvancedDataGrid, and am saving out the data provider's sort fields  
> array to a SharedObject between sessions and refreshes of the data.
> 
> When I retrieve new data I grab the array of sort fields and stuff  
> them into the ArrayCollection's sort property like so:
> 
> private function getDefaultColumnsSort():void {
>       var prefs:SharedObject = SharedObject.getLocal("FogBugzModule");
> 
>       // Look for a saved sort order.
>       if ("defaultColumnsSort" in prefs.data) {
>               var sort:Sort = new Sort();
>               sort.compareFunction = customCompare;
>               sort.fields = new Array();
>               for (var y:int = 0; y < prefs.data.defaultColumnsSort.length; 
> y++) {
>                       if (prefs.data.defaultColumnsSort[y] != null) {
>                               if ("name" in prefs.data.defaultColumnsSort[y]) 
> {
>                                       if 
> (prefs.data.defaultColumnsSort[y].name != null) {
>                                               var sortField:SortField = new 
> SortField 
> (prefs.data.defaultColumnsSort[y].name, true, Boolean 
> (prefs.data.defaultColumnsSort[y].descending));
>                                               sort.fields.push(sortField);
>                                       }
>                               }
>                       }
>               }
>               // Add sort criteria to data provider.
>               casesArray.sort = sort;
>               // Sort data in data provider.
>               casesArray.refresh();
>       }
> }
> 
> The problem is, the ADG does sort the data by the right columns, but...
> 
> * it's always in ascending order, even though the column headers show  
> the sort arrow correctly pointing down if the saved sort was descending.
> 
> * if you click on the column header to re-sort it nothing happens,  
> the sort arrow will flip-flop between pointing up and down as many  
> times as you like, but sort order is always ascending.
> 
> * The sorted column will not sort properly until I sort another  
> column by clicking it's header first, then it'll properly sort  
> ascending and descending when clicked.
> 
> The Sort object I'm assigning to the casesArray ArrayCollection above  
> "looks" OK, it just seems there is something not quite right in the  
> way the ADG uses it.
> 
> If anyone has any advice, I'd be very grateful.
> 
> Thanks,
> 
> Ian
>

Fixed it.

I got close to solving the problem by removing the compareFunction from the 
Sort I was 
constructing at startup, but that meant numeric, date and compound columns were 
always 
sorted alphabetically instead of numerically, by date or through the two or 
more data 
fields that made up the column respectively. But at least it was sorting in the 
right 
direction and the direction could be changed correctly. This was definitely my 
fault, I 
shouldn't have used the custom compareFunction because I dynamically add a 
sortCompareFunction to any AdvancedDataGridColumn that needs it when adding the 
user's preferred columns to the AdvancedDataGrid, so I didn't need to reference 
another 
custom compare function on the data provider.

But why wasn't the AdvancedDataGrid using it's column's sortCompareFunction 
definitions?

When I created the SortFields for the initial sort I was setting the ignore 
case property to 
true just as a means of getting to the descending parameter that I was truly 
interested in, 
when I set that to false, suddenly the AdvancedDataGrid was using the correct 
sortCompareFunctions for it's columns. Very strange.

On reflection, it could be that the framework is assuming that if the SortField 
has it's 
ignore case property set to true then it must need to do an alphabetic sort, 
regardless of 
whether there's a custom compare function on the column or not.

Hey ho, it's fixed now.

Cheers,

Ian

Reply via email to