Scenario:
Sometimes we get this problem. Objects having lot of records,we con't display single page.so we need one more page.Click on next to show records.
Solution:
Visualforce Code:
Apex controller:
Sometimes we get this problem. Objects having lot of records,we con't display single page.so we need one more page.Click on next to show records.
Solution:
Visualforce Code:
<apex:page controller="paginationController"> <apex:form > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton value="Previous" action="{!Previous}" reRender="table" status="status"/> <apex:commandButton value="Next" action="{!Next}" reRender="table" status="status"/> <apex:actionStatus id="status" > <apex:facet name="start"> <apex:image value="/img/loading32.gif" style="height: 15px;"></apex:image> </apex:facet> </apex:actionstatus> </apex:pageBlockButtons> <apex:pageblockTable value="{!lstAcct}" var="item" id="table"> <apex:column value="{!item.name}"/> <apex:column value="{!item.Accountnumber}"/> <apex:column value="{!item.Phone}"/> </apex:pageblockTable> </apex:pageBlock> </apex:form> </apex:page>
public class paginationController { Integer recordLimit = 10; Integer offSetLimit = 0; Public List<Account> lstAcct { get{ lstAcct = [select Id,name,Accountnumber,phone from Account Limit :recordLimit OFFSET :offSetLimit ]; return lstAcct; }set; } public paginationController (){ } Public pagereference Next(){ offSetLimit = offSetLimit + 4; return null; } Public pagereference Previous(){ if(offSetLimit > 0) offSetLimit = offSetLimit - 4; return null; } }Result: