zoukankan      html  css  js  c++  java
  • 65、salesforce的数据分页

    <apex:page controller="PagingController">
        <apex:form >
            <apex:pageBlock title="Invoices">
    
                <apex:pageBlockButtons location="top">
                    <apex:commandButton action="{!process}" value="Selected" />
                    <apex:commandButton action="{!cancel}" value="Cancel" />
                </apex:pageBlockButtons>
                <apex:pageMessages />
    
                <apex:pageBlockSection title="Goods -  Page {!pageNumber}" columns="1">
                    <apex:pageBlockTable value="{!categories}" var="c">
                        <apex:column width="25px">
                            <apex:inputCheckbox value="{!c.checked}" />
                        </apex:column>
                        <apex:column value="{!c.invoice.Name}" headerValue="Name" />
                        <apex:column value="{!c.invoice.Invoice_Total1__c}" headerValue="Total" />
                        <apex:column value="{!c.invoice.Status__c}" headerValue="Status" />
                    </apex:pageBlockTable>
                </apex:pageBlockSection>
            </apex:pageBlock>
    
            <apex:panelGrid columns="4">
                <apex:commandLink action="{!first}">First</apex:commandlink>
                    <apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandlink>
                        <apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandlink>
                            <apex:commandLink action="{!last}">Last</apex:commandlink>
            </apex:panelGrid>
    
        </apex:form>
    </apex:page>

    Controller的代码

    public with sharing class PagingController {
        List<categoryWrapper> categories {get;set;}
        
        //instantiate the StandardSetController from a query locator
        public ApexPages.StandardSetController con{
            get{
                if(con==null){
                    con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name,Invoice_Total1__c,Status__c,Id from Invoice__c]));
                    con.setPageSize(4);
                }
                return con;
            }
            set;
        }
        
        //returns a list of wrapper objects for the sObjects in the current page set
        public List<categoryWrapper> getCategories(){
            categories = new List<categoryWrapper>();
            for(Invoice__c invoice : (List<Invoice__c>)con.getRecords()){
                categories.add(new CategoryWrapper(invoice));
            }
            return categories;
        }
        
        
        //displays the selected items
        public PageReference process(){
            for(CategoryWrapper cw:categories){
                if(cw.checked){
                     ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,cw.invoice.Name));
                }
            }
            return null;
        }
        
        // indicates whether there are more records after the current page set.
         public Boolean hasNext {
             get {
                 return con.getHasNext();
             }
             set;
         }
     
         // indicates whether there are more records before the current page set.
         public Boolean hasPrevious {
             get {
                 return con.getHasPrevious();
             }
             set;
         }
     
         // returns the page number of the current page set
         public Integer pageNumber {
             get {
                 return con.getPageNumber();
             }
             set;
         }
     
         // returns the first page of records
          public void first() {
              con.first();
          }
     
          // returns the last page of records
          public void last() {
              con.last();
          }
     
          // returns the previous page of records
          public void previous() {
              con.previous();
          }
     
          // returns the next page of records
          public void next() {
              con.next();
          }
     
          // returns the PageReference of the original page, if known, or the home page.
          public void cancel() {
              con.cancel();
          }
    }

    包装类的代码

    public class CategoryWrapper {
        public Boolean checked{get;set;}
        
        public Invoice__c invoice{get;set;}
        
        public CategoryWrapper(){
            invoice = new Invoice__c();
            checked = false;
        }
        
        public CategoryWrapper(Invoice__c invoice){
            this.invoice = invoice;
            checked = false;
        }
    }

    最后实现的效果如下图所示

  • 相关阅读:
    new对象数组时的内存布局
    写程序取自己进程的AEP
    类虚函数表原理实现分析(当我们将虚表地址[n]中的函数替换,那么虚函数的实现就由我们来控制了)
    测试 __try, __finally, __except(被__finally捕获的异常, 还会被上一级的__except捕获。反之不行)
    围观M$的new
    将258.369 double值转为内存表示(科学计数法)
    Broadcast Reveiver作用
    DEBUG模式下, 内存中的变量地址分析
    不包含SDK头文件, 补全API定义
    俄罗斯方块SDK版
  • 原文地址:https://www.cnblogs.com/weizhen/p/6416155.html
Copyright © 2011-2022 走看看