自己做的flex分页控件

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml " width="450" creationComplete="initPage()">
<mx:Script>
<![CDATA[
import com.adofits.framework.portal.base.communicate.MessageEvent;
import mx.controls.Alert;
public var totalPages:uint;
public var currentPage:uint;
public var pageRows:uint=10;
public var totalRows:uint;
public var pageStartRow:uint = 0;
public var pageEndRow:uint;
public var lastPageSize:uint;
public var step:uint;
public function initPage():void{
//totalPages = Math.ceil(totalRows / pageRows);
totalPages = totalRows % pageRows == 0 ?
totalRows / pageRows : totalRows / pageRows + 1;
lastPageSize=totalRows % pageRows;
preP.enabled = false;
firstP.enabled = false;
if(totalPages==0||totalPages == 1){
nextP.enabled = false;
lastP.enabled = false;
}
currentPage = 0;
pageStartRow = 0;
jilu_id.text="共"+String(totalRows)+"条记录";
page_id.text="共"+String(totalPages)+"页";
}
public function setButton():void{
if(currentPage==0){
firstP.enabled = false;
preP.enabled = false;
}
if(currentPage==totalPages-1){
lastP.enabled = false;
nextP.enabled = false;
}
if(currentPage<totalPages-1){
lastP.enabled = true;
nextP.enabled = true;
}
if(currentPage>0){
firstP.enabled = true;
preP.enabled = true;
}
pageNum.text = String(currentPage+1)+"/"+String(totalPages);
}
private function tofirst():void{
currentPage = 0;
pageStartRow = 0;
step=pageRows;
setButton();
dispatchEvent(new MessageEvent("pageRefreshed"));
}
private function toEnd():void{
currentPage = totalPages-1;
pageStartRow = currentPage*pageRows;
setButton();
dispatchEvent(new MessageEvent("pageRefreshed"));
}
private function next():void{
if(currentPage==totalPages-1){
Alert.show("当前已是最后一页!","提示");
return;
} else if(currentPage==totalPages-2){
step=lastPageSize;
} else{
step=pageRows;
}
currentPage++;
pageStartRow =currentPage*pageRows;
setButton();
this.dispatchEvent(new MessageEvent("pageRefreshed"));
}
private function pref():void{
if(currentPage==0){
Alert.show("当前已是第一页!","提示");
return;
}
step=pageRows;
currentPage--;
pageStartRow =currentPage*pageRows;
setButton();
this.dispatchEvent(new MessageEvent("pageRefreshed"));
}
private function findExacPage(thePage:uint):void{
if(currentPage==thePage){
return;
}
if(thePage<0||thePage>totalPages-1){
Alert.show("页面范围错误!","错误");
return;
}
if(thePage<=totalPages-2&&thePage>=0){
step= pageRows;
} else if(thePage==totalPages-1){
step=lastPageSize;
}
currentPage=thePage;
pageStartRow=currentPage*pageRows;
setButton();
this.dispatchEvent(new MessageEvent("pageRefreshed"));
}
]]>
</mx:Script>

<mx:Metadata>
[Event(name="pageRefreshed", type="com.adofits.framework.portal.base.communicate.MessageEvent")]
</mx:Metadata>
<mx:HBox width="100%" horizontalAlign="center" verticalAlign="middle">
<mx:Spacer />
<mx:HBox width="20%" horizontalAlign="left" verticalAlign="middle">
<mx:Label fontSize="11" text="转至" width="30%"/>
<mx:TextInput fontSize="11" id="gotoDestination" text="1" width="42"/>
<mx:Button fontSize="11" id="gotoExacPage" width="20%" click="findExacPage(uint(gotoDestination.text)-1)" styleName="MyButton" label="跳转"/>
</mx:HBox>
<mx:HBox width="40%" horizontalAlign="left" verticalAlign="middle">
<mx:Button id="firstP" fontSize="11" click="tofirst()" width="20%" label="|&lt;" styleName="MyButton"/>
<mx:Button id="preP" fontSize="11" click="pref()" width="20%" label="&lt;-" styleName="MyButton"/>
<mx:TextInput id="pageNum" fontSize="11" text="" width="58" editable="false"/>
<mx:Button id="nextP" fontSize="11" click="next()" width="20%" label="-&gt;" styleName="MyButton"/>
<mx:Button id="lastP" fontSize="11" click="toEnd()" width="20%" label="&gt;|" styleName="MyButton"/>
</mx:HBox>
<mx:HBox width="40%" horizontalAlign="left" verticalAlign="top">
<mx:Label fontSize="11" id="jilu_id" text="" width="30%"/>
<mx:Label fontSize="11" id="page_id" text="" width="30%"/>
</mx:HBox>
</mx:HBox>
</mx:VBox>

页面中调用的使用方法:
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml " width="100%" height="100%"
xmlns:common="com.adofits.framework.portal.base.common.*"
>
<mx:Script>
<![CDATA[
private function refreshed(e:com.adofits.framework.portal.base.communicate.MessageEvent):void{
var args:Array = new Array(pagechange.pageStartRow,pagechange.step, "");
trace(args);
opStatus.text = "正在载入...";
if(tabBarid.selectedIndex==0){
manager.invokeServiceWithToken("NoticeService","queryAllNotice",args,handleRefreshResult,handleRefreshFault);
}else if(tabBarid.selectedIndex==1){
manager.invokeServiceWithToken("NoticeService","queryCollegeNotice",args,handleRefreshResult,handleRefreshFault);
}
}

private function handleRefreshResult(event:ResultEvent):void{
noticeInfoArray.removeAll();
perPageRows=pageRows.value;
pagechange.setButton();
handleResult(event);
}
private function handleRefreshFault(event:FaultEvent):void{
handleFault(event);
}
private function refresh():void{
noticeInfoArray.removeAll();
perPageRows=pageRows.value;
pagechange.initPage();
init();
}
]]>
</mx:Script>
<mx:HBox horizontalAlign="center" verticalAlign="middle" width="80%">
<common:PageChange id="pagechange" pageRefreshed="refreshed(event)" pageRows="{perPageRows}" totalRows="{rowCounts}" horizontalAlign="center" width="40%"/>
</mx:HBox>
简化了页面的代码量,屡试不爽。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值