Flex4 DataGrid中嵌入RadioButton实现思路及代码
程序员文章站
2022-07-10 15:14:45
<s:datagrid id="viewdg" width="100%" height="100%" fontfamily="微软雅黑" horizontalscrollpolicy="off" bordervisible="false" dataprovider="{viewlist}"> <s:columns> <s:arraylist> <s:gridcolumn width="{wid*0.02}" resizable="false" itemrenderer="module_schoolview.radiobuttongriditemrenderer"/> <s:gridcolumn width="{wid*0.25}" headertext="名称" datafield="xysj02" resizable="false"/> <s:gridcolumn width="{wid*0.25}" headertext="地名" datafield="xysj02name" resizable="false"/> <s:gridcolumn width="{wid*0.35}" headertext="url" datafield="xysj04" resizable="false"/> <s:gridcolumn width="{wid*0.13}" headertext="备注" datafield="xysj05" resizable="false"/> </s:arraylist> </s:columns> </s:datagrid>
mxml页面
<?xml version="1.0" encoding="utf-8"?> <s:griditemrenderer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"> <fx:declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:declarations> <fx:script> <![cdata[ //---------------------------------------------------------------------------------------------------------- override public function prepare(hasbeenrecycled:boolean):void { super.prepare( hasbeenrecycled ); // we make the radio button mimic the selection status of the whole row. const selected_items: vector.<object> = grid.datagrid.selecteditems; if( null == selected_items ) { radio_button.selected = false; return; } if( -1 != selected_items.indexof( data ) ) radio_button.selected = true; else radio_button.selected = false; } //---------------------------------------------------------------------------------------------------------- ]]> </fx:script> <!--the radio button is only a visual indicator for whether the row is selected or not. the "selected" property of the radio_button will be controlled by the "prepare" function. the radio_button should not be allowed any user interaction. hence disabling it.--> <s:radiobutton id="radio_button" label="" enabled="false" horizontalcenter="0" verticalcenter="0" /> </s:griditemrenderer>
上一篇: Flex 输出文件到本地的两种方法
下一篇: CSS3+Js实现响应式导航条
推荐阅读