flex分页



 
     public var pageRecordes:uint = 8;
   public var totalPages:uint = 0;
   public var totalRows:uint = 0;
   public var currentPage:uint = 1;
   public var pageStartRow:uint = 1;
   public var pageEndRow:uint = 0;
   
   public function initApp():void{
    txt.text = "Page " + currentPage;
    totalRows = initDG.length;
    if(initDG.length > pageRecordes){
     dg.dataProvider = initDG.slice(0,pageRecordes);
     pPage.enabled = false;
    }
    
    if((totalRows % pageRecordes) == 0){
     totalPages = Math.floor(totalRows / pageRecordes);
    }else{
     totalPages = Math.floor(totalRows / pageRecordes + 1);
    }
    
    if(totalRows <= pageRecordes){
     this.pageStartRow = 1;
     this.pageEndRow = totalRows;
    } else {
     this.pageStartRow = 1;
     this.pageEndRow = pageRecordes;
    }
    
    if(totalPages == 1){
     pPage.enabled = false;
     nPage.enabled = false;
    }   
   }
   
   public function showPreviousPage():void{
    currentPage = currentPage - 1;
    txt.text = "Page " + currentPage;
    if(currentPage == 1){
     pPage.enabled = false;
     nPage.enabled = true;
    }else{
     pPage.enabled = true;
     nPage.enabled = true;
    }
    if (currentPage == totalPages) {
     pageStartRow = (currentPage - 1) * pageRecordes + 1;
     pageEndRow = totalRows;
    } else {
     pageStartRow = (currentPage - 1) * pageRecordes + 1;
     pageEndRow = currentPage * pageRecordes;
    }
    dg.dataProvider = initDG.slice(pageStartRow - 1,pageEndRow);
   }
   
   public function showNextPage():void{
    currentPage = currentPage + 1;
    txt.text = "Page " + currentPage;
    if(currentPage == totalPages){
     nPage.enabled = false;
     pPage.enabled = true;
    }else{
     nPage.enabled = true;
     pPage.enabled = true;
    }
    if (currentPage == totalPages) {
     pageStartRow = (currentPage - 1) * pageRecordes + 1;
     pageEndRow = totalRows;
    } else {
     pageStartRow = (currentPage - 1) * pageRecordes + 1;
     pageEndRow = currentPage * pageRecordes;
    }
    dg.dataProvider = initDG.slice((currentPage - 1) * pageRecordes,pageEndRow);
   }
   
   public function showFirstPage():void{
    dg.dataProvider = initDG.slice(0,pageRecordes);
    pPage.enabled = false;
    nPage.enabled = true;
    txt.text = "Page " + 1;
    currentPage = 1;
   }
   
   public function showLastPage():void{
    dg.dataProvider = initDG.slice((totalPages - 1) * pageRecordes,totalRows);
    pPage.enabled = true;
    nPage.enabled = false;
    txt.text = "Page " + totalPages;
    currentPage = totalPages;
   }
  ]]>
 

 
  
   
    
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    

   

  

  
  
   
   
    
     
      firstPage
     

    

   

   
    
     
      prePage
     

    

   

   
   
    
     
      nextPage
     

    

   

   
    
     
      lastPage
     

    

   

  

  
 

你可能感兴趣的:(flex,object,datagrid,function,application,encoding)