ActionScript 2.0 Components Language Reference |
|
|
|
| DataGrid component > DataGrid.headerRelease | |||
Flash Player 6 (6.0.79.0).
Flash MX Professional 2004.
listenerObject= new Object();listenerObject.headerRelease = function(eventObject){// Insert your code here.}myDataGridInstance.addEventListener("headerRelease",listenerObject)
Event; broadcast to all registered listeners when a column header has been released. You can use this event with the DataGridColumn.sortOnHeaderRelease property to prevent automatic sorting and to let you sort as you like.
Components use a dispatcher/listener event model. When the DataGrid component dispatches a headerRelease event, the event is handled by a function (also called a handler) that is attached to a listener object (listenerObject) that you create. You call the addEventListener() method and pass it the name of the handler as a parameter.
When the event is triggered, it automatically passes an event object (eventObject) to the handler. Each event object has properties that contain information about the event. You can use these properties to write code that handles the event. The DataGrid.headerRelease event's event object has two additional properties:
columnIndex A number that indicates the index of the target column.
type The string "headerRelease".
For more information, see EventDispatcher class.
In the following example, a handler called myListener is defined and passed to grid.addEventListener() as the second parameter. The event object is captured by the headerRelease handler in the eventObject parameter. When the headerRelease event is broadcast, a trace statement is sent to the Output panel.
var myListener = new Object();
myListener.headerRelease = function(event) {
trace("column " + event.columnIndex + " header was pressed");
};
grid.addEventListener("headerRelease", myListener);
In the following example, you change the sort direction using a column. With a DataGrid instance named my_dg on the Stage, paste the following code in the first frame of the main timeline:
var my_dg:mx.controls.DataGrid;
my_dg.setSize(150, 100);
my_dg.spaceColumnsEqually();
var myListener:Object = new Object();
myListener.headerRelease = function(evt:Object) {
trace("column "+evt.columnIndex+" header was pressed");
trace("\t current sort order is: "+evt.target.sortDirection);
trace("");
};
my_dg.addEventListener("headerRelease", myListener);
my_dg.addColumn("a");
my_dg.addColumn("b");
my_dg.addItem({a:'one', b:1});
my_dg.addItem({a:'two', b:2});
By accessing the sortDirection property, you can tell whether the sort order is ascending or descending. The sortDirection property is a string, so it traces as either ASC or DESC.
|
|
|
|