Skip to main content
Tweeted twitter.com/StackSalesforce/status/1175107508853190660
edited tags
Link
pchittum
  • 19.8k
  • 5
  • 57
  • 99
added 3 characters in body; edited title
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

pagenation Pagination with wrapperclassWrapper Class and standardsetcontrollerStandardSetController

iI have a requirement for that i 've donewhich I've written some code for pagenatedpaginated wrapped records with checkboxes using standardset controllerstandardsetcontroller. now i wanaNow I want to display all pagenatedpaginated records with allpage buttons like (1..2..3...4..5..etc) with out next,previous previous,first first,last last buttons. PlZCan any body let me know isif it is posible thorugh standardset controllerstandardsetcontroller methods or how? my bellowMy below code is satisfyingonly satisfies my requirement up to some extent only.

pagenation with wrapperclass and standardsetcontroller

i have a requirement for that i 've done some code for pagenated wrapped records with checkboxes using standardset controller. now i wana display all pagenated records with all buttons like (1..2..3...4..5..etc) with out next,previous,first,last buttons. PlZ any body let me know is it posible thorugh standardset controller methods or how? my bellow code is satisfying my requirement up to some extent only.

Pagination with Wrapper Class and StandardSetController

I have a requirement for which I've written some code for paginated wrapped records with checkboxes using standardsetcontroller. Now I want to display all paginated records with page buttons like (1..2..3...4..5..etc) with out next, previous, first, last buttons. Can any body let me know if it is posible thorugh standardsetcontroller methods or how? My below code only satisfies my requirement to some extent.

added 632 characters in body
Source Link
Ratan Paul
  • 22.8k
  • 14
  • 55
  • 99

i have a requirement for that i 've done some code for pagenated wrapped records with checkboxes using standardset controller. now i wana display all pagenated records with all buttons like (1..2..3...4..5..etc) with out next,previous,first,last buttons. PlZ any body let me know is it posible thorugh standardset controller methods or how? my bellow code is satisfying my requirement up to some extent only. controller public class standardsetctrl {

Public List categories {get;set;} Public Account acc {get; set;}
public String accID;
public ApexPages.StandardSetController con { get { String accID= ApexPages.currentPage().getParameters().get('acId'); acc=[select name,id,phone,website,Industry from account where id=:accID]; if(con == null) { con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Name, Phone, Email FROM Contact where AccountID=:accID Order By Name]));
con.setPageSize(5);
} return con;
} set; } public List getCategories() { categories = new List(); for (Contact category : (List)con.getRecords()) { categories.add(new CategoryWrapper(category)); } system.debug('cons1'+categories.size()); return categories; } public pagereference process(){
List contactsDel=new List(); for (CategoryWrapper cw : categories) { if (cw.checked) { contactsDel.add(cw.cat); }
} if(contactsDel!=null){ delete contactsDel; categories.clear(); getCategories(); }
PageReference p = new PageReference(ApexPages.currentPage().getUrl()); p.setRedirect(true);
return p ;
} public Integer totalPages { get { Integer currPageNumber = con.getPageNumber(); con.last(); Integer totalPages = con.getPageNumber(); con.setpageNumber(currPageNumber); return totalPages; } set; }controller

public class standardsetctrl {

 Public List<categoryWrapper> categories {get;set;}
    Public Account acc {get; set;}     
    public String accID;    
public ApexPages.StandardSetController con {
        get {
            String accID=  ApexPages.currentPage().getParameters().get('acId');
            acc=[select name,id,phone,website,Industry from account where id=:accID];
                                   if(con == null) {
                con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Name, Phone, Email FROM Contact where AccountID=:accID Order By Name]));             
           con.setPageSize(5);                
             }
            return con;           
        }
        set;
}
  public List<CategoryWrapper> getCategories() {
        categories = new List<categoryWrapper>();
              for (Contact category : (List<Contact>)con.getRecords()) {
            categories.add(new CategoryWrapper(category));
        }
        system.debug('cons1'+categories.size());
        return categories;
    }
