显视flex DataGrid的两种方法

简介:
Xml代码   收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"  creationComplete="showEmployeeInforList()"  
  3.            xmlns:s="library://ns.adobe.com/flex/spark"   
  4.            xmlns:mx="library://ns.adobe.com/flex/mx"  width="100%" height="100%" xmlns:flexas="flexas.*">  
  5.     <fx:Declarations>  
  6.         <!-- 将非可视元素(例如服务、值对象)放在此处 -->  
  7.         <s:RemoteObject destination="employeeService" fault="initFault(event)"  endpoint="http://localhost:8088/phmis/messagebroker/amf"  
  8.                         result="initSuccess(event)" id="employeeServiceRo"/>  
  9.           
  10.     </fx:Declarations>  
  11.     <fx:Script>  
  12.         <![CDATA[ 
  13.             import flexas.*; 
  14.              
  15.             import mx.collections.ArrayCollection; 
  16.             import mx.controls.Alert; 
  17.             import mx.events.CloseEvent; 
  18.             import mx.managers.PopUpManager; 
  19.             import mx.rpc.events.FaultEvent; 
  20.             import mx.rpc.events.ResultEvent; 
  21.              
  22.             import mxml.component.add; 
  23.             import mxml.component.infoWindow; 
  24.              
  25.             [Bindable] 
  26.             private var dp:ArrayCollection=new ArrayCollection(); 
  27.              
  28.             [Bindable] 
  29.             private var all:int=0; 
  30.              
  31.             [Bindable] 
  32.             private var count:int=0; 
  33.              
  34.             private var k:int=10; 
  35.              
  36.             [Bindable] 
  37.             private var step:int=10; 
  38.              
  39.             [Bindable] 
  40.             public var resX:int = Capabilities.screenResolutionX;   
  41.              
  42.             protected function showEmployeeInforList():void{ 
  43. //              employeeServiceRo.listAll(0,10); 
  44.                 employeeServiceRo.listAlls(0,10); 
  45. //              employeeServiceRo.listAll(); 
  46.             } 
  47.              
  48.             protected function initSuccess(event:ResultEvent):void 
  49.             { 
  50. //              var arr:ArrayCollection=event.result as ArrayCollection; 
  51.                 dp.removeAll(); 
  52.                 dp =event.result as ArrayCollection; 
  53.                 if(this.dp != null && this.dp.length>=1){ 
  54. //                  dg.selectedIndex = 0; 
  55.                 } 
  56. //              all = 0; 
  57. //              var arrLength = arr.length-1; 
  58. //                   
  59. //              all = int(arr[arrLength]); 
  60. //              if(arr != null){ 
  61. ////                    Alert.show("all="+all); 
  62. //              } 
  63. //               
  64. //              for(var i:int=0;i<arrLength;i++){ 
  65. //                  var o:Object=new Object(); 
  66. //                   
  67. //                  o.employeeid=arr[i][0]; 
  68. //                  o.username=arr[i][1]; 
  69. //                  o.sex=arr[i][2]; 
  70. //                  o.birthdate=arr[i][3]; 
  71. //                  o.cardid=arr[i][4]; 
  72. //                   
  73. //                  o.phone=arr[i][5];   
  74. //                  o.address=arr[i][6]; 
  75. //                  o.departmentid=arr[i][7]; 
  76. //                  o.postid=arr[i][8]; 
  77. //                  o.workfromdate=arr[i][9]; 
  78. //                   
  79. //                  o.degree=arr[i][10]; 
  80. //                  o.politics=arr[i][11]; 
  81. //                  o.skills=arr[i][12]; 
  82. //                  o.remark=arr[i][13]; 
  83. //                   
  84. //                  dp.addItem(o); 
  85. //              } 
  86.             } 
  87.              
  88.             protected function initFault(event:FaultEvent):void 
  89.             { 
  90.                 Alert.show("错误"+event.message); 
  91.                 Alert.show("加载数据列表错误"); 
  92.                  
  93.             } 
  94.              
  95.              
  96.             public function $f_viewOneRecord(obj:Object):void{ 
  97.                 var w:infoWindow=new infoWindow(); 
  98.                 PopUpManager.addPopUp(w,this); 
  99.                 PopUpManager.centerPopUp(w); 
  100.                 w.data=obj; 
  101.             } 
  102.              
  103.              
  104.             //弹出增加对话框 
  105.             protected function addOneRecord(event:MouseEvent,resX:Number):void 
  106.             { 
  107.                 var addDialog :employeeinfoadd = new employeeinfoadd(); 
  108.                 PopUpManager.addPopUp(addDialog,this); 
  109.                 PopUpManager.centerPopUp(addDialog); 
  110.                 addDialog.data ="width";//+ resX; 
  111.             } 
  112.              
  113.             //删除一条记录 
  114.             protected function deleteOneRecord(event:MouseEvent):void 
  115.             { 
  116.                 if(dg.selectedItem==null){ 
  117.                     return ; 
  118.                 }else{ 
  119.                     Alert.show("确定删除该记录吗?","提示",1|2,this,CHandler); 
  120.                 } 
  121.             } 
  122.             private function CHandler(e:CloseEvent):void{ 
  123.                 if(e.detail==Alert.YES){ 
  124.                     var o:Object=dg.selectedItem; 
  125. //                  remote1.deleteItem(int(o.num)); 
  126.                 }else{ 
  127.                     return ; 
  128.                 } 
  129.             } 
  130.              
  131.             public   function add(){ 
  132.                 employeeServiceRo.add("bbbbbbbbbbb","name"); 
  133. //              employeeServiceRo.listAll(0,10); 
  134. //              Alert.show("add = "); 
  135.             } 
  136.             public function saveItem(names:String,age:int,sex:String,tel:String,dept:String,job:String,birthday:String,comeday:String,workage:int,ids:String,home:String,edu:String,hobby:String,etc:String):void{ 
  137. //              remote1.saveItem(names,age,sex,tel,dept,job,birthday,comeday,workage,ids,home,edu,hobby,etc); 
  138.             } 
  139.              
  140.             private function toFirstPage(event:MouseEvent):void{ 
  141.                 $f_list(0,10);//改成由后台处理不用传参数 
  142.                 count = 0; 
  143.             } 
  144.              
  145.             private function toPreviousPage(event:MouseEvent):void{ 
  146.                 $f_list(step*(count-1),step*count); 
  147.                 count --; 
  148.             } 
  149.              
  150.             private function toNextPage(event:MouseEvent):void{ 
  151.                 $f_list(step*(count+1),step*(count+2)); 
  152.                 count ++; 
  153.             } 
  154.              
  155.             private function toLastePage(event:MouseEvent):void{ 
  156.                 var index:int = ((step-(all%step))+all)/step; //总的页数 
  157.                 $f_list(step*(index-1),all); 
  158.                 count = index -1;    
  159.             } 
  160.              
  161.             private function $f_list (start:int,end:int):void{ 
  162. //              remote1.getInfo(start,end); 
  163.             } 
  164.              
  165.         ]]>  
  166.     </fx:Script>  
  167.       
  168.     <s:Panel height="100%" width="100%" right="0" top="0" bottom="0" left="0" >  
  169.             <s:VGroup  right="0" bottom="0" left="0" top="0" height="100%" width="100%">    
  170.       
  171.                 <mx:DataGrid width="100%" height="350" id="dg" dataProvider="{dp}" left="0" allowMultipleSelection="true" editable="true">  
  172.                     <mx:columns>  
  173.                         <flexas:CheckBoxColumn dataField="isSelected" width="25" id="selected"   
  174.                                                draggable="false" resizable="false" sortable="false"   
  175.                                                headerRenderer="{new ClassFactory(CheckBoxHeader)}"   
  176.                                                itemRenderer="{new ClassFactory(CheckBoxRenderer)}">  
  177.                         </flexas:CheckBoxColumn>  
  178.                         <mx:DataGridColumn headerText="人员编号" dataField="employeeid"  editable="false">  
  179.                             <mx:itemRenderer>  
  180.                                 <fx:Component>  
  181.                                     <mx:LinkButton label="{data.employeeid}" click="this.outerDocument.$f_viewOneRecord(data);" >  
  182.                                     </mx:LinkButton>  
  183.                                 </fx:Component>  
  184.                             </mx:itemRenderer>  
  185.                         </mx:DataGridColumn>  
  186.                         <mx:DataGridColumn headerText="人员姓名" dataField="username"  editable="false"/>  
  187.                         <mx:DataGridColumn headerText="性别" dataField="sex"/>  
  188.                         <mx:DataGridColumn headerText="出生日期" dataField="birthdate"/>  
  189.                         <mx:DataGridColumn headerText="身份证号码" dataField="cardid"/>  
  190.                         <mx:DataGridColumn headerText="联系电话" dataField="phone"/>  
  191.                         <mx:DataGridColumn headerText="地址" dataField="address"  editable="false"></mx:DataGridColumn>  
  192.                         <mx:DataGridColumn headerText="所属部门" dataField="departmentid"  editable="false"></mx:DataGridColumn>  
  193.                         <mx:DataGridColumn headerText="工作岗位" dataField="postid"  editable="false"></mx:DataGridColumn>  
  194.                         <mx:DataGridColumn headerText="参加工作时间" dataField="workfromdate"  editable="false"></mx:DataGridColumn>  
  195.                         <mx:DataGridColumn headerText="文化程度" dataField="degree"  editable="false"></mx:DataGridColumn>  
  196.                         <mx:DataGridColumn headerText="政治面貌" dataField="politics"  editable="false"></mx:DataGridColumn>  
  197.                         <mx:DataGridColumn headerText="职业技能" dataField="skills"  editable="false"></mx:DataGridColumn>  
  198.                         <mx:DataGridColumn headerText="备注" dataField="remark"  editable="false"></mx:DataGridColumn>  
  199.                     </mx:columns>  
  200.                 </mx:DataGrid>  
  201.                   
  202.                 <mx:HBox verticalAlign="middle" horizontalAlign="center" height="36" width="100%" bottom="10" left="0" top="50" >  
  203.                     <s:Label text="共有:"/>  
  204.                     <s:Label text="{all}"/>  
  205.                     <s:Label text="条记录"/>  
  206.                     <s:Label text="当前第:"/>  
  207.                     <s:Label text="{count+1}"/>  
  208.                     <s:Label text="页"/>  
  209.                     <s:Button label="增加" click="add()"/>  
  210.                     <s:Button label="第一页" enabled="{count>0?true:false}" click="toFirstPage(event)"/>  
  211.                     <s:Button label="上一页" enabled="{count>0?true:false}" click="toPreviousPage(event)"/>  
  212.                     <s:Button label="下一页" enabled="{(count+1)*step+1> all?false:true}" click="toNextPage(event)"/>  
  213.                     <s:Button label="最后页" enabled="{(count+1)*step+1> all?false:true}" click="toLastePage(event)"/>  
  214.                     <s:Button label="删除" click="deleteOneRecord(event)"/>  
  215.                 </mx:HBox>  
  216.             </s:VGroup>  
  217.     </s:Panel>  
  218. </s:Application>  
