Determining a DataGridColumn object’s current sort order – callLater()

The callLater() method queues an operation to be performed for the next screen refresh, rather than in the current update. Without the callLater() method, you might try to access a property of a component that is not yet available. The callLater() method is most commonly used with the creationComplete event to ensure that a component has finished being created before Flex proceeds with a specified method call on that component.

All objects that inherit from the UIComponent class can open the callLater() method. It has the following signature:
callLater(method:Function, args:Array):void

The following example uses a call to the callLater() method to ensure that new data is added to a DataGrid before Flex tries to put focus on the new row. Without the callLater() method

<?xml version="1.0" encoding="utf-8"?>
<mx:Application name="DataGridColumn_sortDescending_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.events.DataGridEvent;

            private function doHeaderRelease(evt:DataGridEvent):void {
                var column:DataGridColumn = DataGridColumn(evt.currentTarget.columns[evt.columnIndex]);
                DataGrid(evt.currentTarget).callLater(onCallLater, [column]);
            }

            private function onCallLater(column:DataGridColumn):void {
                columnSortDescending.text = column.dataField + ".sortDescending: " + column.sortDescending;
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Label id="columnSortDescending" />
    </mx:ApplicationControlBar>

    <mx:DataGrid id="dataGrid"
            rowCount="4"
            headerRelease="doHeaderRelease(event)">
        <mx:columns>
            <mx:DataGridColumn id="col1" dataField="label" />
            <mx:DataGridColumn id="col2" dataField="data" />
        </mx:columns>
        <mx:dataProvider>
            <mx:Array>
                <mx:Object data="one" label="User 1" />
                <mx:Object data="two" label="User 2" />
            </mx:Array>
        </mx:dataProvider>
    </mx:DataGrid>

</mx:Application>