Often when building an application you need to determine the current sort column and sort order, since the user can re-sort columns at any time by clicking on a column’s header. The following example shows how to listen for the headerRelease event (DataGridEvent.HEADER_RELEASE) to determine the current sort order after a user clicks on a column header.
The following example creates an ActionScript 3.0 DataGrid component instance in Flash CS3 and traces the current column and sort order when a data grid header is clicked.
Full code after the jump.
/** * Requires: * - A DataGrid control in the document library. */ import fl.controls.DataGrid; import fl.controls.dataGridClasses.DataGridColumn; import fl.data.DataProvider; import fl.events.DataGridEvent; var dp:DataProvider = new DataProvider(); dp.addItem({columnA:"Row 1A", columnB:1234.00}); dp.addItem({columnA:"Row 2A", columnB:56.30}); dp.addItem({columnA:"Row 3A", columnB:789.12}); var colA:DataGridColumn = new DataGridColumn("columnA"); var colB:DataGridColumn = new DataGridColumn("columnB"); colB.sortOptions = Array.NUMERIC; var myDataGrid:DataGrid = new DataGrid(); myDataGrid.addColumn(colA); myDataGrid.addColumn(colB); myDataGrid.dataProvider = dp; myDataGrid.width = 200; myDataGrid.rowCount = myDataGrid.length; myDataGrid.move(10, 10); myDataGrid.addEventListener(DataGridEvent.HEADER_RELEASE, headerReleaseHandler); addChild(myDataGrid); function headerReleaseHandler(evt:DataGridEvent):void { var dg:DataGrid = evt.currentTarget as DataGrid; trace("column: " + String(evt.dataField)); trace("descending: " + String(dg.sortDescending)); }
4 Responses to Determining the current sort column and sort order on a Flash CS3 DataGrid control
Leave a Reply Cancel reply
Recent Posts
- Getting started with the TLFTextField class in ActionScript 3.0 and Flash CS5
- Adding tick marks to a Slider control in Flash using ActionScript 3.0
- Creating a vertical Slider control in Flash using ActionScript 3.0
- Creating a custom context menu item in Flash using ActionScript 3.0
- Rotating a Sprite object around its x-axis in Flash using ActionScript 3.0 and Flash Player 10
- Detecting when the user changes the color in a ColorPicker control in Flash using ActionScript 3.0
- Getting the currently selected color as a hexadecimal value on a ColorPicker control in Flash using ActionScript 3.0
- Toggling the text field on the ColorPicker control in Flash using ActionScript 3.0
- Creating a vertical Slider control in Flash using ActionScript 3.0
- Setting the number of columns on a ColorPicker control in Flash using ActionScript 3.0
Categories
- Bitmap (1)
- Components (72)
- Button (19)
- CheckBox (2)
- ColorPicker (6)
- ComboBox (1)
- DataGrid (8)
- FLVPlayback (7)
- Label (9)
- ProgressBar (2)
- Slider (3)
- TextArea (1)
- TextInput (7)
- UILoader (7)
- ContextMenu (1)
- Embed (4)
- ExternalInterface (2)
- Flex (7)
- Font (2)
- General (5)
- Graphics (2)
- JSFL (14)
- Loader (3)
- LoadVars (3)
- Microphone (1)
- migration (12)
- MovieClip (1)
- MovieClipLoader (1)
- Sound (2)
- TextField (1)
- TLFTextField (1)
- TransitionManager (1)
- Tween (1)
- Uncategorized (1)
- URLLoader (4)
- URLVariables (1)
- Video (1)
- XML (2)
Advertising
" RT @OReillyMedia: #Ebook Deal/Day: Learning JavaScript Design Patterns -
$11.99
(Save 50%)
http://t.co/ilcmSDv6 " — pdehaan


Hello, I see this does not work if you have the datagrid sortablecolumns set to false. What I want to do is do my own thing when a user clicks a column, not sort. Any ideas?
Hey.. I don’t have that propertied sortDescending.. I’m on flex.. but it’s the same actionscript.. :S
Pedro,
The Flex components are a completely different code base. There is no sortDescending property in the Flex DataGrid. If you are using an ArrayCollection or XMLListCollection you may be able to query the data provider’s sort for that information.
Peter
hello, i want to get this, this data not xml :
&name=melon&age=19&row1
&name=noken&age=29&row2
&name=loemn&age=39&row3
&name=kol&age=49&row4
what can i do in action script 3?