Determine if an element is visible in a scrollable Spark DataGrid

By digging in the Flex 4.5 API docs I’ve found a way to determine if a certain element (object) of the spark.components.DataGrid.dataProvider is visible in the viewport of the spark.components.Scroller wrapping the DataGrid.

The spark.components.Grid offers a method

1
isCellVisible(rowIndex:int = -1, columnIndex:int = -1):Boolean

Since the spark.components.Grid represents the grid part of the spark.components.DataGrid, the method can be called as follows:

1
dataGrid.grid.isCellVisible(rowIndex);.

You can call this method in an event listener to determine if a row (element) is visible in the scroller:

1
2
3
4
5
6
7
8
dataGrid.scroller.verticalScrollBar.addEventListener(
    TrackBaseEvent.THUMB_RELEASE,updateIsItemVisible
);
 
private function updateIsItemVisible( e:Event):void
{
    var visible:Boolean = dataGrid.grid.isCellVisible( _itemIndex );
}

Leave a Reply

 (required)
 (required)