显视flex DataGrid的两种方法
<?xml version="1.0" encoding="utf-8"?><s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" creationComplete="showEmployeeInforList()" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%" xmlns:flexas="flexas.*"><fx:Declarations><!-- 将非可视元素(例如服务、值对象)放在此处 --><s:RemoteObject destination="employeeService" fault="initFault(event)" endpoint="http://localhost:8088/phmis/messagebroker/amf"result="initSuccess(event)" id="employeeServiceRo"/></fx:Declarations><fx:Script><![CDATA[import flexas.*;import mx.collections.ArrayCollection;import mx.controls.Alert;import mx.events.CloseEvent;import mx.managers.PopUpManager;import mx.rpc.events.FaultEvent;import mx.rpc.events.ResultEvent;import mxml.component.add;import mxml.component.infoWindow;[Bindable]private var dp:ArrayCollection=new ArrayCollection();[Bindable]private var all:int=0;[Bindable]private var count:int=0;private var k:int=10;[Bindable]private var step:int=10;[Bindable]public var resX:int = Capabilities.screenResolutionX; protected function showEmployeeInforList():void{//employeeServiceRo.listAll(0,10);employeeServiceRo.listAlls(0,10);//employeeServiceRo.listAll();}protected function initSuccess(event:ResultEvent):void{//var arr:ArrayCollection=event.result as ArrayCollection;dp.removeAll();dp =event.result as ArrayCollection;if(this.dp != null && this.dp.length>=1){//dg.selectedIndex = 0;}//all = 0;//var arrLength = arr.length-1;////all = int(arr[arrLength]);//if(arr != null){////Alert.show("all="+all);//}////for(var i:int=0;i<arrLength;i++){//var o:Object=new Object();////o.employeeid=arr[i][0];//o.username=arr[i][1];//o.sex=arr[i][2];//o.birthdate=arr[i][3];//o.cardid=arr[i][4];////o.phone=arr[i][5]; //o.address=arr[i][6];//o.departmentid=arr[i][7];//o.postid=arr[i][8];//o.workfromdate=arr[i][9];////o.degree=arr[i][10];//o.politics=arr[i][11];//o.skills=arr[i][12];//o.remark=arr[i][13];////dp.addItem(o);//}}protected function initFault(event:FaultEvent):void{Alert.show("错误"+event.message);Alert.show("加载数据列表错误");}public function $f_viewOneRecord(obj:Object):void{var w:infoWindow=new infoWindow();PopUpManager.addPopUp(w,this);PopUpManager.centerPopUp(w);w.data=obj;}//弹出增加对话框protected function addOneRecord(event:MouseEvent,resX:Number):void{var addDialog :employeeinfoadd = new employeeinfoadd();PopUpManager.addPopUp(addDialog,this);PopUpManager.centerPopUp(addDialog);addDialog.data ="width";//+ resX;}//删除一条记录protected function deleteOneRecord(event:MouseEvent):void{if(dg.selectedItem==null){return ;}else{Alert.show("确定删除该记录吗?","提示",1|2,this,CHandler);}}private function CHandler(e:CloseEvent):void{if(e.detail==Alert.YES){var o:Object=dg.selectedItem;//remote1.deleteItem(int(o.num));}else{return ;}}public function add(){employeeServiceRo.add("bbbbbbbbbbb","name");//employeeServiceRo.listAll(0,10);//Alert.show("add = ");}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{//remote1.saveItem(names,age,sex,tel,dept,job,birthday,comeday,workage,ids,home,edu,hobby,etc);}private function toFirstPage(event:MouseEvent):void{$f_list(0,10);//改成由后台处理不用传参数count = 0;}private function toPreviousPage(event:MouseEvent):void{$f_list(step*(count-1),step*count);count --;}private function toNextPage(event:MouseEvent):void{$f_list(step*(count+1),step*(count+2));count ++;}private function toLastePage(event:MouseEvent):void{var index:int = ((step-(all%step))+all)/step; //总的页数$f_list(step*(index-1),all);count = index -1;}private function $f_list (start:int,end:int):void{//remote1.getInfo(start,end);}]]></fx:Script><s:Panel height="100%" width="100%" right="0" top="0" bottom="0" left="0" ><s:VGroup right="0" bottom="0" left="0" top="0" height="100%" width="100%"><mx:DataGrid width="100%" height="350" id="dg" dataProvider="{dp}" left="0" allowMultipleSelection="true" editable="true"><mx:columns><flexas:CheckBoxColumn dataField="isSelected" width="25" id="selected" draggable="false" resizable="false" sortable="false" headerRenderer="{new ClassFactory(CheckBoxHeader)}" itemRenderer="{new ClassFactory(CheckBoxRenderer)}"></flexas:CheckBoxColumn><mx:DataGridColumn headerText="人员编号" dataField="employeeid" editable="false"><mx:itemRenderer><fx:Component><mx:LinkButton label="{data.employeeid}" click="this.outerDocument.$f_viewOneRecord(data);" ></mx:LinkButton></fx:Component></mx:itemRenderer></mx:DataGridColumn><mx:DataGridColumn headerText="人员姓名" dataField="username" editable="false"/><mx:DataGridColumn headerText="性别" dataField="sex"/><mx:DataGridColumn headerText="出生日期" dataField="birthdate"/><mx:DataGridColumn headerText="身份证号码" dataField="cardid"/><mx:DataGridColumn headerText="联系电话" dataField="phone"/><mx:DataGridColumn headerText="地址" dataField="address" editable="false"></mx:DataGridColumn><mx:DataGridColumn headerText="所属部门" dataField="departmentid" editable="false"></mx:DataGridColumn><mx:DataGridColumn headerText="工作岗位" dataField="postid" editable="false"></mx:DataGridColumn><mx:DataGridColumn headerText="参加工作时间" dataField="workfromdate" editable="false"></mx:DataGridColumn><mx:DataGridColumn headerText="文化程度" dataField="degree" editable="false"></mx:DataGridColumn><mx:DataGridColumn headerText="政治面貌" dataField="politics" editable="false"></mx:DataGridColumn><mx:DataGridColumn headerText="职业技能" dataField="skills" editable="false"></mx:DataGridColumn><mx:DataGridColumn headerText="备注" dataField="remark" editable="false"></mx:DataGridColumn></mx:columns></mx:DataGrid><mx:HBox verticalAlign="middle" horizontalAlign="center" height="36" width="100%" bottom="10" left="0" top="50" ><s:Label text="共有:"/><s:Label text="{all}"/><s:Label text="条记录"/><s:Label text="当前第:"/><s:Label text="{count+1}"/><s:Label text="页"/><s:Button label="增加" click="add()"/><s:Button label="第一页" enabled="{count>0?true:false}" click="toFirstPage(event)"/><s:Button label="上一页" enabled="{count>0?true:false}" click="toPreviousPage(event)"/><s:Button label="下一页" enabled="{(count+1)*step+1> all?false:true}" click="toNextPage(event)"/><s:Button label="最后页" enabled="{(count+1)*step+1> all?false:true}" click="toLastePage(event)"/><s:Button label="删除" click="deleteOneRecord(event)"/></mx:HBox></s:VGroup></s:Panel></s:Application>?