tags:

views:

19

answers:

2

I have several datagrids with changing columns. For the text fields the datagrid's sort function neems to be making a case sensitive compare.

eg. the following list sorted would look like this

apples
strawberries
Autos

Autos should be with apples but since the capital A is counted differently all capital letters come after.

I've found a lot of information on setting a CASEINSENSITIVE flag, but I can't figure out where to do this. Could you please help? The best solution would be one where I can override the default behavior to be case insensitive for all my datagrids and all my compare functions.

A: 

The sort is applied to the underlying dataprovider. So you need to alter how that Sort works by setting the sort fields. You need to capture the sort event from the header, and prevent it's default behaviour and sort the arraycollection on the fly.

protected function onHeaderRelease( event : AdvancedDataGridEvent ) : void {
    event.preventDefault();
    var sort : Sort = new Sort();
    sort.fields = [new SortField(event.dataField, true)];
    dataProvider.sort = sort;
    dataProvider.refresh();
}

Note that this will stop the arrows on the header from rendering. You'll also need to add the code for reversing the sort when the header is clicked on again.

Take away message, the ADG is really rubbish.

Gregor Kiddie
A: 

Use the sortCompareFunction

Amarghosh
I ended up doing this, but I feel that it's kind of unclean because now I had to manually add this every time there is a text fiel, but not a number or date field. I would have preferred to be able to set this globally somewhere for the entire application.
Dennkster