flex datagrid DataGridColumn

找了好多次,竟然发现网上没有DataGridColumn itemRenderer   RadioButton,悲剧.

有一个这样的.


这样做真的很容易.容易的原因是他在一行,不会创建新的实例.


我需要的是这个效果



代码奉上:

<?xml version="1.0" encoding="utf-8"?>
<s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" width="780" height="530"
			   fontFamily="微软雅黑" fontSize="12"
			   close="closeHandler(event)" creationComplete="completeHandler(event)" xmlns:components="com.gwtjs.components.*">
	
	<fx:Script>
		<![CDATA[
			import com.gwtjs.entity.User;
			import com.gwtjs.renderer.grid.GridColumnRadioButton;
			
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.controls.Text;
			import mx.events.CloseEvent;
			import mx.events.FlexEvent;
			import mx.events.ListEvent;
			import mx.managers.PopUpManager;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			
			import spark.events.IndexChangeEvent;
			
			//修改时要用的store索引数
			public var arrIndex:int = 0;
			[Bindable]
			public var item:Object = new Object();
			[Bindable] public var action:String = "Insert";
			[Bindable] public var userIds:String = "";
			
			//用户角色寄存器
			private var userParentArray:ArrayCollection = new ArrayCollection();
			
			[Bindable]
			private var rolesArray:ArrayCollection = new ArrayCollection([
				{roleId:"0",roleName:"请选择角色"},
				{roleId:"10",roleName:"系统管理员",status:1,roleAuths:"",rolesAuthNames:"",roleDesc:"系统管理员,可操作其它角色,具备全部权限" },
				{roleId:"20",roleName:"安全管理员",status:1,roleAuths:"",rolesAuthNames:"",roleDesc:"系统管理员,可以自提漏洞工单的需求"},
				{roleId:"30",roleName:"检测负责人",status:1,roleAuths:"",rolesAuthNames:"",roleDesc:"系统管理员,检测漏洞"},
				{roleId:"40",roleName:"修复负责人",status:1,roleAuths:"",rolesAuthNames:"",roleDesc:"修复负责人,修复漏洞"}
			]);
			
			[Bindable]
			private var bugsArray:ArrayCollection = new ArrayCollection([
				{bugTypeCodes:"10",bugTypeNames:"成功入侵事件",status:1,bugLev:"高危",bugDesc:"成功入侵事件" },
				{bugTypeCodes:"20",bugTypeNames:"SQL 注射漏洞",status:1,bugLev:"中",bugDesc:"SQL 注射漏洞"},
				{bugTypeCodes:"30",bugTypeNames:"设计错误/逻辑缺陷",status:1,bugLev:"高危",bugDesc:"设计错误/逻辑缺陷"},
				
				{bugTypeCodes:"40",bugTypeNames:"重要敏感信息泄露",status:1,bugLev:"高危",bugDesc:"重要敏感信息泄露" },
				{bugTypeCodes:"50",bugTypeNames:"系统/服务运维配置不当",status:1,bugLev:"中",bugDesc:"系统/服务运维配置不当"},
				
				{bugTypeCodes:"60",bugTypeNames:"命令执行",status:1,bugLev:"常见",bugDesc:"命令执行"}
			]);
			
			/**上级用户*/
			[Bindable]
			private var userArray:ArrayCollection = new ArrayCollection([
				{userId:"1000101",userAccount:"playCol",userName:"张111",parentUser:"",userMobile:"13902762078",status:"1",userAclTypeCode:"10",userAclTypeNames:"超级管理员",bugTypeNames:"蠕虫病毒",bugTypeCodes:"1",userDesc:"说明"},
				{userId:"1000102",userAccount:"administrator",userName:"李芳",parentUser:"1000101",userMobile:"13902762078",status:"1",userAclTypeCode:"10",userAclTypeNames:"超级管理员",bugTypeNames:"木马植入",bugTypeCodes:"2",userDesc:"说明"},
				{userId:"10001",userAccount:"admin888",userName:"陈真",parentUser:"",userMobile:"13902762078",status:"1",userAclTypeCode:"10",userAclTypeNames:"超级管理员",bugTypeNames:"SQL注入",bugTypeCodes:"3",userDesc:"说明"},
				{userId:"10002",userAccount:"dzg867",userName:"王时",parentUser:"10001",userMobile:"13902762078",status:"1",userAclTypeCode:"20,30",userAclTypeNames:"安全管理员,检测人员",bugTypeNames:"木马植入",bugTypeCodes:"2",userDesc:"说明"},
				{userId:"10003",userAccount:"you29386",userName:"杨二辉",parentUser:"10002",userMobile:"13902762078",status:"1",userAclTypeCode:"30,40",userAclTypeNames:"检测人员",bugTypeNames:"SQL注入",bugTypeCodes:"3",userDesc:"说明"},
				{userId:"10004",userAccount:"zhang382",userName:"施文杰",parentUser:"10003",userMobile:"13902762078",status:"0",userAclTypeCode:"30",userAclTypeNames:"检测人员",bugTypeNames:"蠕虫病毒",bugTypeCodes:"1",userDesc:"说明"},
				{userId:"10005",userAccount:"guangdong",userName:"晓科",parentUser:"10003",userMobile:"13902762078",status:"1",userAclTypeCode:"20,40",userAclTypeNames:"安全管理员,修复人员",bugTypeNames:"SQL注入",bugTypeCodes:"3",userDesc:"说明"}
			]);
			
			[Bindable]
			public var items:ArrayCollection = new ArrayCollection();
			
			protected function closeHandler(event:CloseEvent):void
			{
				PopUpManager.removePopUp(this);
			}
			
			import mx.formatters.DateFormatter;
			public function compareTime(str:String):Boolean
			{
				var myPattern1:RegExp=/-|:| /g;
				
				var dateFormatter:DateFormatter = new DateFormatter();
				dateFormatter.formatString = "YYYY-MM-DD JJ:NN:SS";
				var now:String= dateFormatter.format(new Date());
				
				str = dateFormatter.format(str);
				str = str.replace(myPattern1,'');
				
				now = now.replace(myPattern1,'');
				if(Number(str)>Number(now)){return true;}else{return false;}
			}
			private function completeHandler(event:FlexEvent):void
			{
				var time:String = "2014-11-29 18:33:22";
				var bool:Boolean = compareTime(time);
				if(bool){
					trace("参考绑定",item.userAclTypeCode);
					trace(userAclTypeCode.text,parentUser.text);
					
					if(item!=null && item.userAclTypeCode!=null){
						var roleIds:Array = item.userAclTypeCode.split(",");
						for(var i:int=0;i<roleIds.length;i++){
							var role:Object = getRoleItem(roleIds[i]);
							userParentArray.addItem(role);
						}
						
					}
				}
			}
			
			private function setRolesArrayChecked():void
			{
			}
			
			/**
			 * 验证名称
			 */
			protected function nameChangeHandler(event:Event):void
			{
				//trace(Validator.validateAll(enNameValidator).length);
				if(Validator.validateAll(enNameValidator).length != 0) {
					userName.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_OVER));
				}
			}
			
			protected function saveBtnClickHandler(event:MouseEvent):void
			{
				var obj:Object = {};
				obj.userId = new Date().getDay()+""+new Date().getMilliseconds();
				obj.userAccount = userAccount.text;
				obj.userName = userName.text;
				obj.userMobile = userMobile.text;
				obj.status = status.selected;
				obj.parentUser = getSelectedUserParentCode();
				obj.parentUserName = getSelectedUserParentName();
				obj.userDesc = userDesc.text;
				trace(action,obj.parentUser,obj.parentUserName);
				if(action == "Insert"){
					items.addItemAt(obj,arrIndex);
				}else{
					obj.userAclTypeNames = item.userAclTypeNames;
					obj.bugTypeNames = item.bugTypeNames;
					obj.userId = item.userId;
					items.setItemAt(obj,arrIndex);
				}
				trace("items",items);
				trace(obj.userId,obj.userAccount,obj.userName,obj.userMobile,obj.status,obj.parentUser,obj.parentUserName,obj.userDesc);
				
				var user:User = new User();
				user.userId = "userId";
				user.userAccount = "userAccount";
				user.password = "password";
				user.userName = "userName";
				user.parentUser = "parentUser";
				user.userMobile = "userMobile";
				user.status = "status";
				user.userDesc = "userDesc";
				user.userAclTypeCode = "userAclTypeCode";
				user.userAclTypeNames = "userAclTypeNames";
				user.bugTypeCodes = "bugTypeCodes";
				user.bugTypeNames = "bugTypeNames";
				UserServicesController.saveOrUpdate(user);
				
				//
				PopUpManager.removePopUp(this);
			}
			
			/**比对是否存在**/
			private function validateUserSelected(id:String):Boolean
			{
				var bool:Boolean = false;
				for(var i:int=0;i<userParentArray.length;i++)
				{
					var obj:Object = userParentArray[i];
					if(id==obj.userId){
						return true;
					}
				}
				
				return bool;
			}
			
			/**获取某角色添加到寄存器*/
			private function getRoleItem(id:String):Object
			{
				var bool:Object = {};
				for(var i:int=0;i<userArray.length;i++)
				{
					var obj:Object = userArray[i];
					//trace(id,obj.roleId);
					if(id==obj.userId){
						bool = obj;
					}
				}
				return bool;
			}
			
			/**获取寄存器所有角色名称*/
			private function getSelectedUserParentName():String
			{
				var bool:String = "";
				for(var i:int=0;i<userParentArray.length;i++)
				{
					var obj:Object = userParentArray[i];
					bool+=obj.userName+",";
				}
				return bool.substr(0,bool.length-1);
			}
			
			/**获取寄存器所有角色标识*/
			private function getSelectedUserParentCode():String
			{
				var bool:String = "";
				for(var i:int=0;i<userParentArray.length;i++)
				{
					var obj:Object = userParentArray[i];
					bool+=obj.userId+",";
				}
				return bool.substr(0,bool.length-1);
			}
			
			protected function resetBtnClickHandler(event:MouseEvent):void
			{
				
			}
			
			/**
			 * 用户角色选择操作,用户角色临时寄存器
			 * */
			public function userSelectBoxChangeHandler(event:Event):void
			{
				var box:CheckBox = event.target as CheckBox;
				trace("TODO Auto-generated method stub\n",box.label);
				var bool:Boolean = validateUserSelected(box.label);
				trace("存在否",bool);
				if(!bool){
					var role:Object = getRoleItem(box.label);
					//trace(role);
					userParentArray.addItem(role);
				}
			}
			
			import  spark.components.RadioButton;
			/**
			 * 用户角色选择操作,用户角色临时寄存器
			 * */
			public function userSelectRadioChangeHandler(event:Event):void
			{
				var box:RadioButton = event.target as RadioButton;
				trace("group",box.group,"groupName",box.groupName,"name",box.name,"\n",box);
				myParentUserRadioButtonGroup.selection = box;
				var selObj:Object;
				for(var i:int =0 ;i<userArray.length;i++)
				{
					var obj:Object = userArray[i];
					if(box.value==obj.userId){
						//如果相同,selected=true;
						//obj.checked = true;
						selObj = obj;
					}else{
						//如果不同,selected=false;
						//obj.checked = false;
					}
					
				}
				myParentUserRadioButtonGroup.selectedValue = selObj;
			}
			
			protected function serverPagingBarFunctionHandler(event:Event):void
			{
				// TODO Auto-generated method stub
			}
			
			protected function bugTypesComboChangeHandler(event:IndexChangeEvent):void
			{
				// TODO Auto-generated method stub
			}
			
			protected function userRolesComboChangeHandler(event:IndexChangeEvent):void
			{
				var obj:Object = userRolesCombo.selectedItem;
				if(obj.roleName=="安全管理员")
				{
					bugTypesCombo.enabled = true;
				}else{
					bugTypesCombo.enabled = false;
				}
			}
			
			/**
			 * 请求异常
			 * 客户端的faultCode以Client开头,服务器端的faultCode以Server开头
			 * */
			private function httpServiceFault(event:FaultEvent):void
			{
				var str:String = "客户端异常";
				var index:int = -1;
				var faultCode:String = event.fault.faultCode.toString();
				index = faultCode.indexOf("Server", 0);
				if(index!=-1)
				{
					str= "服务端异常";
				}
				//trace(index,str);
				
				//客户端的faultCode以Client开头,服务器端的faultCode以Server开头
				Alert.show(event.fault.toString(),faultCode);
				trace(event.fault.toString());
			}
			
			/**
			 * 数据请求成功处理
			 * */
			private function saveOrUpdateResultHandler(event:ResultEvent):void
			{
				var obj:Object = event.result;
				trace(obj);
				Alert.show(obj.toString(),"保存成功");
			}

		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处
		-->
		<fx:Array id="enNameValidator">
			<mx:Validator property="text" source="{userAccount}"
						  required="true" requiredFieldError="请输入登陆帐号" />
			<mx:StringValidator property="text" source="{userAccount}"
								tooShortError="字符串太短了,请输入最少3个字符. "
								tooLongError="字符串太长了,请输入最长32个字符. "
								minLength="3" maxLength="32"/>
			<mx:RegExpValidator property="text" source="{userAccount}"
								flags="g,i" expression="^[a-zA-Z]\w+$"
								noMatchError="请输入3到32位英文字母与数字,且英文字母在前数字在后"
								trigger="{saveBtn}" triggerEvent="click"
								required="true"/>
		</fx:Array>
		
		<!--无猜中远程调用-->
		<s:RemoteObject id="UserServicesController" destination="UserServicesController" fault="httpServiceFault(event)"
						endpoint="http://127.0.0.1:8080/buganalysis/messagebroker/amf">
			<s:method name="saveOrUpdate" result="saveOrUpdateResultHandler(event)" />
		</s:RemoteObject>
		
		<s:RadioButtonGroup id="myParentUserRadioButtonGroup" />
		
	</fx:Declarations>
	
	<mx:Form textAlign="left" verticalGap="0" width="100%" height="568" paddingLeft="6" paddingRight="6" paddingBottom="6" paddingTop="6">
		
		<mx:HBox width="100%" height="32">
			<mx:FormItem label="登陆账号:" width="50%" height="32" horizontalAlign="center">
				<s:TextInput id="userAccount"
							 text="{item.userAccount}" textAlign="left" width="100%"/>
			</mx:FormItem>
			<mx:FormItem label="用户姓名:" width="50%" height="32" horizontalAlign="center">
				<s:TextInput id="userName"
							 text="{item.userName}" textAlign="left" width="100%"/>
			</mx:FormItem>
			
			<mx:FormItem label="工号状态正常:" horizontalAlign="center" width="0" height="0" visible="false" >
				<s:CheckBox id="status" selected="{item.status!=null}" textAlign="left" width="100%"/>
			</mx:FormItem>
		</mx:HBox>
		
		<mx:HBox width="100%" height="32">
			<mx:FormItem label="角色选择:" width="50%" height="32" horizontalAlign="center">
				<s:ComboBox dataProvider="{rolesArray}" skinClass="assets.skin.ComboBoxTextInputEditSkin" width="100%" labelField="roleName"
							id="userRolesCombo" change="userRolesComboChangeHandler(event)" />
			</mx:FormItem>
			<mx:FormItem label="权限类型:" width="50%" height="32" horizontalAlign="center">
				<s:ComboBox dataProvider="{bugsArray}" skinClass="assets.skin.ComboBoxTextInputEditSkin" enabled="false" selectedIndex="1" 
                                                   width="100%" labelField="bugTypeNames"
							id="bugTypesCombo" change="bugTypesComboChangeHandler(event)" />
			</mx:FormItem>
		</mx:HBox>
		
		<mx:HBox width="100%" height="32">
			<mx:FormItem label="用户密码:" width="100%" height="32" horizontalAlign="center">
				<s:TextInput id="userPwd" displayAsPassword="true"
							 text="{item.userPwd}" textAlign="left" width="100%"/>
			</mx:FormItem>
			<mx:FormItem label="重复密码:" width="100%" height="32" horizontalAlign="center">
				<s:TextInput id="userOldPwd" displayAsPassword="true"
							 text="{item.userOldPwd}" textAlign="left" width="100%"/>
			</mx:FormItem>
		</mx:HBox>
		<mx:FormItem label="手机号:" width="100%" height="32" horizontalAlign="center">
			<s:TextInput id="userMobile"
						 text="{item.userMobile}" textAlign="left" width="100%"/>
		</mx:FormItem>
		
		<mx:FormItem label="上级用户:" width="100%" height="228" horizontalAlign="center">
			<mx:DataGrid id="userParentUserGrid" width="100%" height="100%" dataProvider="{userArray}" >
				<mx:columns>
					<mx:DataGridColumn headerText="选择" textAlign="left" width="58">
						<mx:itemRenderer>
							<fx:Component>
								<mx:HBox textAlign="left" verticalAlign="middle" horizontalAlign="center">
									<s:RadioButton value="{data.userId}" textAlign="left" name="parent_user"
												   group="{outerDocument.myParentUserRadioButtonGroup}"
												   groupName="myParentUserRadioButtonGroup" selected="{data.checked}" 
												   change="outerDocument.userSelectRadioChangeHandler(event)" />
								</mx:HBox>
							</fx:Component>
						</mx:itemRenderer>
					</mx:DataGridColumn>
					<mx:DataGridColumn headerText="用户编号" dataField="userId" textAlign="left" width="78">
					</mx:DataGridColumn>
					<mx:DataGridColumn headerText="用户姓名" dataField="userName" textAlign="left" width="160" />
				</mx:columns>
			</mx:DataGrid>
			<components:Pager id="parentUserServerPagingBar1" url="USER_DATAGRID" datagrid="{userParentUserGrid}" pageSize="3"
							  myFunction="serverPagingBarFunctionHandler(event)"
							  destination="userFlexServices" methodName="getUsers" height="26" width="100%" />
		</mx:FormItem>
		
		<mx:FormItem label="用户说明:" width="100%" height="88" horizontalAlign="center" paddingTop="6">
			<s:TextArea id="userDesc" text="{item.userDesc}" textAlign="left" width="100%" maxChars="218" height="68" >
			</s:TextArea>
		</mx:FormItem>
		<mx:HBox visible="false" height="0">
			<s:TextInput text="{item.userAclTypeCode}" id="userAclTypeCode" visible="false" height="0" />
			<s:TextInput text="{item.userNames}" id="parentUser" visible="false" height="0" />
			
			<s:TextInput id="roleId" height="0" visible="false"
						 text="{item.roleId}" textAlign="left" width="100%"/>
		</mx:HBox>
		<mx:HBox width="100%" height="32" horizontalAlign="center" verticalAlign="middle">
			<s:Button label="重置" id="resetBtn" click="resetBtnClickHandler(event)" />
			<s:Button label="保存" id="saveBtn" click="saveBtnClickHandler(event)" />
		</mx:HBox>
	</mx:Form>








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值