Flex 4 - DataGrid with Button in cells

六眼飞鱼酱① 提交于 2019-12-12 12:15:34

问题


How can I add a button control in cells of a datagrid? I'm looking to have a button in each row of one column in the datagrid. The datagrid control rows don't need to be selectable in any way.


回答1:


It's really quite simple. Just define a custom item renderer for the column

<mx:DataGrid width="100%" height="100%" dataProvider="{this.someData}">
        <mx:columns>                
            <mx:DataGridColumn headerText="Buttons" >
                <mx:itemRenderer>
                    <fx:Component>
                        <s:ItemRenderer width="100%">
                            <s:Button label="{data.buttonName}" click="{outerDocument.someFunction()}" />
                        </s:ItemRenderer>
                    </fx:Component>
                </mx:itemRenderer>
            </mx:DataGridColumn>
       </mx:columns>
</mx:DataGrid>

use data to refer to the row's dataprovider object and outerDocument to access methods outside of the item renderer.

Hope this helps!




回答2:


To do this with Flex 4 controls - ie. Spark use a GridItemRenderer.

There are very good examples here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/gridClasses/GridItemRenderer.html#includeExamplesSummary



来源:https://stackoverflow.com/questions/5004841/flex-4-datagrid-with-button-in-cells

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!