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;
        }
    }

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

  • 相关阅读:
    GPU 加速NLP任务(Theano+CUDA)
    SOJ 1717 Computer (单机任务调度)
    CNN for NLP (CS224D)
    数据分析:中国高校更名历史 Python
    TextRank 自动文摘
    深度学习笔记(十一)网络 Inception, Xception, MobileNet, ShuffeNet, ResNeXt, SqueezeNet, EfficientNet, MixConv
    深度学习笔记(七)SSD 论文阅读笔记简化
    在Windows下编译扩展OpenCV 3.1.0 + opencv_contrib 及一些问题
    win10 + gtx1060 + cuda8.0 + caffe + vs2013 + Tensorflow + PyTorch
    深度学习笔记(二十五)DenseBox & FCOS & PolarMask
  • 原文地址:https://www.cnblogs.com/weizhen/p/6416155.html
Copyright © 2011-2022 走看看