Controller Code :-
public class PaginationControllerOpportunity { Public integer TotalRecordCount=0; Public Integer Offsetsize=0; Public Integer LimitSize=10; Public PaginationControllerOpportunity (){ TotalRecordCount=[Select count() From opportunity]; } public boolean getNxt() { if((OffsetSize + LimitSize) > TotalRecordCount) return true; else return false; } public boolean getPrev() { if(Offsetsize==0) return true; else return false; } public void LastPage() { Offsetsize = TotalRecordCount - math.mod(TotalRecordCount,LimitSize); } public void Next() { Offsetsize=Offsetsize+LimitSize; } public void Previous() { Offsetsize=Offsetsize-LimitSize; } public void FirstPage() { Offsetsize=0; } public List<opportunity> getopplist(){ List<opportunity> opp= Database.Query('SELECT Name, StageName, CloseDate FROM opportunity LIMIT :LimitSize OFFSET :OffsetSize'); return opp; } }
VisualForce Page Code :-
<apex:page controller="PaginationControllerOpportunity"> <apex:form > <apex:pageBlock title="All Opportunity Details" id="BlockId"> <apex:pageBlockTable value="{!Opplist}" var="Opp"> <apex:column value="{!Opp.name}" /> <apex:column value="{!Opp.StageName}" /> <apex:column value="{!Opp.CloseDate }" /> </apex:pageBlockTable> <apex:pageBlockButtons > <apex:commandButton action="{!FirstPage}" value="First Page" rerender="BlockId" disabled="{!Prev}" /> <apex:commandButton action="{!Previous}" value="Previous" rerender="BlockId" disabled="{!Prev}" /> <apex:commandButton action="{!Next}" value="Next" rerender="BlockId" disabled="{!Nxt}" /> <apex:commandButton action="{!LastPage}" value="Last Page" rerender="BlockId" disabled="{!Nxt}" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
Screenshot 1 :-
No comments:
Post a Comment