ketan
ketan

Reputation: 19341

Sort on datagrid also sort null values in flex

Today i am getting some weird issue in datagrid.

<s:DataGrid id="grid_result" dataProvider="{somelist}" sortableColumns="true">

I have datagrid and on top header click it sort the column suppose this is the column.

<s:GridColumn headerText="Temp" dataField="tempName">

It will display tempName from someList. But some of data is null. So, when i sort this column on header of this column click it will sort null value also.

like it display:

A
B
.
.
l
m
blank cell
blank cell
o
p
.
.
Z

It consider null value after m and before o. I think it consider null as n(I may wrong for this).

I want to display null value at last. I have search lot but not found any solution.

Any help is greatly appreciated.

Upvotes: 0

Views: 274

Answers (1)

Petr Hrehorovsky
Petr Hrehorovsky

Reputation: 1153

You can create custom sortCompareFunction and force using SortingCollator class, which is supposed to handle null values.

private var collator:SortingCollator = new SortingCollator();

private function sortCompareFunction(obj1:Object, obj2:Object, gc:GridColumn):int {
    return collator.compare(obj1[gc.dataField], obj2[gc.dataField]);
}

And then assign it to the GridColumn.

<s:GridColumn headerText="Temp" dataField="tempName" sortCompareFunction="sortCompareFunction">

Upvotes: 3

Related Questions