- <apex:page controller="multiRow" tabStyle="Contact">
- <apex:form id="accountForm" >
- <apex:pageMessages />
- <apex:pageBlock title="Search Results" >
- <apex:pageBlockButtons >
- <apex:outputPanel rendered="{!totalPages > 1}" >
- <table border="0" style="width:100%; text-align: right">
- <tr>
- <td style="width:100%"> </td>
- <td style="vertical-align: middle">
- <apex:actionStatus id="statusPaging">
- <apex:facet name="start">
- <apex:outputPanel >Please wait...</apex:outputPanel>
- </apex:facet>
- <apex:facet name="stop" />
- </apex:actionStatus>
- </td>
- <td style="text-align: center; white-space: nowrap">
- <b>Page:</b><br/>{!contactsSetController.PageNumber} of {!totalPages}
- </td>
- <td style="vertical-align: middle">
- <apex:commandButton value="|<" action="{!contactsSetController.First}"
- disabled="{!Not(contactsSetController.HasPrevious)}" rerender="accountForm" status="statusPaging"/>
- </td>
- <td style="vertical-align: middle">
- <apex:commandButton value="<" action="{!contactsSetController.Previous}"
- disabled="{!Not(contactsSetController.HasPrevious)}" rerender="accountForm" status="statusPaging"/>
- </td>
- <td style="vertical-align: middle">
- <apex:commandButton value=">" action="{!contactsSetController.Next}"
- disabled="{!Not(contactsSetController.HasNext)}" rerender="accountForm" status="statusPaging"/>
- </td>
- <td style="vertical-align: middle">
- <apex:commandButton value=">|" action="{!contactsSetController.Last}"
- disabled="{!Not(contactsSetController.HasNext)}" rerender="accountForm" status="statusPaging"/>
- </td>
- </tr>
- </table>
- </apex:outputPanel>
- </apex:pageBlockButtons>
-
- <apex:pageBlockTable value="{!Contacts}" var="contact" >
- <apex:column headerValue="Name">
- <apex:outputLink value="/{!contact.id}" id="contactLink">{!contact.name}</apex:outputLink>
- </apex:column>
- <apex:column value="{!contact.FirstName}"/>
- <apex:column value="{!contact.LastName}"/>
- </apex:pageBlockTable>
- </apex:pageBlock>
- </apex:form>
- </apex:page>
----------------------------------------------------------------------------------------------------
- public class multiRow {
- public Integer totalPages { get; set; }
- public ApexPages.StandardSetController contactsSetController { get; set; }
- public List<Contact> Contacts {
- get {
- return (List<Contact>) contactsSetController.getRecords();
- }
- }
-
- public multiRow () {
- Decimal dtotalPages;
- Integer iRecordsPerPage = 5;
- Database.QueryLocator qLoc;
-
- // You can initialize the set controller using a SOQL query:
- qLoc = Database.getQueryLocator([Select Id, Name, AccountId, FirstName, LastName From Contact c]);
- contactsSetController = new ApexPages.StandardSetController(qLoc);
-
- // Or with a list of records, which is useful for SOSL searches or if you already have the records in a list.
- // List<Sobject> lContacts = [FIND 'smith*' IN ALL FIELDS RETURNING Contact (Id, Name, AccountId, FirstName, LastName )][0];
- // contactsSetController = new ApexPages.StandardSetController(lContacts);
-
- // Create the set controller
-
- // Set the number of records to be displayed per page and calculate the number of pages.
- contactsSetController.setPageSize(iRecordsPerPage);
- dtotalPages = (contactsSetController.getResultSize() / contactsSetController.getPageSize());
- dtotalPages = Math.floor(dtotalPages) + ((Math.mod(contactsSetController.getResultSize(), iRecordsPerPage)>0) ? 1 : 0);
- totalPages = Integer.valueOf(dtotalPages);
- }
- }
No comments:
Post a Comment