How can I know when a Button in a Flex DataGrid itemRenderer is clicked?

Posted by Eric Belair on Stack Overflow See other posts from Stack Overflow or by Eric Belair
Published on 2009-07-08T16:12:46Z Indexed on 2010/05/07 1:18 UTC
Read the original article Hit count: 320

I have a DataGrid component that displays a few columns of data. It has one additional column that displays a Button that allows the user to take an action with regard to the record.

<mx:DataGrid dataProvider="{myData}">
    <mx:columns>
        <mx:DataGridColumn dataField="firstName" headerText="First Name" 
            width="75" />

        <mx:DataGridColumn dataField="LastName" headerText=" Last Name" 
            width="150" />

        <mx:DataGridColumn dataField="phone" headerText="Phone" 
            width="120" />

        <mx:DataGridColumn headerText="" width="110">
            <mx:itemRenderer>
                <mx:Component>
                    <mx:Box horizontalAlign="center" width="100%">
                        <mx:Button label="Take Action" />
                    </mx:Box>
                </mx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
    </mx:columns>
</mx:DataGrid>

I need to perform an action in the parent component, using other data that is available there, but unrelated to the data in the DataGrid.

What is the best way to catch the Button click in the parent component, and know what record it corresponds to?

Should I use a Custom Event, or an itemEditor, or something else completely?

© Stack Overflow or respective owner

Related posts about flex

Related posts about actionscript-3