+ Start a Discussion
Chitral ChaddaChitral Chadda 

pagination code

<apex:page controller="Pagination_min">
    <apex:form >
        <apex:pageBlock id="pb">
            <apex:pageBlockTable value="{!Accounts}" var="a">
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Type}"/>
                <apex:column value="{!a.BillingCity}"/>
                <apex:column value="{!a.BillingState}"/>
                <apex:column value="{!a.BillingCountry}"/>
            </apex:pageBlockTable>
            <apex:panelGrid columns="7">
                <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/>
                <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/>
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}   -    {!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>
                <apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
                <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                    <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
                </apex:outputPanel>
            </apex:panelGrid>
        </apex:pageBlock>
    </apex:form>
</apex:page>


class



public  class Pagination_min {
    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}
    public ApexPages.StandardSetController setCon {
        get{
            if(setCon == null){
                size = 10;
                string queryString = 'Select Name, Type, BillingCity, BillingState, BillingCountry from Account order by Name';
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();
            }
            return setCon;
        }set;
    }
    
    Public List<Account> getAccounts(){
        List<Account> accList = new List<Account>();
        for(Account a : (List<Account>)setCon.getRecords())
            accList.add(a);
        return accList;
    }
    
    public pageReference refresh() {
        setCon = null;
        getAccounts();
        setCon.setPageNumber(1);
        return null;
    }
}

i cant undstnd the bold part in the code also

<apex:outputText >{!(setCon.pageNumber * size)+1-size}   -    {!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>

i cudnt get the logic  also in the class  i fail to undsth the bold part

Best Answer chosen by Chitral Chadda
Grazitti TeamGrazitti Team
Hi,

Please see the below links which will be helpful to understand the code of pagination.

https://developer.salesforce.com/page/Paginating_Data_for_Force.com_Applications

https://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_standardsetcontroller.htm (https://developer.salesforce.com/page/Paginating_Data_for_Force.com_Applications)

Please mark as best answer if it solves your problem.

Regards,
Grazitti Team,
www.grazitti.com


All Answers

Grazitti TeamGrazitti Team
Hi,

Please see the below links which will be helpful to understand the code of pagination.

https://developer.salesforce.com/page/Paginating_Data_for_Force.com_Applications

https://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_standardsetcontroller.htm (https://developer.salesforce.com/page/Paginating_Data_for_Force.com_Applications)

Please mark as best answer if it solves your problem.

Regards,
Grazitti Team,
www.grazitti.com


This was selected as the best answer
Chitral ChaddaChitral Chadda
@grazitti
thanks a lot



public ApexPages.StandardSetController setCon{}

setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));

m unable to undstnd these two lines can u pls xplain them and what it means wd querylocator
Grazitti TeamGrazitti Team
Please see the links below which will be helpful to understand the above lines.

https://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_standardsetcontroller.htm
(Give information about "ApexPages.StandardSetController" class)

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_database.htm
(Give information about "Database.getQueryLocator()" function)

Regards,
Grazitti Team,
www.grazitti.com
Ravikant kediaRavikant kedia
Please read here https://developer.salesforce.com/page/Paginating_Data_for_Force.com_Applications
Chitral ChaddaChitral Chadda
@grazitti

what i cud undstng regarding  ApexPages.StandardSetController

i think is that , it divides the record into chunks and perform operation on it  considering the whole record as ONE



thnku