public pagereference process(){         
         List<Contact> contactsDel=new List<Contact>();
 for (CategoryWrapper cw : categories) {
             if (cw.checked) {
                 contactsDel.add(cw.cat);
             }            
               }
             if(contactsDel!=null){
         delete contactsDel;
categories.clear();
getCategories();
      }           
          PageReference p = new PageReference(ApexPages.currentPage().getUrl());
          p.setRedirect(true);     
         return p ;   
     }
     public Integer totalPages {
get {
Integer currPageNumber = con.getPageNumber();
con.last();
Integer totalPages = con.getPageNumber();
con.setpageNumber(currPageNumber);
return totalPages;
}
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;
    }
    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 Contact cat { get; set;}

  // 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 Contact cat { get; set;}

        public CategoryWrapper(){
            cat = new Contact();
            checked = false;
        }
        public CategoryWrapper(Contact c){
            cat = c;
            checked = false;
        }
    }
}

} vf vf page: <apex:page controller="standardsetctrl"> <apex:form > <apex:pageBlock > <apex:pageBlockSection columns="2"> <apex:facet name="header"> Account details </apex:facet>
<apex:outputField value="{!acc.name}"/> <apex:outputField value="{!acc.phone}"/> <apex:outputField value="{!acc.Website }"/> <apex:outputField value="{!acc.Industry}"/> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock title="Contacts" id="pbt">
<apex:pagemessages />
<apex:pageBlockSection columns="1" id="ps"> <apex:facet name="header"> Contact - Page #{!pageNumber}of {!totalPages} </apex:facet>
<apex:outputPanel id="pb1"> <apex:pageBlockTable value="{!Categories}" var="c" id="pg"> <apex:column width="25px">
<apex:inputCheckbox value="{!c.checked}" id="inputId"/> </apex:column> <apex:column value="{!c.cat.Name}" headerValue="Name"/> <apex:column value="{!c.cat.phone}" headerValue="phone"/> <apex:column value="{!c.cat.email}" headerValue="email"/> </apex:pageBlockTable>
</apex:outputPanel>
</apex:pageBlockSection> <apex:pageBlockButtons location="top"> <apex:commandButton action="{!process}" value="Delete" rerender="pbt" />
</apex:pageBlockButtons>
</apex:pageBlock> <apex:panelGrid columns="4"> <apex:commandLink action="{!first}" dir="RTL">first</apex:commandlink> <apex:commandLink action="{!previous}" rendered="{!hasPrevious}" Dir="LTR">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>

<apex:page controller="standardsetctrl">
    <apex:form >
        <apex:pageBlock >
    <apex:pageBlockSection columns="2">
    <font>
        <apex:facet name="header">
            <span style="color:black">Account details</span>
        </apex:facet>     
    </font> 
        <apex:outputField value="{!acc.name}"/>
        <apex:outputField value="{!acc.phone}"/>
        <apex:outputField value="{!acc.Website }"/>
        <apex:outputField value="{!acc.Industry}"/>
    </apex:pageBlockSection>
    </apex:pageBlock>
    <apex:pageBlock title="Contacts" id="pbt">     
        <apex:pagemessages />        
      <apex:pageBlockSection columns="1" id="ps">
      <font>
        <apex:facet name="header">
            <span style="color:black">Contact - Page #{!pageNumber}of {!totalPages}</span>
        </apex:facet>     
      </font>
      <apex:outputPanel id="pb1">
        <apex:pageBlockTable value="{!Categories}" var="c" id="pg">
          <apex:column width="25px">                        
                        <apex:inputCheckbox value="{!c.checked}" id="inputId"/>
                    </apex:column>
          <apex:column value="{!c.cat.Name}" headerValue="Name"/>
           <apex:column value="{!c.cat.phone}" headerValue="phone"/>
            <apex:column value="{!c.cat.email}" headerValue="email"/>
        </apex:pageBlockTable>        
        </apex:outputPanel>        
      </apex:pageBlockSection>
           <apex:pageBlockButtons location="top">
        <apex:commandButton action="{!process}" value="Delete" rerender="pbt" />         
      </apex:pageBlockButtons>  
    </apex:pageBlock>
    <apex:panelGrid columns="4">
    <apex:commandLink action="{!first}" dir="RTL">first</apex:commandlink>
    <apex:commandLink action="{!previous}" rendered="{!hasPrevious}" Dir="LTR">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>

