浏览 2642 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (10)
|
|
---|---|
作者 | 正文 |
发表时间:2010-02-28
最后修改:2010-02-28
DataGrid的实现和翻页 1.mxml代码: <mx:VBox width="100%" height="100%" backgroundColor="#ffffff"> <mx:HBox width="100%" height="100%" id="hbox2"> <mx:DataGrid width="100%" height="100%" id="dg" rowCount="20" fontSize="12"> <mx:columns> <mx:DataGridColumn headerText="ID" dataField="ID" visible="false"/> <mx:DataGridColumn headerText="模块名称" dataField="ModuleName" width="150"/> <mx:DataGridColumn headerText="父亲模块" dataField="ModuleID" width="150"/> <mx:DataGridColumn headerText="链接模块" dataField="Hreflink" width="150"/> <mx:DataGridColumn headerText="排 序" dataField="Sort" width="80"/> <mx:DataGridColumn headerText="描 述" dataField="Description"/> </mx:columns> </mx:DataGrid> </mx:HBox> <mx:HBox width="100%" height="28" verticalAlign="middle" horizontalAlign="right"> <ns1:SplitPage height="32" id="splitPage" clickSplitEvent="clicksplitPage(event);"> </ns1:SplitPage> </mx:HBox> </mx:VBox>
2.splitPage.mxml 组件 <?xml version="1.0" encoding="utf-8"?> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="32" backgroundColor="#ffffff" fontSize="12"> <mx:Metadata> [Event(name="clickSplitEvent","MyEvent.SplitEvent")] </mx:Metadata> <mx:Script> <![CDATA[ import MyEvent.SplitEvent; import mx.controls.Alert; private var page:Number; private var clickEvent:SplitEvent; //第一页 private function first(event:Event):void{ if(Number(currentPage.text) ==1) return; page = 1; clickEvent = new SplitEvent("clickSplitEvent",page); dispatchEvent(clickEvent); } //上一页 private function previous(event:Event):void{ if(Number(currentPage.text) ==1) return; page = new Number(currentPage.text)-1; clickEvent = new SplitEvent("clickSplitEvent",page); dispatchEvent(clickEvent); } //下一页 private function nexts(event:Event):void{ if(Number(currentPage.text) ==Number(pageSize.text)) return; page = new Number(currentPage.text)+1; clickEvent = new SplitEvent("clickSplitEvent",page); dispatchEvent(clickEvent); } //最后一页 private function lasts(event:Event):void{ if(Number(currentPage.text) ==Number(pageSize.text)) return; page = new Number(pageSize.text); clickEvent = new SplitEvent("clickSplitEvent",page); dispatchEvent(clickEvent); } //下拉框 private function selectPage(event:Event):void{ page = new Number(pageSelects.selectedItem.data); clickEvent = new SplitEvent("clickSplitEvent",page); dispatchEvent(clickEvent); } ]]> </mx:Script> <mx:HBox width="100%" height="100%" horizontalAlign="right" verticalAlign="middle" horizontalGap="1"> <mx:Label text="共"/> <mx:Label id="total" text=""/> <mx:Label text="条"/> <mx:Spacer width="5"/> <mx:Label id="currentPage" text="" /><mx:Label text="/" width="13"/> <mx:Label id="pageSize" text=""/> <mx:Label text="页"/> <mx:Spacer width="5"/> <mx:Image id="top" click="first(event);" x="628" y="7" height="20" source="images/top.gif" width="26"/> <mx:Image id="privous" click="previous(event);" x="628" y="7" height="20" source="images/privous.gif" width="26"/> <mx:Spacer width="5"/> <mx:ComboBox width="94" id="pageSelects" close="selectPage(event);"></mx:ComboBox> <mx:Spacer width="5"/> <mx:Image id="next" click="nexts(event);" x="628" y="7" height="20" source="images/next.gif" width="26"/> <mx:Image id="last" click="lasts(event);" x="628" y="7" height="20" source="images/bottom.gif" width="26"/> <mx:Spacer width="10"/> </mx:HBox> </mx:Canvas>
2.as实现代码:
//获取列表信息 private function getlist(page:Number,lineSize:Number):void { menuRo= new RemoteObject("menuService"); operation = menuRo.getOperation("getMenuList"); menuToken = operation.send(page,lineSize); menuToken.addResponder(new AsyncResponder(success,null)); } //成功返回处理 public function success(result:Object,token:Object=null):void { var eve:ResultEvent = result as ResultEvent; if(eve.result != null) { var returnArray:Array = eve.result as Array; var returnString:String = returnArray[0]; var xmlList:XMLList = new XMLList(returnString); xmlListCollection = new XMLListCollection(xmlList); dg.dataProvider = xmlListCollection; splitPage.currentPage.text = new String(returnArray[1]); if(returnArray[1] ==1){ splitPage.total.text=new String(returnArray[2]); splitPage.pageSize.text=new String(returnArray[3]); splitPage.pageSelects.dataProvider=returnArray[4]; } splitPage.pageSelects.selectedIndex=returnArray[1]-1; } } //翻页处理 private function clicksplitPage(event:Event):void{ var nextPage:SplitEvent = event as SplitEvent; var page:Number = nextPage.current_page; getlist(page,lineSize); }
3.java代码: public Object[] getMenuList(int current_page, int lineSize) { Object[] obj = new Object[5]; int totalRecord =0; int pages = 0; List pageSelect = new ArrayList(); if(current_page == 0 || current_page ==1){ current_page = 1; //当前页 totalRecord = this.service.getAllCount("TFunction")-1; pages =((totalRecord+lineSize-1)/lineSize); pageSelect = PagComboBox.listToxml(pages); } List list = new ArrayList(); list = this.service.findAllObjects("TFunction", current_page, lineSize,""); String listXml =""; if(list.size()>0){ listXml = listToxml(list); } obj[0] = listXml; obj[1] = current_page; obj[2] = totalRecord; obj[3] = pages; obj[4] = pageSelect; return obj; } /** * 把list对象转化成XML * @param list * @return * 2010-2-9 * Administrator */ private String listToxml(List list) { String listXml = ""; List listF =this.service.findAllObjects("TFunction", 0, 0,""); for (int i = 0; i < list.size(); i++) { TFunction tFunction = (TFunction) list.get(i); String moduleid =""; if(tFunction.getModuleId() ==0){ moduleid="权限管理系统"; continue; }else{ for(int j=0;listF !=null && j<listF.size();j++){ TFunction tF = (TFunction) listF.get(j); if(tFunction.getModuleId() == tF.getId()){ moduleid = tF.getModuleName(); break; } } } listXml += "<functions>\n"; listXml += "<ID>"+tFunction.getId()+"</ID>\n"; listXml += "<ModuleName>"+tFunction.getModuleName()+"</ModuleName>\n"; listXml += "<ModuleID>"+moduleid+"</ModuleID>\n"; listXml += "<Hreflink>"+tFunction.getHreflink()+"</Hreflink>\n"; listXml += "<Sort>"+tFunction.getSort()+"</Sort>\n"; listXml += "<Description>"+tFunction.getDescription()+"</Description>\n"; listXml +="</functions>"; } return listXml; }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |