Simple Pagination Example in Visualforce.
Hi,
In this post i am writing simple pagenation example on Account object, Here i am using a controller class.
Controller Class :
public class AccountPaginationController {
public ApexPages.StandardSetController stCon{
get{
if(stCon == null){
stCon = new ApexPages.StandardSetController(Database.getQueryLocator([Select id,Name,Phone from Account order by Name limit 1000]));
stCon.setPageSize(5);
}
return stCon;
}
set;
}
//method.
public List<Account> getAccoountList(){
return (List<Account>)stCon.getRecords();
}
public Boolean hasNext {
get {
return stCon.getHasNext();
}
set;
}
public Boolean hasPrevious {
get {
return stCon.getHasPrevious();
}
set;
}
public Integer pageNumber {
get {
return stCon.getPageNumber();
}
set;
}
public void first() {
stCon.first();
}
public void last() {
stCon.last();
}
public void previous() {
stCon.previous();
}
public void next() {
stCon.next();
}
public void cancel() {
stCon.cancel();
}
}
Visualforce Page :
<apex:page controller="AccountPaginationController">
<apex:form >
<apex:pageblock >
<apex:pageblockSection title="Account Results - Page #{!pageNumber}" columns="1" >
<apex:pageblockTable value="{!AccoountList}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.phone}"/>
</apex:pageblockTable>
<apex:panelGrid columns="4">
<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandlink>
<apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandlink>
<apex:commandLink action="{!last}">Last</apex:commandlink>
</apex:panelGrid>
</apex:pageblockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Output:
That's it..
0 comments:
Post a Comment