You need to sign in to do that
Don't have an account?
ashish jadhav 9
How to implement pagination in vf?
I'm new to salesforce, can you please tell me rough idea that how can I implement pagination?
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
Hi Ashish,
Please check the sample code for pagination.
Please check the below links:
http://blog.jeffdouglas.com/2009/07/14/visualforce-page-with-pagination/
https://www.minddigital.com/how-to-create-pagination-within-salesforce/
http://www.redpointcrm.com/add-pagination-to-your-visualforce-pages-using-the-soql-offset-clause
https://hisrinu.wordpress.com/2012/01/09/pagination-using-standardsetcontroller/
Hope this helps you!
Best Regards,
Deepthi
1) http://amitsalesforce.blogspot.in/search/label/Pagination
StandardSetController objects allow you to create list controllers similar to, or as extensions of, the pre-built Visualforce list controllers provided by Salesforce
You can instantiate a StandardSetController in either of the following ways:
From a list of sObjects:
From a list of sObjects: Visual force page
Apex Class
Let us know if this will help you
Thanks
Amit Chaudhary
Please check the below sample code
Visualforce Page:
Controller
Output
Hope this helps you!
Best Regards,
Jyothsna
Above is the output for the below code:
APEX CODE:-
===========
public with sharing class DoctorLookUpMorning_cntrl {
public String istab3disabled { get; set; }
public Patientfield__c patc {get;set;}
private string selectedtab;
public Patient__c p {get; set;}
public String str1 {get; set;}
public Out_Patient__c DS{get; set;}
public DoctorLookUpMorning_cntrl(){
selectedTab = 'tab1';
p= new Patient__c();
patc=new Patientfield__c();
DS= New Out_Patient__c();
str1= ApexPages.currentPage().getParameters().get('id');
system.debug('hello'+ str1);
p = [select id,Name,Contact_NO__c,Patient_Problem__c from Patient__c where id=:str1];
//patc.Patient_ID_del__c = p.id;
// patc.contact__c=p.Contact_NO__c;
//DS=[select Medicine_Type__c,Diet__c,Injections__c,Quantity__c from Out_Patient__c];
}
public boolean getistab1disabled() {
return selectedTab != 'tab1';
}
public boolean getistab2disabled() {
return selectedTab != 'tab2';
}
public boolean getistab3disabled() {
return selectedTab != 'tab3';
}
public void enabletab1() {
selectedtab = 'tab1';
}
public void enabletab2() {
selectedtab = 'tab2';
}
public string getselectedtab() {
return selectedtab;
}
public void enabletab3() {
selectedtab = 'tab3';
}
}
VF Page:-
=====================================
<apex:page controller="DoctorLookUpMorning_cntrl" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:inputField value="{!p.Name}"/>
<apex:inputField value="{!p.Contact_NO__c}"/>
<apex:inputField value="{!p.Patient_Problem__c }"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Day Sheets">
<apex:tabPanel id="tabPanel" selectedTab="{!selectedTab}">
<apex:tab Title="Tab1" labelWidth="100px" label="Morning Medicine" reRender="tabPanel" id="tab1" disabled="{!istab1disabled}" immediate="false">
<apex:outputPanel id="id1">
<apex:pageBlock id="pb1">
<apex:pageBlockSection title="Morning Medicine Details" >
<apex:inputField value="{!DS.Medicine_Type__c}"/><br/><br/>
<apex:inputField value="{!DS.Diet__c}"/><br/><br/>
<apex:inputField value="{!DS.Quantity__c }"/><br/><br/>
<apex:inputField value="{!DS.Injections__c}"/><br/><br/>
<apex:commandButton value="Next" action="{!enabletab2}" rerender="tabPanel,id2" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:tab>
<apex:tab title="Tab2" labelWidth="100px" label="Afternoon Medicine" reRender="tabPanel" id="tab2" disabled="{!istab2disabled}" immediate="false">
<apex:outputPanel id="id2">
<apex:pageBlock >
<apex:pageBlockSection title="Afternoon Medicine Details">
<apex:inputField value="{!DS.Medicine_Type__c}" /><br/><br/>
<apex:inputField value="{!DS.Diet__c}"/><br/><br/>
<apex:inputField value="{!DS.Quantity__c }"/><br/><br/>
<apex:inputField value="{!DS.Injections__c}"/><br/><br/>
<apex:commandButton value="Previous" action="{!enabletab1}" rerender="tabPanel,id1" />
<apex:commandButton value="Next" action="{!enabletab3}" rerender="tabPanel,id3" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:tab>
<apex:tab title="Tab3" labelWidth="100px" label="Evening Medicine" reRender="tabPanel" id="tab3" disabled="{!istab3disabled}" immediate="false">
<apex:outputPanel id="id3">
<apex:pageBlock >
<apex:pageBlockSection title="Evening Medicine Details">
<apex:inputField value="{!DS.Medicine_Type__c}" /><br/><br/>
<apex:inputField value="{!DS.Diet__c}"/><br/><br/>
<apex:inputField value="{!DS.Quantity__c }"/><br/><br/>
<apex:inputField value="{!DS.Injections__c}"/><br/><br/>
<apex:commandButton value="Previous" action="{!enabletab2}" rerender="tabPanel,id2" />
<apex:commandButton value="Save" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:outputPanel>
</apex:tab>
</apex:tabpanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
we have one custom object called DaySheets we fetched the three fields in that objects in three different tabs using tabPanel but here the problem is we have to give different values in each tab but the value is carry forwrding when we press the next button and previous buttons as well please suggest any solution
Thanks
Regards
Veena
==========================================================================
<apex:page standardController="Contact" recordSetVar="contacts">
<apex:form>
<apex:pageBlock title="Contacts List" id="contacts_list">
Filter:
<apex:selectList value="{! filterId }" size="1">
<apex:selectOptions value="{! listViewOptions }"/>
<apex:actionSupport event="onchange" reRender="contacts_list"/>
</apex:selectList>
<!-- Contacts List -->
<apex:pageBlockTable value="{! contacts }" var="ct">
<apex:column value="{! ct.FirstName }"/>
<apex:column value="{! ct.LastName }"/>
<apex:column value="{! ct.Email }"/>
<apex:column value="{! ct.Account.Name }"/>
</apex:pageBlockTable>
<!-- Pagination -->
<table style="width: 100%"><tr>
<td>
Page: <apex:outputText value=" {!PageNumber} of {! CEILING(ResultSize / PageSize) }"/>
</td>
<td align="center">
<!-- Previous page -->
<!-- active -->
<apex:commandLink action="{! Previous }" value="« Previous" rendered="{! HasPrevious }"/>
<!-- inactive (no earlier pages) -->
<apex:outputText style="color: #ccc;" value="« Previous" rendered="{! NOT(HasPrevious) }"/>
<!-- Next page -->
<!-- active -->
<apex:commandLink action="{! Next }" value="Next »" rendered="{! HasNext }"/>
<!-- inactive (no more pages) -->
<apex:outputText style="color: #ccc;" value="Next »" rendered="{! NOT(HasNext) }"/>
</td>
<td align="right">
Records per page: <apex:selectList value="{! PageSize }" size="1">
<apex:selectOption itemValue="5" itemLabel="5"/>
<apex:selectOption itemValue="20" itemLabel="20"/>
<apex:actionSupport event="onchange" reRender="contacts_list"/>
</apex:selectList>
</td>
</tr></table>
</apex:pageBlock>
</apex:form>
</apex:page>
Thank You,
Kundlik Yewale
I am new salesforce. What is the advantage of creating a customcontroller over using standard controller. Since most of the recommended custom controller. Made me curious. Please elighten us.
Use a custom controller for custom object or for multi object query.
I've tidied and corrected Jyothsna's code...
<apex:page Controller="PaginationExampleController">
<!-- readOnly="true" contentType="application/vnd.ms-excel#UserReport.xls" cache="true" -->
<!-- https://trailhead.salesforce.com/visualforce_fundamentals/visualforce_standard_list_controllers -->
<!-- Pagination -->
<!--
https://developer.salesforce.com/forums/?id=906F0000000BZxWIAW
https://developer.salesforce.com/forums/?id=906F000000096lRIAQ
-->
<apex:form id="form">
<apex:pageBlock >
<apex:pageBlockTable value="{!leads}" var="ld">
<apex:column headerValue="Name">
<apex:outputField value="{!ld.Name}"/>
</apex:column>
<apex:column headerValue="Email">
<apex:outputField value="{!ld.Email}"/>
</apex:column>
<apex:column headerValue="Company">
<apex:outputField value="{!ld.Company}"/>
</apex:column>
</apex:pageBlockTable>
<apex:outputLabel >Total no of recs:{!totalRecs}</apex:outputLabel>
<div align="center">
<apex:commandButton value="First Page" action="{!Firstbtn}" disabled="{!prv}" reRender="form"/>
<apex:commandButton value="PreviousPage" action="{!prvbtn}" disabled="{!prv}" reRender="form"/>
<apex:commandButton value="NextPage" action="{!Nxtbtn}" disabled="{!nxt}" reRender="form"/>
<apex:commandButton value="LastPage" action="{!lstbtn}" disabled="{!nxt}" reRender="form"/>
</div>
Display records per page <apex:selectList value="{!numberOfRowsToReturn}" size="1" >
<apex:selectOption itemLabel="1" itemValue="1" ></apex:selectOption>
<apex:selectOption itemLabel="2" itemValue="2"></apex:selectOption>
<apex:selectOption itemLabel="5" itemValue="5"></apex:selectOption>
<apex:selectOption itemLabel="10" itemValue="10"></apex:selectOption>
<apex:actionSupport event="onchange" reRender="form" action="{!updatePage}"/>
</apex:selectList><br/>
</apex:pageBlock>
</apex:form>
</apex:page>
public with sharing class PaginationExampleController {
public List<Lead> leads=new List<Lead>();
public integer totalRecs { get; set; }
public integer numberOfRowsToReturn {get; set;}
integer skipCount;
//Constructor
public PaginationExampleController()
{
numberOfRowsToReturn= 10;
skipCount= 0;
totalRecs = [SELECT Count() FROM Lead];
}
public List<Lead> getLeads() {
system.debug('numberOfRowsToReturn :' + numberOfRowsToReturn);
system.debug('skipCount :' + skipCount);
List<Lead> ld=[SELECT Name,Email,Company FROM Lead LIMIT:numberOfRowsToReturn OFFSET:skipCount];
system.debug('values are:' + ld);
return ld;
}
public void updatePage() {
leads.clear();
leads=[SELECT Name,Email,Company FROM Lead LIMIT:numberOfRowsToReturn OFFSET:skipCount];
}
public PageReference firstBtn() {
skipCount=0;
return null;
}
public PageReference prvBtn() {
skipCount=skipCount-numberOfRowsToReturn;
return null;
}
public PageReference nxtBtn() {
//skipCount cannot be > 2000 - a limitation of this method
skipCount=skipCount+numberOfRowsToReturn;
if (skipCount>2000){skipCount=2000;}
return null;
}
public PageReference lstBtn() {
skipCount= totalrecs - math.mod(totalRecs,numberOfRowsToReturn);
if (skipCount>2000){skipCount=2000;}
return null;
}
public Boolean getNxt() {
if((skipCount+ numberOfRowsToReturn) > totalRecs)
return true;
else
return false;
}
public Boolean getPrv() {
if(skipCount== 0)
return true;
else
return false;
}
}//PaginationExampleController
Its a generic pagination code. You need to just copy the base classes and add your recordper page in a apex constructor.
Please mark as best answer if you like.
https://github.com/ArunSahu1992/Generic-Pagination-in-Apex/tree/Learn-Environment/Pagination
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, Phone from Contact order by Name';
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
setCon.setPageSize(size);
noOfRecords = setCon.getResultSize();
}
return setCon;
}set;
}
Public List<Contact> getContacts(){
List<Contact> conList = new List<Contact>();
for(Contact a : (List<Contact>)setCon.getRecords())
conList.add(a);
return conList;
}
public pageReference refresh() {
setCon = null;
getContacts();
setCon.setPageNumber(1);
return null;
}
}
VFP:
<apex:page Controller="PaginationExtension">
<apex:form >
<apex:pageBlock id="pb">
<apex:pageBlockTable value="{!Contacts}" var="a">
<apex:column value="{!a.Name}"/>
<apex:column value="{!a.Phone}"/>
</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>
like if you liked it.
You can take reference from the below code for the pagination.
//Vf Page
//Class
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi