You need to sign in to do that
Don't have an account?

Pagination with Standard controller and Extension
Hello Dears,
Please let me know how to implement Pagination with Standard Controller and Extension used in Apex:Page.
Kindly assist on this.
Thanks,
Rohit Sharma
Please let me know how to implement Pagination with Standard Controller and Extension used in Apex:Page.
Kindly assist on this.
Thanks,
Rohit Sharma
Check the below links.
http://blog.jeffdouglas.com/2009/07/14/visualforce-page-with-pagination/
http://hisrinu.wordpress.com/2012/01/09/pagination-using-standardsetcontroller/
There are several tutorials that expalins how can we do pagination by standard controller.
Please find below the code that paginate using extension.
Apex Controller:-
public with sharing class PaginationExtension {
Public Integer noOfRecords{get; set;}
Public Integer size{get;set;}
public ApexPages.StandardSetController setCon {
get{
if(setCon == null){
size = 10;
string queryString = 'Select Name, Type, BillingCity, BillingState, BillingCountry from Account order by Name';
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);
noOfRecords = setCon.getResultSize();
}
return setCon;
}set;
}
Public List<Account> getAccounts(){
List<Account> accList = new List<Account>();
for(Account a : (List<Account>)setCon.getRecords())
accList.add(a);
return accList;
}
public pageReference refresh() {
setCon = null;
getAccounts();
setCon.setPageNumber(1);
return null;
}
}
VF page:
<apex:page Controller="PaginationExtension">
<apex:form >
<apex:pageBlock id="pb">
<apex:pageBlockTable value="{!Accounts}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Type}"/>
<apex:column value="{!a.BillingCity}"/>
<apex:column value="{!a.BillingState}"/>
<apex:column value="{!a.BillingCountry}"/>
</apex:pageBlockTable>
<apex:panelGrid columns="7">
<apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/>
<apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/>
<apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>
<apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
<apex:outputPanel style="color:#4AA02C;font-weight:bold">
<apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
</apex:outputPanel>
</apex:panelGrid>
</apex:pageBlock>
</apex:form>
</apex:page>
Please find here some url where you can explore yourself and customize accordingly.
1. http://hisrinu.wordpress.com/2012/01/09/pagination-using-standardsetcontroller/
2. http://blog.ryansieve.com/2012/06/06/pagination-made-easy-with-standard-set-controllers/
3. https://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_sosc_pagination.htm
4. https://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm
Please feel free to contact in case of any other issue.
Thanks,
Regards,
Grazitti Team
Web: www.grazitti.com
https://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_sosc_pagination.htm
Is there any way to give the page size dynamically from vf ? like passing the select list values from vf to apex variable size = 10 mentioned above?
Regards,
Raj
I want to use pagination for search result at my visualforce page, I want to use your PaginationExtension apex controller code in my existing apex controller displaycase, pl suggest required change in my apex controller code, my apex controller and visualforce page code is below