3

I was able to create pagination for my table. Now i want to add page number on the bottom of my table(like page number of Total pages ). But i kinda struggle to do that. Anybody have any idea? Thanks

VF Page:

<apex:page standardController="Product_Brief__c" extensions="DispatcherContactNewController">
    <apex:pageBlock >
        <apex:pageBlockTable value="{!pbs}" var="p">
            <tr class="lnkdsble" ><apex:column value="{!p.Name}"/></tr>
            <apex:column value="{!p.RecordTypeId}"/>
            <apex:column value="{!p.Createddate}"/>
            </apex:pageBlockTable> 
        </apex:pageBlock>

        <apex:panelGrid columns="4">
            <apex:commandLink action="{!first}">First</apex:commandlink>
            <apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandlink>
            <apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandlink>
            <apex:commandLink action="{!last}">Last</apex:commandlink>
        </apex:panelGrid>


    </apex:pageBlock>
   </apex:form>
</apex:page>

Extension

public class DispatcherContactNewController {

    public DispatcherContactNewController(ApexPages.StandardController controller) {
        this.controller = controller;
    }

    public ApexPages.StandardSetController setpb {
        get{
            if (setpb == null) {
                setpb = new ApexPages.StandardSetController(Database.getQueryLocator(
                    [SELECT Id, Name, RecordTypeId, Createddate FROM Product_Brief__c])
                                                           );
            }
            return setpb;
        }
        set;
    }

    public List<Product_Brief__c>getpbs() {
        return (List<Product_Brief__c>)setpb.getrecords();
    }

    public Boolean hasNext {
        get {
            return setpb.getHasNext();
        }
        set;
    }

    public Boolean hasPrevious {
        get {
            return setpb.getHasPrevious();
        }
        set;
    }

    public Integer pageNumber {
        get {
            return setpb.getPageNumber();
        }
        set;
    }

    public void first() {
        setpb.first();
    }

    public void last() {
        setpb.last();
    }


    public void previous() {
        setpb.previous();
    }


    public void next() {
        setpb.next();
    }
}
  • 1
    I have an idea and it involves the getPageSize() and getResultSize() methods along with a little math. Where are you stuck? What have you tried? – Mark Pond Jul 1 '15 at 6:48
4

Add following code in your VF page :

<apex:outputText value="Page {!pageNumber} of {!CEILING(ResultSize / PageSize)}" />

where "ResultSize"variable indicates how many records are in the list in total, and "PageSize" indicates the number of records displayed per page.

2

controller....

Public Integer getTotalPages(){
        pages = recNum/recLimit;
        return (Integer)pages.round(System.RoundingMode.CEILING);
    }

// here recNum is total no. of rec and recLimit is no of records to be shown on page

vf......

  apex:outputLabel value=" page {!pageNum} of {!totalPages} " />

// here pageNum is get set integer var.. that is 0 at initialize and pageNum++ on each next call and pageNum-- on each previous button call !!! I hope it helps!!!

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.