Flex中DataGrid使用列中放Button
发布时间:2020-12-15 04:09:19 所属栏目:百科 来源:网络整理
导读:Flex 中使用DataGrid,让其中的某些列可以编辑,并在最后一列放按钮,单击保存修改。效果如下: 其中价格是可以编辑的,其他不可编辑。点击按钮之后将数据更新到服务器。代码如下: mx:DataGrid x="0" y="0" height="80%" width="100%" dataProvider="{DP}"
Flex 中使用DataGrid,让其中的某些列可以编辑,并在最后一列放按钮,单击保存修改。效果如下:
其中价格是可以编辑的,其他不可编辑。点击按钮之后将数据更新到服务器。代码如下: <mx:DataGrid x="0" y="0" height="80%" width="100%" dataProvider="{DP}" id="producesell" editable="true">
<mx:columns>
<mx:DataGridColumn headerText="名称" dataField="name" editable="false"/>
<mx:DataGridColumn headerText="数量" dataField="volume" editable="false"/>
<mx:DataGridColumn headerText="价格(元/千克)" dataField="price" editable="true">
</mx:DataGridColumn>
<mx:DataGridColumn headerText="确认价格" editable="false">
<mx:itemRenderer>
<fx:Component>
<mx:VBox>
<!--parentDocument很牛B的办法 -->
<s:Button label="确认" id="produceConfirmButton" width="50" click="parentDocument.produceConfirmButton_clickHandler(event)"/>
</mx:VBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
editable="true"使DataGrid的每一列都可以编辑,如果某一列不想被编辑,如编号一般都不会允许编辑,就用editable="false"设定, 这样单击某单元格,就可以编辑了,编辑完毕之后单击确认,提交到数据库。代码如下:public function produceConfirmButton_clickHandler(event:MouseEvent):void { var id:int=producesell.selectedItem.id; var str:String=producesell.selectedItem.price; if(str==null||str=="") Alert.show("请输入价格","提示"); else { str=str.replace(/^s*|s*$/g,""); if(Number(str).toString()!="NaN") { var price:Number=(Number)(str); commUserservice.updatePriceFromWarehouse(id,price); } else { Alert.show("价格必须为数字","提示"); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |