I don't know why the below code is not working , next and previous button.
Any help would be highly appreciated??
VF Page :-
<apex:page controller="paginationcls" >
<apex:form>
<apex:pageblock>
<apex:pageBlockTable value="{!paginateAccts}" var="acc" id="pbt">
<apex:column value="{!acc.Name}" />
<apex:column value="{!acc.Phone}"/>
</apex:pageBlockTable>
<apex:commandButton value="Next" action="{!GoNext}" reRender="pbt"/>
<apex:commandButton value="Previous" action="{!GoPrevious}" reRender="pbt"/>
</apex:pageblock>
</apex:form>
</apex:page>
Apex Class:-
public class paginationcls {
public ApexPages.StandardSetController setCon{set;get;}
public List<Account> paginateAccts{set;get;}
public paginationcls(){
setCon= new ApexPages.StandardSetController([select id,name,phone from Account limit 20]);
setCon.setPageSize(5);
paginateAccts=(List<Account>)setCon.getRecords();
system.debug(paginateAccts);
}
public void GoNext(){
setCon.next();
}
public void GoPrevious(){
setCon.previous();
}
}
You never update paginateAccts
. You need to reset that variable each time you change a page, in the GoNext()
and GoPrevious()
. Otherwise, you're simply re-rendering the same list each time.
-
,thnx for ur awesome response but i dont know how to reset the page on calling next method...i dont think any standard method is given in Standardsetcontroller class – SFDCTashan Apr 10 '20 at 15:51
-
got the answer from your hint... paginateAccts=(List<Account>)setCon.getRecords(); This line i need to write again in GoNext() method it will work. Let me try it for Previuos method also. – SFDCTashan Apr 10 '20 at 15:54
-