06.04.09
Capturing DataGrid Sort
In a current project of mine, I needed to capture when a user clicks on a DataGrid header to sort it (to track the column and sort order). The only good event to listen to is “headerRelease”. However, if you just add a declarative event listener to the DataGrid, you’ll find in your handler the sort hasn’t been applied yet. This is because your handler will complete before the sort ever takes place, due to DataGrid adding its own handler for the event with a priority of -50.
In order for DataGrid’s handler to complete so that the sort will be applied for your handler, you’ll need to add your handler with a lower priority:
dataGrid.addEventListener( DataGridEvent.HEADER_RELEASE, dataGridHeaderReleaseHandler, false, -100 );
I chose to use -100 in this instance. If you check out the class EventPriority, you’ll find where DataGrid’s -50 is defined (this is the value used for all internal handlers of Flex core components), along with some other priorities used for core Flex components such as Effects, Binding and CursorManager.
Depending on your scenario, you may want to always add your handlers at a lower priority than the component’s internal handlers, unless there’s a chance you need to call “preventDefault()” in order to stop the component from performing default behavior.