加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex 组件分页

发布时间:2020-12-15 04:06:11 所属栏目:百科 来源:网络整理
导读:?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="loadData(1)" ? fx:Script ? ![CDATA[? impo
<?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="loadData(1)"> ?
<fx:Script> ?
<![CDATA[?
import mx.collections.ArrayCollection;
import mx.controls.DataGrid;

[Bindable]?
[Embed(source='assets/first.jpg')]?
public var firstIcon:Class; ? ? ? ? ? ? ? ?
public var firstPage:uint; ?

[Bindable]?
[Embed(source='assets/pre.jpg')]?
public var preIcon:Class;?
public var prePage:uint; ?

[Bindable]?
[Embed(source='assets/next.jpg')]?
public var nextIcon:Class;?
public var nextPage:uint; ?

[Bindable]?
[Embed(source='assets/last.jpg')]?
public var lastIcon:Class;?
public var lastPage:uint;?

//每页显示的数据数 (如果 调用该组件的页面不设置,默认为15)
[Bindable]
public var pageSize:int=15;
//总页数
[Bindable]
public var totalPage:int=1;
//当前页
[Bindable]
public var currentPage:int=1;
//总记录数?
[Bindable]
public var totalClum:int=0;

//所有的数据
public var orgData:ArrayCollection=null;
//显示到Grid的数据
[Bindable]
public var viewData:ArrayCollection=null;

//分页条对应的Grid
public var dataGrid:DataGrid=null;

//分页函数?
public var localFunction:Function=null;?

//重新为当前页的变量赋值?
public function loadData(pageNum:int):void{?
? ??this.totalPage =Math.ceil(this.totalClum/this.pageSize);?
? ??if(pageNum > 0 && pageNum <= this.totalPage){?
? ? ? ??this.currentPage=pageNum;?
? ? ? ? var firstNum:int = (currentPage-1) * pageSize;
? ? ? ? var lastNum:int = firstNum + pageSize - 1;
? ? ? ? if(lastNum > (totalClum-1)){
? ? ? ? ? ? lastNum = totalClum - 1;
? ? ? ??}
? ? ? ??var dataArr:Array = orgData.source;
? ? ? ??var newArr:Array = new Array();
? ? ? ??for(var i:int=firstNum;i<=lastNum;i++){
? ? ? ? ? ??newArr.push(dataArr[i]);
? ? ? ??}
? ? ? ??viewData = new ArrayCollection();
? ? ? ??viewData.source = newArr; ? ?
? ? ? ??dataGrid.dataProvider = viewData;
? ??}?
}?

]]> ?
</fx:Script> ?

<mx:Text id="temp" text="" visible="false" includeInLayout="false"/> ?
<mx:HBox?verticalGap="0" horizontalGap="0" horizontalAlign="center" verticalAlign="middle"> ??
<mx:Text text="{' ? 共'+(totalClum)+'条记录'}" fontSize="12"/> ? ? ? ? ? ? ? ? ?
<mx:Button id="firstNavBtn" icon="{firstIcon}" width="10" height="10" click="loadData(1)" enabled=" {lbtnPrevious.enabled}"/> ?
<mx:LinkButton id="lbtnFirst" label="首页" click="loadData(1)" enabled="{lbtnPrevious.enabled}" fontSize="12"/> ?
<mx:Button id="preNavBtn" icon="{preIcon}" width="7" height="10" click="loadData(currentPage-1)" enabled="{currentPage!=1? true:false}"/> ?
<mx:LinkButton id="lbtnPrevious" label="上一页" click="loadData(currentPage-1)" enabled="{currentPage!=1?true:false}" fontSize="12"/> ?

<mx:Text text="{'【 '+(Math.ceil(this.totalClum/this.pageSize)>0?(currentPage):1)+'/'+ (Math.ceil(this.totalClum/this.pageSize)>0?Math.ceil(this.totalClum/this.pageSize):1)+'页】 ?'}" fontSize="12"/> ?

<mx:Button id="nextNavBtn" icon="{nextIcon}" width="7" height="10" click="loadData(currentPage+1)" enabled=" {Math.ceil(this.totalClum/this.pageSize)>(currentPage)?true:false}"/> ?
<mx:LinkButton id="lbtnNext" label="下一页" click="loadData(currentPage+1)" enabled=" {Math.ceil(this.totalClum/this.pageSize)>(currentPage)?true:false}" fontSize="12"/> ?

<mx:Button id="lastNavBtn" icon="{lastIcon}" width="10" height="10" click="loadData(Math.ceil(this.totalClum/this.pageSize))" enabled="{lbtnNext.enabled}"/> ?
<mx:LinkButton id="lbtnLast" label="尾页" click="loadData(Math.ceil(this.totalClum/this.pageSize))" enabled=" {lbtnNext.enabled}" fontSize="12"/> ?

<mx:Label text="跳转到"/> ?
<mx:NumericStepper id="nsPageNum" width="50" height="22" stepSize="1" minimum="1" maximum=" {Math.ceil(this.totalClum/this.pageSize)}" enabled="{lbtnJump.enabled}" cornerRadius="0" fontSize="12"/> ?
<mx:Label text="页"/> ?
<mx:LinkButton id="lbtnJump" label="GO" ?click="loadData(nsPageNum.value)" enabled=" {Math.ceil(this.totalClum/this.pageSize)>1?true:false}" fontSize="12"/> ? ? ? ? ? ? ? ?

</mx:HBox> ?

举例:

?
<pagination:PageInfo id="pagePar" totalClum="{pageNums}" pageSize="5" orgData="{pages}" dataGrid="{grid}"/>
//totalClum表示总记录数,pageSize表示每页显示的记录数,orgData表示要显示的所有数据,dataGrid表示DataGrid

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读