Real Flex pages. One page can be reused multiple times and multiple flex pages can be reused.
<? 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 =" 0 xffffff "> <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] // number of records private var items: ArrayCollection; [Bindable] // The paging parameter private var params: Array = new Array (); [Bindable] // number of entries displayed per page private var pageSizeBoxListData: ArrayCollection = ne W ArrayCollection ([{pageSize: 10 },{ pageSize: 20 },{ pageSize: 30 },{ pageSize: 50 },{ pageSize: 100}]); [Bindable] // number of records displayed on each page public var pageSize: int = 10; [Bindable] // the current page public var curPage: int = 1; [Bindable] // number of records to the next page public var offSet: int = 1; [Bindable] // total number of pages public var totalPage: int = 0; [Bindable] // total number of records public var totalCount: int = 263; public var destination: String; public var methodName: String; [Bindable] // component width pub Lic var widthTo: int; [Bindable] // public var url: String; [Bindable] // datagridpublic var datagrid: DataGrid; /***/protected function progressBarClickHandler (event: MouseEvent): void {var bc: HBox = HBox(event.tar get); widthTo = event.localx;progressbar#t.tar get = 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 ();} /*** previous page */protected function pagePrevClickHandler (event: MouseEvent): void {var tempNum: int = getMinimum (); curPage = curPage-1; getBtnEnabled (); pagingRemoteObject ();}/*** jump to the specified page */protected function pageStepperClickHandler (event: MouseEvent): void {curPage = pageSteppe R. value;}/*** next page */protected function pageNextClickHandler (event: MouseEvent): void {if (curPage <totalPage) {curPage = curPage + 1;} getBtnEnabled (); pagingRemoteObject ();}/*** last page */protected function pageLastClickHandler (event: MouseEvent): void {curPage = totalPage; getBtnEnabled (); pagingRemoteObject ();} /*** refresh the current page */protected function pageRefreshClickHandler (event: MouseEvent): void {totalPage = getTo TalPageNum (); pagingRemoteObject ();}/*** initialization function */protected function initHandler (event: FlexEvent): void {totalPage = getTotalPageNum ();} /*** set how many records are displayed per page */protected function pageSizeComboboxChangeHandler (event: MouseEvent): void {var obj: Object = pageSizeCombobox. selectedItem; pageSize = obj. pageSize; trace (url, "", pageSize);}/*** get the total number of pages */private function getBtnEnabled (): void {if (totalPage <1) {pageFirstB Tn. 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; pageN ExtBtn. 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 ;}/ *** successful processing of service requests */private function serviceSuccessResult (event: ResultEvent): void {totalCount = event. result. totalCounts; items = event. result. entityLis T as ArrayCollection; trace (url, "", items);}/*** processing of service request failure */private function httpServiceFault (event: FaultEvent): void {Alert. show (event. fault. message, "service request failed");}/*** send service request */private function pagingRemoteObject (): void {var remote: RemoteObject = new RemoteObject (destination ); offSet = (curPage-1) * pageSize; remote. getOperation (methodName ). send (pageSize, offSet); remote. addEventListener (ResultEvent. RESUL T, serviceSuccessResult); remote. addEventListener (FaultEvent. FAULT, httpServiceFault);}/*****/private function loadingDatagrid (): void {}]> </fx: Script> <fx: Declarations> <! -- Place non-visual elements (such as services and value objects) Here --> </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 =" {curPage} "/> <s: Label text =" of "/> <s: label id = "totalPageLab" text = "{totalPage}"/> </mx: HBox> <mx: HBox verticalAlign = "middle"> <s: comboBox dataProvider = "{pageSizeBoxListData}" selectedIndex = "1" width = "60" labelField = "pageSize" id = "pageSizeComboBox" change = "pageSizeComboboxChangeHandler (event) "/> <s: Label text =" Total {totalCount} records "/> </mx: HBox> <mx: linkButton styleName = "pageRefreshBtn" id = "pageRefreshBtn" click = "pageRefreshClickHandler (event)"/> </mx: HBox> <s: borderContainer x = "0" y = "0" width = "40%" height = "20" borderColor = "0x336699" textAlign = "center" visible = "false"> <s: group id = "hgimg" x = "0" y = "0" width = "100%" height = "100%" clipAndEnableScrolling = "true"> <mx: HBox width = "60%" height = "18" styleName = "progressBarPageBlue" id = "progressBarPageBlue"> </mx: HBox> <mx: HBox width = "96%" height = "100%" paddingLeft = "3" x = "2" horizontalAlign = "center" verticalAlign = "middle"> <s: label text = "Displaying"/> <s: Label text = "{pageSize * curPage-1-pageSize}" id = "pageStartLab"/> <s: label text = "-"/> <s: Label text = "{pageSize * curPage-1}" id = "pageSizeLab"/> <s: label text = "of"/> <s: Label text = "{totalCount}" id = "allRecordsLab"/> </mx: HBox> <mx: HBox width = "100%" height = "100%" click = "progressBarClickHandler (event)" verticalAlign = "middle"> </mx: HBox> </s: group> </s: BorderContainer> </mx: HBox>
After the check box is added to the datagrid In Flex, the number of rows on the last page is not enough, but the check box is still there. How can I remove it?
Well, you did. I tested it this time.
Because there are not all the code, I copied the code above and deleted all the scripts.
The test uses an ArrayCollention with four elements. Four checkboxes are displayed.
Then a button will replace ArrayCollention with three elements. There are only three checkboxes left.
There is no special code. The check box is not empty.
How can I separate the paging JavaScript code and use a single js file for reuse?
It can be reused. However, your each loop cannot be reused (You know ). Here is my reuse:
Var sus = "request IP Address: Port"; // server: Request Path // params: Request Parameter // fun1: callback method after successful request // fun2: the callback method function getAction (server, params, fun1, fun2) {$. ajax ({type: "post", url: sus + server, dataType: 'jsonp', jsonp: "jsonpCallback", data: params, success: function (result) {if ($. isFunction (fun1) {fun1 (result) ;}}, error: function (XMLHttpRequest, textStatus, errorThrown) {if ($. isFunction (fun2) {fun2 (XMLHttpRequest) ;}}) ;}// call method: getAction ("login/login. ashx ", {name: 'zs', pwd: '000000'}, function (result) {// successful processing of normal requests}, function (error) {// processing when an error is returned });