相关文章
flex布局属性简介
flex布局属性简介
|
7月前
|
前端开发 开发者 容器
flex和grid布局
flex和grid布局
CSS3【display: flex;】与【align-items: 侧轴对齐方式;】的使用
CSS3【display: flex;】与【align-items: 侧轴对齐方式;】的使用
78 0
CSS3 【display: flex;】与【align-self: 可覆盖父元素设置的algin-items;】的使用
CSS3 【display: flex;】与【align-self: 可覆盖父元素设置的algin-items;】的使用
53 0
CSS3 【display: flex;】与【align-self: 可覆盖父元素设置algin-items;】的使用
CSS3 【display: flex;】与【align-self: 可覆盖父元素设置algin-items;】的使用
76 0
|
测试技术 容器
Easyui datagrid 扩展单元格textarea editor
Easyui datagrid 扩展单元格textarea editor
300 0
|
前端开发
css中 vertical-align 属性的应用和案例
vertical-align 属性应用 css的 vertical - align 属性使用场景:经常用于设置图片或者表单(行内块元素)和文字垂直对齐。 官方解释:用于设置一个元素的垂直对齐方式,但是它只针对于行内元素或者行内块元素有效。
110 0
css中 vertical-align 属性的应用和案例
为控件动态添加Style
原文:为控件动态添加Style 此文可解决:  重写控件时,给控件加入子控件或父控件的样式切换问题。 很灵活的可以根据不同内容显示不同样式   子控件作用在: ...
836 0
|
XML 存储 数据格式