开发者

Flex AdavcedDatagrid Sorting is case-sensitive

开发者 https://www.devze.com 2023-01-08 20:43 出处:网络
I have several datagrids with changing columns. Fo开发者_开发技巧r the text fields the datagrid\'s sort function neems to be making a case sensitive compare.

I have several datagrids with changing columns. Fo开发者_开发技巧r 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.


Set the sortCompareFunction on your datagrid column:

<mx:DataGridColumn dataField="name" headerText="Name" sortCompareFunction = sortCaseInsensitive  />

private function sortCaseInsensitive(obj1:Object, obj2:Object):int
    {
        return ObjectUtil.stringCompare(obj1.name, obj2.name, true);
    }


Use the sortCompareFunction


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消