i have a requirement for that i 've done some code for pagenated wrapped records with checkboxes using standardset controller. now i wana display all pagenated records with all buttons like (1..2..3...4..5..etc) with out next,previous,first,last buttons. PlZ any body let me know is it posible thorugh standardset controller methods or how? my bellow code is satisfying my requirement up to some extent only. controller public class standardsetctrl {

Public List categories {get;set;} Public Account acc {get; set;}
public String accID;
public ApexPages.StandardSetController con { get { String accID= ApexPages.currentPage().getParameters().get('acId'); acc=[select name,id,phone,website,Industry from account where id=:accID]; if(con == null) { con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Name, Phone, Email FROM Contact where AccountID=:accID Order By Name]));
con.setPageSize(5);
} return con;
} set; } public List getCategories() { categories = new List(); for (Contact category : (List)con.getRecords()) { categories.add(new CategoryWrapper(category)); } system.debug('cons1'+categories.size()); return categories; } public pagereference process(){
List contactsDel=new List(); for (CategoryWrapper cw : categories) { if (cw.checked) { contactsDel.add(cw.cat); }
} if(contactsDel!=null){ delete contactsDel; categories.clear(); getCategories(); }
PageReference p = new PageReference(ApexPages.currentPage().getUrl()); p.setRedirect(true);
return p ;
} public Integer totalPages { get { Integer currPageNumber = con.getPageNumber(); con.last(); Integer totalPages = con.getPageNumber(); con.setpageNumber(currPageNumber); return totalPages; } 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;
}
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 Contact cat { get; set;}

    public CategoryWrapper(){
        cat = new Contact();
        checked = false;
    }
    public CategoryWrapper(Contact c){
        cat = c;
        checked = false;
    }
}

} vf page: <apex:page controller="standardsetctrl"> <apex:form > <apex:pageBlock > <apex:pageBlockSection columns="2"> <apex:facet name="header"> Account details </apex:facet>
<apex:outputField value="{!acc.name}"/> <apex:outputField value="{!acc.phone}"/> <apex:outputField value="{!acc.Website }"/> <apex:outputField value="{!acc.Industry}"/> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock title="Contacts" id="pbt">
<apex:pagemessages />
<apex:pageBlockSection columns="1" id="ps"> <apex:facet name="header"> Contact - Page #{!pageNumber}of {!totalPages} </apex:facet>
<apex:outputPanel id="pb1"> <apex:pageBlockTable value="{!Categories}" var="c" id="pg"> <apex:column width="25px">
<apex:inputCheckbox value="{!c.checked}" id="inputId"/> </apex:column> <apex:column value="{!c.cat.Name}" headerValue="Name"/> <apex:column value="{!c.cat.phone}" headerValue="phone"/> <apex:column value="{!c.cat.email}" headerValue="email"/> </apex:pageBlockTable>
</apex:outputPanel>
</apex:pageBlockSection> <apex:pageBlockButtons location="top"> <apex:commandButton action="{!process}" value="Delete" rerender="pbt" />
</apex:pageBlockButtons>
</apex:pageBlock> <apex:panelGrid columns="4"> <apex:commandLink action="{!first}" dir="RTL">first</apex:commandlink> <apex:commandLink action="{!previous}" rendered="{!hasPrevious}" Dir="LTR">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>

