您的位置:首页 > 其它

flex中使dataGrid每行都有button

2014-12-30 15:08 176 查看
使dataGrid中每行都有button,且在点击button时知道点击的是哪行的button。

代码如下:

<mx:DataGrid id="dg" editable="true" color="0x323232" width="100%" height="450" rowCount="32" rowHeight="40" dataProvider="{dataIndicator}">
<mx:columns>
<mx:DataGridColumn dataField="indexIndicator" width="50" headerText="序号" textAlign="center" editable="false"/>
<mx:DataGridColumn dataField="INDICATOR_VALUE" headerText="指标值" editable="true"/>
<mx:DataGridColumn editable="false" width="120" itemRenderer="">
<mx:itemRenderer>
<fx:Component>
<mx:HBox width="100" horizontalAlign="center" verticalAlign="top">
<mx:Button label="保    存" width="80" click="outerDocument.button1_clickHandler(event)">

<fx:Script>
<![CDATA[
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub

}
]]>
</fx:Script>

</mx:Button>
</mx:HBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>


自动生成的button的click方法没有在原页面上,所以无法调用dataGrid中selectedIndex,所以需要引用outerDocument.的方法,这样就能访问到外面的方法,此时可以删掉<mx:Button>中间的<fx:Script>,直接调用外面的方法了,外面的方法一定要定义为public类型,否则还会报错.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: