views:

1100

answers:

4

In Adobe Flex, when user presses and releases Mouse on a column header in a Datagrid, the corresponding sorting function for the column is called. Is there a way to figure out, when does the sorting stop? Basically, there is a column "Serial Number" in the datagrid, which I want to relabel, when the sorting for a particular column happens and stops.

I need it because : There is an year column in my datagrid. When I sort it, suppose there are 6 entries :

2008
2008
2008
2009
2009
2009

I want the labeling to be 1,2,3,1,2,3, i.e. the labeling restarts after the year changes.

A: 

Sorting is not an asynchronous process, hence no events are generated. You could though get the headerRelease event to know when sorting is about to begin.

dirkgently
A: 

If you are wanting to relabel the column, why wouldn't you use a label function? and why would you need it to wait until the sorting is complete?

Ryan Guill
A: 

You could turn off sorting on the column and add a headerRelease Event Handler to the DataGrid that sorts the dataProvider's underlying Collection "manually" in ActionScript, and after at refreshing the Collection, call a function to reset your column header text. Check out this link for more detailed info on overriding the sort functionality:

http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_7.html

Eric Belair
+1  A: 

DataGrid's dataProvider dispatches a CollectionEvent.COLLECTION_CHANGE event with its 'kind' property set to CollectionEvent.REFRESH after the sort has been completed. Just get the dataProvider and add an event handler to it and you should be fine.

Simon