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
Agent Comms 7Agent Comms 7 

in my pagination i want navigate to any page by entering page number

Hi All,
I have created a Vf with  pagination , I want to show page number (Current Page Number/Total Page Numbers) ,so User should be able to navigate to any page by entering page number, 
here is my code..

vf page..

<apex:page controller="LeadPaginate" > <apex:pageMessages ></apex:pageMessages> <apex:pageBlock title="Hello !"> Here is your Document Lead List </apex:pageBlock> <apex:form id="myform"> <apex:pageblock id="pbId" > <apex:pageBlockSection columns="1" > <apex:pageblock > <apex:pageblockButtons location="Top"> <apex:commandButton value="Processed" action="{!clickMe}" /> </apex:pageblockButtons> <div align="right" id="div1"> <apex:outputPanel rendered="{!Setcon.hasPrevious}"> <apex:commandLink id="diableanchor" value="Previous" action="{!Setcon.Previous}" reRender="myform" /> &nbsp; &nbsp; </apex:outputPanel> <apex:outputPanel rendered="{!NOT(Setcon.hasPrevious)}" > <apex:commandLink id="diableanchor1" value="Previous" reRender="myform" style="color: #555555; cursor: default; text-decoration: none;"/> &nbsp; &nbsp; </apex:outputPanel> <apex:outputPanel rendered="{!Setcon.hasNext}"> <apex:commandLink value="Next" action="{!Setcon.Next}" reRender="myform" /> </apex:outputPanel> <apex:outputPanel rendered="{!NOT(Setcon.hasNext)}"> <apex:commandLink value="Next" reRender="myform" style="color: #555555; cursor: default; text-decoration: none;"/> </apex:outputPanel> </div> <apex:pageblocktable value="{!Contact}" var="cc" id="test" > <apex:column headerValue=""> <apex:inputCheckbox value="{!cc.bool}"/> </apex:column> <apex:column value="{!cc.con.Name}"/> <apex:column value="{!cc.con.Approval_Status__c }"/> </apex:pageblocktable> <apex:pageBlockButtons location="Bottom"> </apex:pageBlockButtons> <div align="right" id="div1"> <apex:outputPanel rendered="{!Setcon.hasPrevious}"> <apex:commandLink id="diableanchor2" value="Previous" action="{!Setcon.Previous}" reRender="myform" /> &nbsp; &nbsp; </apex:outputPanel> <apex:outputPanel rendered="{!NOT(Setcon.hasPrevious)}" > <apex:commandLink id="diableanchor3" value="Previous" reRender="myform" style="color: #555555; cursor: default; text-decoration: none;"/> &nbsp; &nbsp; </apex:outputPanel> <apex:outputPanel rendered="{!Setcon.hasNext}"> <apex:commandLink value="Next" action="{!Setcon.Next}" reRender="myform" /> </apex:outputPanel> <apex:outputPanel rendered="{!NOT(Setcon.hasNext)}"> <apex:commandLink value="Next" reRender="myform" style="color: #555555; cursor: default; text-decoration: none;"/> </apex:outputPanel> </div> <apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="pbId"/> <apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();"> <apex:selectOptions value="{!ContactsTables}"/> </apex:selectList> <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText> </apex:pageblock> <apex:pageBlock > <apex:outputPanel rendered="{!display}"> <apex:pageblocktable value="{!selectedList}" var="w" columns="2" > <apex:column value="{!w.Name}"/> <apex:column value="{!w.Approval_Status__c }"/> </apex:pageblocktable> </apex:outputPanel> </apex:pageblock> </apex:pageBlockSection> </apex:pageblock> </apex:form> </apex:page>

controller...

Public class LeadPaginate{
 
    public Integer size { get; set; }
    Public List<WrapperContactWrapper> wrapperlist;
    Public Integer noOfRecords{get; set;}
    Map <id,Lead> SelectedcontactMap = new Map <id,Lead>();
    public boolean display{get;set;}
    public list<Lead> selectedList {get;set;}
    public List<SelectOption> ContactsTables{get;set;}
 
    Public class WrapperContactWrapper {
        Public Lead con{get;set;}
        Public boolean bool{get;set;}
        public WrapperContactWrapper(Lead c,boolean bool) {
            this.con = c; 
            this.bool = bool;
        }
    }
    public LeadPaginate(){
        size=3;

        ContactsTables= new List<SelectOption>();
        
        ContactsTables.add(new SelectOption('10','10'));
        ContactsTables.add(new SelectOption('20','20'));

        ContactsTables.add(new SelectOption('50','50'));

        ContactsTables.add(new SelectOption('100','100'));
        ContactsTables.add(new SelectOption('200','200'));

    }
 public ApexPages.StandardSetController Setcon {
        get { if(Setcon == Null) {
            Setcon = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id , Name,CreatedDate,Approval_Status__c  from Lead where Approval_Status__c = 'Approved' limit 100 ]));
     
            setCon.setpagesize(size);
            noOfRecords = setCon.getResultSize(); }
            return Setcon;
        }
        set;
    }
    public PageReference refreshPageSize() {
         Setcon.setPageSize(size);
         return null;
    }
   Public List<WrapperContactWrapper> getContact() {
        getSelectedContact();
        wrapperlist = new List <WrapperContactWrapper>();
         
        for(Lead cc : (List<Lead>)Setcon.getRecords()) {
            if( SelectedcontactMap .ContainsKey(cc.id)) {
                wrapperlist.add (new WrapperContactWrapper(cc,true));
            } else {
            wrapperlist.add(new WrapperContactWrapper(cc,false));
            }
        }
        return wrapperlist;
    }
     
    public void getSelectedContact(){
        if(wrapperlist!=null) {
            for(WrapperContactWrapper wr:wrapperlist) {
                if(wr.bool == true) {
                    SelectedcontactMap.put(wr.con.id,wr.con);
                } else {
                    SelectedcontactMap.remove(wr.con.id);     
                }     
            }
       }
    }
    
    public void clickMe() {
        display = true;
        getSelectedContact();
        selectedList = SelectedcontactMap.values();
        wrapperlist = null;
        SelectedcontactMap.clear();
        getContact();
}
     
    public integer pageNumber {
        get {
            return Setcon.getPageNumber();
        }
        set;
    }
    
}

please give me some solution,
James LoghryJames Loghry
You'll want to add some sort of input text or select list to your visualforce pages for displaying all the available pages.  If you're implementing this as a select list, then you'll want to generate the select options by calculating the number of pages.  Unfortunately, I don't see any "getNumberOfPages" method in the standard set controller, but you can calculate it with something:
 
Math.ceil(setCon.getResultSize() / setCon.getPageSize())

Then, with a for loop, generate the proper selectOptions.

Next, when the input changes, you'll want to fire an action (e.g. using the apex:actionFunction element) that calls the a PageReference method with:
 
setCon.setPageNumber(yourSelectedPageNumVariableGoesHere);

You can find more on the standard set controller methods here: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_ApexPages_StandardSetController_methods.htm
James LoghryJames Loghry
Also, when you post code on these forums, please use the code formatting button (< >).  Thanks!
Suraj Tripathi 47Suraj Tripathi 47
Hi Agent Comms 7,

Check the below link, in that you will get reference how to navigate to page number dynamically using actionFunction.

Go through this link, it may help you:
https://redpointcrm.com/add-pagination-using-dynamic-visualforce-components-and-soql-offset/

If you find your Solution then mark this as the best answer.

Thank you!

Regards,
Suraj Tripathi