Simple Visualforce Pagination Example Using Standaredset Controller.
Hi,In this post i am giving a simple example of visualforce pagination using standardset controller.
Visualforce Page:
<apex:page controller="opportunityListCon">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!Opportunities}" var="o">
<apex:column value="{!o.name}"/>
<apex:column value="{!o.closedate}"/>
</apex:pageBlockTable>
<apex:commandButton rendered="{!setCon.hasPrevious}" value="first" action="{!setCon.first}"/>
<apex:commandButton rendered="{!setCon.hasPrevious}" value="Previous" action="{!setCon.previous}"/>
<apex:outputText rendered="{!(setCon.pageNumber * setCon.pageSize) < setCon.ResultSize}" value="{!setCon.pageNumber * setCon.pageSize} Of {!setCon.ResultSize}"></apex:outputText>
<apex:outputText rendered="{!(setCon.pageNumber * setCon.pageSize) >= setCon.ResultSize}" value="{!setCon.ResultSize} Of {!setCon.ResultSize}"></apex:outputText>
<apex:commandButton rendered="{!setCon.hasNext}" value="next" action="{!setCon.next}"/>
<apex:commandButton rendered="{!setCon.hasNext}" value="last" action="{!setCon.last}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller Class:
public class opportunityListCon {
// ApexPages.StandardSetController must be instantiated
// for standard list controllers
public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
[select name,closedate from Opportunity]));
}
return setCon;
}
set;
}
// Initialize setCon and return a list of records
public List<Opportunity> getOpportunities() {
setCon.setpagesize(5);
return (List<Opportunity>) setCon.getRecords();
}
}
Output:
1 comments:
Hi! Do you have a test class written for this example?
Post a Comment