i have a requirement for that i 've done some code for pagenated wrapped records with checkboxes using standardset controller. now i wana display all pagenated records with all buttons like (1..2..3...4..5..etc) with out next,previous,first,last buttons. PlZ any body let me know is it posible thorugh standardset controller methods or how? my bellow code is satisfying my requirement up to some extent only.

controller

public class standardsetctrl {

 Public List<categoryWrapper> categories {get;set;}
    Public Account acc {get; set;}     
    public String accID;    
public ApexPages.StandardSetController con {
        get {
            String accID=  ApexPages.currentPage().getParameters().get('acId');
            acc=[select name,id,phone,website,Industry from account where id=:accID];
                                   if(con == null) {
                con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Name, Phone, Email FROM Contact where AccountID=:accID Order By Name]));             
           con.setPageSize(5);                
             }
            return con;           
        }
        set;
}
  public List<CategoryWrapper> getCategories() {
        categories = new List<categoryWrapper>();
              for (Contact category : (List<Contact>)con.getRecords()) {
            categories.add(new CategoryWrapper(category));
        }
        system.debug('cons1'+categories.size());
        return categories;
    }
public pagereference process(){         
         List<Contact> contactsDel=new List<Contact>();
 for (CategoryWrapper cw : categories) {
             if (cw.checked) {
                 contactsDel.add(cw.cat);
             }            
               }
             if(contactsDel!=null){
         delete contactsDel;
categories.clear();
getCategories();
      }           
          PageReference p = new PageReference(ApexPages.currentPage().getUrl());
          p.setRedirect(true);     
         return p ;   
     }
     public Integer totalPages {
get {
Integer currPageNumber = con.getPageNumber();
con.last();
Integer totalPages = con.getPageNumber();
con.setpageNumber(currPageNumber);
return totalPages;
}
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;
    }
    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 Contact cat { get; set;}

        public CategoryWrapper(){
            cat = new Contact();
            checked = false;
        }
        public CategoryWrapper(Contact c){
            cat = c;
            checked = false;
        }
    }
}

vf page:

<apex:page controller="standardsetctrl">
    <apex:form >
        <apex:pageBlock >
    <apex:pageBlockSection columns="2">
    <font>
        <apex:facet name="header">
            <span style="color:black">Account details</span>
        </apex:facet>     
    </font> 
        <apex:outputField value="{!acc.name}"/>
        <apex:outputField value="{!acc.phone}"/>
        <apex:outputField value="{!acc.Website }"/>
        <apex:outputField value="{!acc.Industry}"/>
    </apex:pageBlockSection>
    </apex:pageBlock>
    <apex:pageBlock title="Contacts" id="pbt">     
        <apex:pagemessages />        
      <apex:pageBlockSection columns="1" id="ps">
      <font>
        <apex:facet name="header">
            <span style="color:black">Contact - Page #{!pageNumber}of {!totalPages}</span>
        </apex:facet>     
      </font>
      <apex:outputPanel id="pb1">
        <apex:pageBlockTable value="{!Categories}" var="c" id="pg">
          <apex:column width="25px">                        
                        <apex:inputCheckbox value="{!c.checked}" id="inputId"/>
                    </apex:column>
          <apex:column value="{!c.cat.Name}" headerValue="Name"/>
           <apex:column value="{!c.cat.phone}" headerValue="phone"/>
            <apex:column value="{!c.cat.email}" headerValue="email"/>
        </apex:pageBlockTable>        
        </apex:outputPanel>        
      </apex:pageBlockSection>
           <apex:pageBlockButtons location="top">
        <apex:commandButton action="{!process}" value="Delete" rerender="pbt" />         
      </apex:pageBlockButtons>  
    </apex:pageBlock>
    <apex:panelGrid columns="4">
    <apex:commandLink action="{!first}" dir="RTL">first</apex:commandlink>
    <apex:commandLink action="{!previous}" rendered="{!hasPrevious}" Dir="LTR">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>
Source Link
Loading