You need to sign in to do that
Don't have an account?
Lakshmi Gupta 4
Help with Pagination code
Hi All,
I'm trying to do Pagination in my VFpage. I have the below code. When I preview the page all my buttons are Disabled. Can someone tell me why is it dispabled? Attendance__C had When I load the page it displays 10 records.
Thanks for your help!!
public class PaginationAttendance{
public String acctlist { get; set; }
private integer totalRecs = 0;
private integer OffsetSize = 0;
private integer LimitSize= 10;
public integer Pagination() {
totalRecs = [select count() from attendance__c];
return totalRecs;
}
public List<attendance__c> getacclist() {
List<attendance__c> acc =[SELECT contact__c, Manager__c, Manager_s_Manager__c,
Approved__c,Attendance_Date__c, Hours__C,
Is_Eligible_for_compensatory_off__c, AttendanceType__c FROM Attendance__c LIMIT :LimitSize OFFSET :OffsetSize];
return acc;
}
public void FirstPage() {
OffsetSize = 0;
}
public void previous(){
OffsetSize = OffsetSize - LimitSize;
}
public void next(){
OffsetSize = OffsetSize + LimitSize;
}
public void LastPage() {
OffsetSize = totalrecs - math.mod(totalRecs,LimitSize);
}
public boolean getprev() {
if(OffsetSize == 0)
return true;
else
return false;
}
public boolean getnxt(){
if((OffsetSize + LimitSize) > totalRecs)
return true;
else
return false;
}
}
===============================================================================
<apex:page controller="PaginationAttendance" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock id="details">
<apex:pageblockTable value="{!acclist}" var="acc">
<apex:column value="{!acc.Contact__c}"/>
<apex:column value="{!acc.Manager__c}"/>
<apex:column value="{!acc.Manager_s_Manager__c}"/>
<apex:column value="{!acc.Approved__c}"/>
<apex:column value="{!acc.Attendance_Date__c}"/>
<apex:column value="{!acc.Hours__c}"/>
<apex:column value="{!acc.Is_Eligible_for_compensatory_off__c}"/>
<apex:column value="{!acc.AttendanceType__c}"/>
</apex:pageblockTable>
<apex:pageblockButtons >
<apex:commandButton value="First Page" rerender="details" action="{!FirstPage}" disabled="{!prev}"/>
<apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/>
<apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/>
<apex:commandButton value="Last Page" rerender="details" action="{!LastPage}" disabled="{!nxt}"/>
</apex:pageblockButtons>
</apex:pageBlock>
</apex:form></apex:page>
I'm trying to do Pagination in my VFpage. I have the below code. When I preview the page all my buttons are Disabled. Can someone tell me why is it dispabled? Attendance__C had When I load the page it displays 10 records.
Thanks for your help!!
public class PaginationAttendance{
public String acctlist { get; set; }
private integer totalRecs = 0;
private integer OffsetSize = 0;
private integer LimitSize= 10;
public integer Pagination() {
totalRecs = [select count() from attendance__c];
return totalRecs;
}
public List<attendance__c> getacclist() {
List<attendance__c> acc =[SELECT contact__c, Manager__c, Manager_s_Manager__c,
Approved__c,Attendance_Date__c, Hours__C,
Is_Eligible_for_compensatory_off__c, AttendanceType__c FROM Attendance__c LIMIT :LimitSize OFFSET :OffsetSize];
return acc;
}
public void FirstPage() {
OffsetSize = 0;
}
public void previous(){
OffsetSize = OffsetSize - LimitSize;
}
public void next(){
OffsetSize = OffsetSize + LimitSize;
}
public void LastPage() {
OffsetSize = totalrecs - math.mod(totalRecs,LimitSize);
}
public boolean getprev() {
if(OffsetSize == 0)
return true;
else
return false;
}
public boolean getnxt(){
if((OffsetSize + LimitSize) > totalRecs)
return true;
else
return false;
}
}
===============================================================================
<apex:page controller="PaginationAttendance" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock id="details">
<apex:pageblockTable value="{!acclist}" var="acc">
<apex:column value="{!acc.Contact__c}"/>
<apex:column value="{!acc.Manager__c}"/>
<apex:column value="{!acc.Manager_s_Manager__c}"/>
<apex:column value="{!acc.Approved__c}"/>
<apex:column value="{!acc.Attendance_Date__c}"/>
<apex:column value="{!acc.Hours__c}"/>
<apex:column value="{!acc.Is_Eligible_for_compensatory_off__c}"/>
<apex:column value="{!acc.AttendanceType__c}"/>
</apex:pageblockTable>
<apex:pageblockButtons >
<apex:commandButton value="First Page" rerender="details" action="{!FirstPage}" disabled="{!prev}"/>
<apex:commandButton value="Previous" rerender="details" action="{!previous}" disabled="{!prev}"/>
<apex:commandButton value="Next" rerender="details" action="{!next}" disabled="{!nxt}"/>
<apex:commandButton value="Last Page" rerender="details" action="{!LastPage}" disabled="{!nxt}"/>
</apex:pageblockButtons>
</apex:pageBlock>
</apex:form></apex:page>
All Answers
You can try pagination with standard set controller which was provided natively by salesforce rather reinventing the wheel again.
Below you can find the links for the same.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_pages_standardsetcontroller.htm
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardSetController_methods.htm
https://hisrinu.wordpress.com/2012/01/09/pagination-using-standardsetcontroller/
Thanks for reply!
I have to write pagination on a custom object. So How can I use the standard set controller?
https://hisrinu.wordpress.com/2012/01/09/pagination-using-standardsetcontroller/ this link was very useful!!