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.
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>