Overriding Default Size 20 of Standard List Controller While Pagination
// Override default size 20 to 2 as below.
If you want to overide the record per page then you will have to use custom controller for Sales__c object as below. In the below custom controller, i have set page size =2 so that you can see the effects of pagination.
----------------VF------------------------------------
<apex:page controller="CustomObjectPaginationController">
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!setCon.save}"/>
<apex:commandButton value="Return" action="{!setCon.cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!customObjects}" var="s" id="table" rows="10">
<apex:column headerValue="Account Name">
<apex:outputField value="{!s.Name}"/>
</apex:column>
</apex:pageBlockTable>
<apex:commandLink action="{!setCon.previous}" value="Previous Page" rendered="{!setCon.hasPrevious}"/>
<apex:commandLink action="{!setCon.next}" value="Next Page" rendered="{!setCon.hasNext}"/>
<apex:commandLink action="{!setCon.last}" value="Last Page" rendered="{!setCon.hasNext}"/>
<apex:commandLink action="{!setCon.first}" value="First Page" rendered="{!setCon.hasPrevious}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
---------------------------------
Controller
----------------------------------
public class CustomObjectPaginationController{
public Integer size{get;set;}
public CustomObjectPaginationController(){
size=2;
}
public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
[select id,Name from sale__c]));
setCon.setPageSize(size);
}
return setCon;
}
set;
}
// Initialize setCon and return a list of record
public List<sale__c> getCustomObjects() {
return (List<sale__c>) setCon.getRecords();
}
}
---------------------------------------------------------------
If you want to overide the record per page then you will have to use custom controller for Sales__c object as below. In the below custom controller, i have set page size =2 so that you can see the effects of pagination.
----------------VF------------------------------------
<apex:page controller="CustomObjectPaginationController">
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!setCon.save}"/>
<apex:commandButton value="Return" action="{!setCon.cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!customObjects}" var="s" id="table" rows="10">
<apex:column headerValue="Account Name">
<apex:outputField value="{!s.Name}"/>
</apex:column>
</apex:pageBlockTable>
<apex:commandLink action="{!setCon.previous}" value="Previous Page" rendered="{!setCon.hasPrevious}"/>
<apex:commandLink action="{!setCon.next}" value="Next Page" rendered="{!setCon.hasNext}"/>
<apex:commandLink action="{!setCon.last}" value="Last Page" rendered="{!setCon.hasNext}"/>
<apex:commandLink action="{!setCon.first}" value="First Page" rendered="{!setCon.hasPrevious}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
---------------------------------
Controller
----------------------------------
public class CustomObjectPaginationController{
public Integer size{get;set;}
public CustomObjectPaginationController(){
size=2;
}
public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
[select id,Name from sale__c]));
setCon.setPageSize(size);
}
return setCon;
}
set;
}
// Initialize setCon and return a list of record
public List<sale__c> getCustomObjects() {
return (List<sale__c>) setCon.getRecords();
}
}
---------------------------------------------------------------
I hope this will help you.
Comments
Post a Comment