Sunday, April 5, 2015

Pagination with a Standard List Controller


In Visualforce you can add pagination logic in a visualforce page using a Standard List Controller by helping standard functions of pagination "first", "previous", "next", "last". This page also have a capability to mass update records using Inline Editing Support.


If you create a visualforce page with the following markup:

<apex:page standardController="Account" recordSetVar="accounts" tabstyle="Account">

    <apex:form >

        <apex:pageblock id="customerPageBlock" title="Mass Update Customers">

            <apex:pageblocktable value="{!accounts}" var="acct" id="customerTable">

                <apex:column headerValue="Customer ID">
                    <apex:outputField value="{!acct.Id}"/>
                </apex:column> 
                <apex:column headerValue="Customer Name">
                    <apex:outputField value="{!acct.Name}"/>
                </apex:column> 
                <apex:column headerValue="Industry">
                    <apex:outputField value="{!acct.Industry}"/>
                </apex:column>                             
                <apex:inlineEditSupport event="onClick"/>
            </apex:pageblocktable>

            <center>
                <apex:panelGrid columns="7">
                    <apex:commandButton action="{!quickSave}" value="Save"/>
                    <apex:commandButton action="{!Cancel}" value="Cancel"/>
                    <apex:inputHidden />              
                    <apex:commandButton disabled="{!NOT(hasPrevious)}" action="{!first}" value="First"/>
                    <apex:commandButton disabled="{!NOT(hasPrevious)}" action="{!previous}" value="Previous"/>
                    <apex:commandButton disabled="{!NOT(hasNext)}" action="{!next}" value="Next"/>
                    <apex:commandButton disabled="{!NOT(hasNext)}" action="{!last}" value="Last"/>
                </apex:panelGrid>
            </center>

        </apex:pageblock>
    </apex:form>
</apex:page>








Considerations

  • By default, a standard list controller returns 20 records on the page.
  • To control the number of records displayed on each page, use a controller extension to set the pageSize. See Controller Extensions.