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>