function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anji P 9Anji P 9 

{!controller.pagenumber}  of  {!controller.resultsize} i'm getting o/p like 1 of 47 but i want 1-10 of 47

apex code:--

public class Pagination_Example {
    public Apexpages.StandardSetController controller {set;get;}
    public List<Opportunity> getOptyList(){
        List<Opportunity> opty=(List<Opportunity>)controller.getRecords();
        return opty;
    }
    public Pagination_Example (){
       List<opportunity> opps=[select id,name,stagename,amount from opportunity];
      controller=new apexpages.standardsetcontroller(opps);
        controller.setpagesize(10);
    }
    
}

vf page:--

<apex:page controller="Pagination_Example">
    <apex:form >
       <apex:pageblock id="pb">
        <apex:pageblockbuttons location="top">
        <apex:commandButton value="Previous" action="{!controller.previous}" rendered="{!controller.hasprevious}"/>
        <apex:commandButton value="First" action="{!controller.first}" rendered="{!controller.hasprevious}"/>
        <apex:commandButton value="Next" action="{!controller.Next}" rendered="{!controller.hasnext}"/>
        <apex:commandButton value="Last" action="{!controller.last}" rendered="{!controller.hasnext}"/>
        </apex:pageblockbuttons>
           <apex:pageBlockTable value="{!optylist}" var="a">
               <apex:column value="{!a.name}"/>
               <apex:column value="{!a.stagename}"/>
               <apex:column value="{!a.amount}"/>
           </apex:pageBlockTable>
           <apex:facet name="footer"> <h1>
            {!controller.pagenumber}&nbsp;&nbsp;of&nbsp;&nbsp;{!controller.resultsize}
         
               </h1>
           </apex:facet>
           </apex:pageblock>
    </apex:form>
</apex:page>
Best Answer chosen by Anji P 9
Anji P 9Anji P 9
thanks maharajan c its working fine 

All Answers

Maharajan CMaharajan C
Hi Anji,

Please use the below Code i.e small changes in your code that will work!!!

Apex Code:

public class Pagination_Example {
Public Integer resultsize{get;set;}
Public Integer size{get;set;}
    public Apexpages.StandardSetController controller {set;get;}
    public List<Opportunity> getOptyList(){
        List<Opportunity> opty=(List<Opportunity>)controller.getRecords();
        return opty;
    }
    public Pagination_Example (){
    size=10;
       List<opportunity> opps=[select id,name,stagename,amount from opportunity];
       resultsize=opps.size();
       controller=new apexpages.standardsetcontroller(opps);
        controller.setpagesize(size);
    }
    
}

Visualforce Page:

<apex:page controller="Pagination_Example">
    <apex:form >
       <apex:pageblock id="pb">
        <apex:pageblockbuttons location="top">
        <apex:commandButton value="Previous" action="{!controller.previous}" rendered="{!controller.hasprevious}"/>
        <apex:commandButton value="First" action="{!controller.first}" rendered="{!controller.hasprevious}"/>
        <apex:commandButton value="Next" action="{!controller.Next}" rendered="{!controller.hasnext}"/>
        <apex:commandButton value="Last" action="{!controller.last}" rendered="{!controller.hasnext}"/>
        </apex:pageblockbuttons>
           <apex:pageBlockTable value="{!optylist}" var="a">
               <apex:column value="{!a.name}"/>
               <apex:column value="{!a.stagename}"/>
               <apex:column value="{!a.amount}"/>
           </apex:pageBlockTable>
           <apex:facet name="footer"> <h1>
           {!(controller.pageNumber * size)+1-size}-{!IF((controller.pageNumber * size)>resultsize, resultsize,
                     (controller.pageNumber * size))} of {!resultsize}
                 </h1>    
           </apex:facet>        
           </apex:pageblock>
    </apex:form>
</apex:page>

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
​Raj
Anji P 9Anji P 9
thanks maharajan c its working fine 
This was selected as the best answer
Maharajan CMaharajan C
Thanks Anji choose your answer as a best answer great reward to my help!!! LOL!!! please choose the answer which one helps to you it will increase our points!!!