Search This Blog

Monday, March 28, 2011

Flex access dataGrid from ItemRenderer

If you have a buttonClickCall in your DataGrid and you want to access the whole DataGrid from your ItemRenderer call do the following:

add imports:

import mx.controls.DataGrid;
import mx.core.Application;
import mx.core.FlexGlobals;

access DataGrid in the following way:

var dataProvider = FlexGlobals.topLevelApplication.dataGrid.dataProvider;
var dataProvider = Application.application.dataGrid.dataProvider;


It will work despite the fact that these DataGrid variable is defined in a different mxml file.

ItemRenderer – ItemRendererXXX.mxml
Application – Name_Of_Your_App.mxml


You can that access all items in the following way:

for (var i:int = 0; i < dataProvider.length; i++)
    item = dataProvider.getItemAt(i);


If you like this post, please leave a comment :)