代码贴上来:
<view:PageController id="pageCtt" width="100%" height="25" targetUI="{this}"/
<view:DtableGrid id="dtableGrid" width="100%" height="100%" horizontalScrollPolicy="auto" columnHeaderList="{columnHeaderList}" dataProvider="{dataProvider}" itemClick="dataClick(event)" doubleClickEnabled="true" doubleClick="dataDoubleClick(event)" > </view:DtableGrid>
PageController 是自定义的一个分页控件:
<?xml version="1.0" encoding="utf-8"?> <s:HGroup xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" verticalAlign="middle" paddingLeft="6" paddingRight="20" > <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <fx:Script> <![CDATA[ import com.adobe.utils.IntUtil; import com.adobe.utils.StringUtil; import com.thams.common.constant.Glob; import com.thams.grid.skin.EditButtonICO; import com.thams.grid.skin.NoeditButtonICO; import com.thams.grid.vo.DataLoaderClass; import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.controls.DataGrid; import mx.events.FlexEvent; import mx.events.ItemClickEvent; import mx.events.ListEvent; import mx.events.MenuEvent; import spark.components.ToggleButton; import spark.events.IndexChangeEvent; //保存散 / 卷内 的 pid值 private var oldPid:int = -1; [Bindable] /** * 选择条目数 . 下拉 */ protected var showCounts:ArrayCollection = new ArrayCollection( [{label:"50", data:50}, {label:"100", data:100}, {label:"500", data:500}, {label:"1000", data:1000}, {label:"全部", data:-1} ]); [Bindable] public var targetUI:TableList; [Bindable] private var tabNames:Array ; public function set getLevelStr(level:int):void{ switch(level){ case Glob.PRJ_LEVEL: tabNames = new Array(); tabNames.push("项目"); tabSel.selectedIndex=0; break; case Glob.VOL_LEVEL: tabNames = new Array(); if(targetUI.dataLoaderClass.parentLevel==Glob.PRJ_LEVEL){ //如果最高级别为项目 tabNames.push("案卷"); tabNames.push("散案卷"); } if(targetUI.dataLoaderClass.parentLevel==Glob.VOL_LEVEL){//如果最高级别为案卷 则没有散案卷 tabNames.push("案卷"); } tabSel.selectedIndex=0; break; case Glob.FILE_LEVEL: tabNames = new Array(); if(targetUI.dataLoaderClass.parentLevel==Glob.PRJ_LEVEL||targetUI.dataLoaderClass.parentLevel==Glob.VOL_LEVEL){// 如果最高级别为项目或者案卷 tabNames.push("文件"); tabNames.push("散文件"); } if(targetUI.dataLoaderClass.parentLevel==Glob.FILE_LEVEL){// 最高级别为文件 则没有散文件 tabNames.push("文件"); } tabSel.selectedIndex=0; break; } } protected function tabItemClick(event:ItemClickEvent):void{ //var toggleButt:ToggleButtonBar = ToggleButtonBar(event.currentTarget); if(targetUI.dataLoaderClass.pid!=-1){ oldPid = targetUI.dataLoaderClass.pid; } if(event.index==0){ //点击第一个tab不为散 juannei(); }else{ // 显示散数据 san(); } } //显示散 protected function san():void{ targetUI.dataLoaderClass.pid = -1; targetUI.loadDataGrid(); } //显示卷内 protected function juannei():void{ targetUI.dataLoaderClass.pid = oldPid; targetUI.loadDataGrid(); } /** * 分页监听事件 */ public function set pageChanged(page:Object):void{ if(page.page>1){ goback.enabled = true; goback.addEventListener(MouseEvent.CLICK,go_back); }else{ goback.enabled = false; goback.removeEventListener(MouseEvent.CLICK,go_back); } if(page.page<page.pageum){ gonext.enabled = true; gonext.addEventListener(MouseEvent.CLICK,go_next); }else{ gonext.enabled = false; gonext.removeEventListener(MouseEvent.CLICK,go_next); } var _totalnum:uint = uint(page.totalnum); var _pnum:uint = uint(page.page); var _pageum:uint = uint(page.pageum); if(page.page==-1){ totalNum.text = "1/1 页 共"+_totalnum+"条数据"; }else{ totalNum.text = _pnum+"/"+_pageum+" 页 共"+_totalnum+"条数据"; } } /** * 上一页 */ protected function go_back(event:MouseEvent):void{ targetUI.dataLoaderClass.pageNumber = uint(targetUI.page.page)-1; targetUI.loadDataGrid(); } /** * 后一页 */ protected function go_next(event:MouseEvent):void{ targetUI.dataLoaderClass.pageNumber = uint(targetUI.page.page)+1; targetUI.loadDataGrid(); } /** * 选择显示条目数 */ protected function pageSizeChanged(event:IndexChangeEvent):void { if(event.newIndex==4){ targetUI.dataLoaderClass.pageNumber = -1; }else{ targetUI.dataLoaderClass.pageNumber = 1; } targetUI.dataLoaderClass.pageSize = uint(showCounts[event.newIndex].data); targetUI.loadDataGrid(); } /** * 根据列出数据的每页条目数 定位下拉 */ public function set changePageSize(sel:Object):void { switch(sel){ case 50: comb.selectedIndex=0; break; case 100: comb.selectedIndex=1; break; case 500: comb.selectedIndex=2; break; case 1000: comb.selectedIndex=3; break; case -1: comb.selectedIndex=4; break; } } protected function enableGridEdit_click(event:MouseEvent):void { if(targetUI.dtableGrid.editable){ //关闭行编辑后.可案卷跟随刷新 targetUI.dtableGrid.editable = false; enableGridEdit.toolTip = "开启行编辑"; enableGridEdit.setStyle("skinClass",Class(EditButtonICO)); }else{ //开启行编辑后. 取消跟随刷新 targetUI.dtableGrid.editable = true; enableGridEdit.toolTip = "关闭行编辑"; enableGridEdit.setStyle("skinClass",Class(NoeditButtonICO)); } } ]]> </fx:Script> <fx:Binding source="{targetUI.dataLoaderClass.level}" destination="getLevelStr"/> <fx:Binding source="{targetUI.dataLoaderClass.pageSize}" destination="changePageSize"/> <fx:Binding source="{targetUI.page}" destination="pageChanged" /> <mx:ToggleButtonBar id="tabSel" color="0x323232" horizontalGap="5" itemClick="tabItemClick(event)" dataProvider="{tabNames}"> </mx:ToggleButtonBar> <s:Button id="goback" toolTip="上一页" width="16" height="16" enabled="false" skinClass="com.thams.grid.skin.PageBackButtonICO"/> <s:Button id="gonext" toolTip="下一页" width="16" height="16" enabled="false" skinClass="com.thams.grid.skin.PageNextButtonICO"/> <s:DropDownList id="comb" dataProvider="{showCounts}" change="pageSizeChanged(event)" selectedIndex="0" width="70"> </s:DropDownList> <s:Label id="totalNum"> </s:Label> <s:Button id="enableGridEdit" toolTip="开启行编辑" width="16" height="16" click="enableGridEdit_click(event)" skinClass="com.thams.grid.skin.EditButtonICO"/> </s:HGroup>
项目用上了cairngorm 框架. 底层不好解释. 各位将就看吧.
贴上model类:
package com.thams.grid.model { import com.adobe.cairngorm.model.IModelLocator; import com.thams.grid.vo.DataLoaderClass; [Bindable] public class FileDataGridModellocator implements IModelLocator { private static var instance:FileDataGridModellocator; public var dataProvider:Object; public var dataLoaderClass:DataLoaderClass ; //用于分页使用 public var page:Object; //个性设置.显示字段定义 public var columnHeaderList:Object; //定义视图状态,方便后台与前台交换的给用户的视觉改变 public static var CURRENTSTATE_NO_CHANGE:uint = 0; public static var CURRENTSTATE_IS_CHANGE:uint = 1; //默认视图状态 public var viewState:uint = CURRENTSTATE_NO_CHANGE; public function FileDataGridModellocator() { if(instance==null){ instance = this; } } public static function getInstance():FileDataGridModellocator{ if(instance==null){ instance = new FileDataGridModellocator(); } return instance; } } }
DataLoaderClass 是条件封装查询类:
package com.thams.grid.vo { import com.adobe.cairngorm.vo.IValueObject; /** * 查询参数封装类 */ [Bindable] public class DataLoaderClass implements IValueObject { /** * * 加载数据 * * level 默认传入 -1 代表数据库自动判断最高级别 <br> * 数据库格式如下: <br> * switch (level) { <br> * case 0: * return EOperLevelType.D_PRJ_LEVEL; <br> * case 1: <br> * return EOperLevelType.D_VOL_LEVEL; <br> * case 2: <br> * return EOperLevelType.D_FILE_LEVEL; <br> * case 3: <br> * return EOperLevelType.E_EFILE_LEVEL; <br> * case 4: <br> * return EOperLevelType.W_QT_LEVEL; <br> * default: <br> * return EOperLevelType.D_FILE_LEVEL; <br> * } <br> * */ public var level:int; /** * 当前最高级别 */ public var parentLevel:int; public var libcode:int; public var searchFromFields:String = "*"; public var qxwhere:String = ""; public var orderBy:String ; public var pageNumber:int = 1;//默认为第一页 public var pageSize:int = 50;//默认条目数为50 public var qzh:String; public var pid:int = -1; //默认为不属于任何项目或者案卷的条目 public var flhwhere:String = ""; // 单独为项目级做的检索机制. 因为项目级不继承分类条件 /** * attr 归档前后 0为归档后 1为归档前 */ public var attr:int = 0; public function DataLoaderClass() { } } }
个人备查