actionscript-3apache-flexflex3mxmlitemrenderer

I want to put a button inside datagrid's column tag in flex 3


I need to put a button in one of the columns of datagrid tag and the column's value should appear on the buttons label. Any help will be highly appreciated


Solution

  • In flex 3, use the tag mx:itemRenderer:

    <mx:DataGrid id="myDataGrid" dataProvider="{myDP}">
            <mx:columns>
                <mx:DataGridColumn dataField="field">
                    <mx:itemRenderer>
                        <mx:Component>
                            <mx:Button label="{data.field}"/>
                        </mx:Component>
                    </mx:itemRenderer>
                </mx:DataGridColumn>
            </mx:columns>
        </mx:DataGrid>
    

    In flex 4, use spark dataGrid and the s:itemRenderer tag:

    <s:DataGrid dataProvider="{myDP}">
        <s:columns>
            <s:ArrayList>
                <s:GridColumn dataField="Price">
                    <s:itemRenderer>
                        <fx:Component>
                            <s:GridItemRenderer>
                                <s:Button label="{data.Price}"/>
                            </s:GridItemRenderer>
                        </fx:Component>
                    </s:itemRenderer>    
                </s:GridColumn>
            </s:ArrayList>
        </s:columns>
    </s:DataGrid>