DataGrid.headerRelease example

Today is Tuesday LiveDocs day. Sometimes questions are posted in LiveDocs. Although please note that LiveDocs is not the place for questions about how to do things in Flash: the proper place is in the Macromedia forums. But at times, there are sections of the docs that could use some fleshing out, perhaps an additional example is necessary. So, this blog from time to time will “document” some areas where an extra example might be helpful.

First one up to bat is DataGrid.headerRelease. This example shows you how to change the direction of the DataGrid by clicking the column.

1. Drag a DataGrid onto the Stage.
2. In the property inspector, add the instance name my_dg.
3. Add the following ActionScript to frame 1 of the Timeline:

var my_dg:mx.controls.DataGrid;
my_dg.setSize(150, 100);
var myListener:Object = new Object();
myListener.headerRelease = function(evt:Object) {
trace(“column “+evt.columnIndex+” header was pressed”);
trace(“\t current sort order is: “;
my_dg.addEventListener(“headerRelease”, myListener);
my_dg.addItem({a:’one’, b:1});
my_dg.addItem({a:’two’, b:2});

By accessing the sortDirection property, you can then tell the sort order is ascending or descending. The sortDirection is actually a string, so it traces as either ASC or DESC.

One Response to DataGrid.headerRelease example

  1. mike says:

    Very handy, thanks for that example.