0

I am achieving pagination of Account records using vf page with custom controller.But the issue is that it is the Next button is functioning even when the list size has ended. How to fix that??

<apex:page controller="paginationcls">
    <apex:form>
       <apex:pageBlock id="pg">

           <apex:pageBlockButtons location="bottom">
                   <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="{!accLst}" var="acc"  id="table">
               <apex:column value="{!acc.name}"/>
           </apex:pageBlockTable>
       </apex:pageBlock>
    </apex:form>
</apex:page>

Controller Class :

public class Paginationcls{

    integer recordLimit = 10;
    integer offSetLimit = 0;
    integer index;

    public list<account> acclst{get
                                {acclst = [select Id,name from Account Limit :recordLimit OFFSET :offSetLimit ];
                                return acclst;
                                } set;
                             }

    public Paginationcls(){
    }                            

    public pagereference Next(){
    index = acclst.size() - 1;
         if(acclst.size()>0 && acclst.size()<index)

          system.debug('<<<<<<<acclst>>>>>>>>>>>'+acclst.size());
           offSetLimit = offSetLimit + 10;
    return null;
    }    

    public pagereference previous(){
           if(offSetLimit>0)
              offSetLimit = offSetLimit -10;

    return null;
    }
}
  • create a index variable. increase index++ on next button. calculate lastindex=list.size()/10; disable button when index==lastindex – Shravan Boddula Nov 10 '16 at 6:23
0
public boolean StillHas{get{
    if(listsize-offSetLimit <= 10){
        StillHas = true;
    }
    else{
        stillHas = false;
    }
} private set;}


public integer listsize {get{
    if(listsize==null){
        listsize = [select Id,name from Account].size();
    }
    return listSize;
}Set;}

public boolean IsBase {get{
    if(offSetLimit == 0){
        IsBase = true;
    }
    else{
        IsBase = false;
    }
} private set;}

Populate rendered attribute of next button with StillHas on the page.

Populate rendered attribute of Previous button with !IsBase on the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.