標籤:
使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>,直接調用外面的方法了
flex中使dataGrid每行都有button