首页 > 代码库 > Flex真真的分页,一个页面支持多次复用
Flex真真的分页,一个页面支持多次复用
<?xml version="1.0" encoding="utf-8"?> <mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="initHandler(event)" width="100%" height="300" backgroundColor="0xffffff"> <fx:Script> <![CDATA[ import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.controls.DataGrid; import mx.events.FlexEvent; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.rpc.remoting.RemoteObject; [Bindable] //记录数 private var items:ArrayCollection; [Bindable] //分页参数 private var params:Array = new Array(); [Bindable] //每页显示的条数 private var pageSizeBoxListData:ArrayCollection = new ArrayCollection([ {pageSize:10}, {pageSize:20}, {pageSize:30}, {pageSize:50}, {pageSize:100} ]); [Bindable] //每页显示的记录数 public var pageSize:int = 10; [Bindable] //当前页 public var curPage:int = 1; [Bindable] //下一页到多少记录数 public var offSet:int = 1; [Bindable] //总页数 public var totalPage:int = 0; [Bindable] //总记录数 public var totalCount:int = 263; public var destination:String; public var methodName:String; [Bindable] //组件宽度 public var widthTo:int; [Bindable] //服务请求地址 public var url:String; [Bindable] //datagrid public var datagrid:DataGrid; /** * */ protected function progressBarClickHandler(event:MouseEvent):void { var bc:HBox = HBox(event.target); widthTo = event.localX; progressBarEffect.target = progressBarPagerBlue; progressBarEffect.play(); } /** * */ private function getMinimum():int { if(totalCount < 1) { return 0; } else { return 1; } } /** * */ protected function pageFirstClickHandler(event:MouseEvent):void { curPage = getMinimum(); getBtnEnabled(); pagingRemoteObject(); } /** * 上一页 */ protected function pagePrevClickHandler(event:MouseEvent):void { var tempNum:int = getMinimum(); curPage = curPage - 1; getBtnEnabled(); pagingRemoteObject(); } /** * 跳转到指定页 */ protected function pageStepperClickHandler(event:MouseEvent):void { curPage = pageStepper.value; } /** * 下一页 */ protected function pageNextClickHandler(event:MouseEvent):void { if(curPage < totalPage) { curPage = curPage + 1; } getBtnEnabled(); pagingRemoteObject(); } /** * 最后一页 */ protected function pageLastClickHandler(event:MouseEvent):void { curPage = totalPage; getBtnEnabled(); pagingRemoteObject(); } /** * 刷新当前页 */ protected function pageRefreshClickHandler(event:MouseEvent):void { totalPage = getTotalPageNum(); pagingRemoteObject(); } /** * 初始化函数 */ protected function initHandler(event:FlexEvent):void { totalPage = getTotalPageNum(); } /** * 设置每页显示多少条记录 */ protected function pageSizeComboboxChangeHandler(event:MouseEvent):void { var obj:Object = pageSizeCombobox.selectedItem; pageSize = obj.pageSize; trace(url,"",pageSize); } /** * 获取总页数 */ private function getBtnEnabled():void { if(totalPage < 1) { pageFirstBtn.enabled = false; pagePreBtn.enabled = false; pageNextBtn.enabled = false; pageLastBtn.enabled = false; pageRefreshBtn.enabled = false; } else if(curPage == 1) { pageFirstBtn.enabled = false; pagePreBtn.enabled = false; pageNextBtn.enabled = true; pageLastBtn.enabled = true; pageRefreshBtn.enabled = true; } else if(curPage < totalPage && curPage > 1) { pageFirstBtn.enabled = true; pagePreBtn.enabled = true; pageNextBtn.enabled = true; pageLastBtn.enabled = true; pageRefreshBtn.enabled = true; } else if(curPage == totalPage) { pageFirstBtn.enabled = true; pagePreBtn.enabled = true; pageNextBtn.enabled = false; pageLastBtn.enabled = false; pageRefreshBtn.enabled = true; } } /** * 服务请求成功的处理 */ private function serviceSuccessResult(event:ResultEvent):void { totalCount = event.result.totalCounts; items = event.result.entityList as ArrayCollection; trace(url,"",items); } /** * 服务请求失败的处理 */ private function httpServiceFault(event:FaultEvent):void { Alert.show(event.fault.message,"服务请求失败"); } /** * 发送服务请求 */ private function pagingRemoteObject():void { var remote:RemoteObject = new RemoteObject(destination); offSet = (curPage - 1)*pageSize; remote.getOperation(methodName).send(pageSize,offSet); remote.addEventListener(ResultEvent.RESULT,serviceSuccessResult); remote.addEventListener(FaultEvent.FAULT,httpServiceFault); } /** * */ private function loadingDatagrid():void { } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <mx:HBox width="30%" height="100%" verticalAlign="middle"> <mx:LinkButton styleName="pageFirstBtn" id="pageFirstBtn" enabled="false" click="pageFirstClickHandler(event)"/> <mx:LinkButton styleName="pagePreBtn" id="pagePreBtn" enabled="false" click="pagePrevClickHandler(event)"/> <mx:LinkButton styleName="pageNextBtn" id="pageNextBtn" enabled="false" click="pageNextClickHandler(event)"/> <mx:LinkButton styleName="pageLastBtn" id="pageLastBtn" enabled="false" click="pageLastClickHandler(event)"/> </mx:HBox> <mx:HBox width="40%" height="100%" verticalAlign="middle"> <s:Label text="Page"/> <s:NumericStepper id="pageStepper" width="78" click="pageStepperClickHandler(event)" maximum="{totalPage}" minimum="{getMinimum()}" value=http://www.mamicode.com/"{curPage}"/>>Flex真真的分页,一个页面支持多次复用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。