Wednesday, November 18, 2009

Adobe Flex Grid Column Sort

Lately I have been doing some work with Adobe Flex because it has some very nice data manipulation features, such as the DataGrid. One item that came to my attention was that when I sorted a column, I wanted the grid to jump to the top of the data set.

Here is my solution:

1. add a "headerRelase" attribute to the DataGrid tag that will call an event handler

<mx:DataGrid id="ratesGrid" headerRelease="ratesGrid_headerRelease(event)" >

2. create the new event handler

private function ratesGrid_headerRelease(evt:DataGridEvent):void {
ratesGrid.validateNow(); // allow sort to occur
ratesGrid.selectedIndex=-1; // turn off selected/highlighted row
ratesGrid.scrollToIndex(0); // move to top of data set

No comments: