Visualforce ページネーションのリストへの追加方法
環境
Salesforce
構文
1.apex:commandLink action="{! Previous}"
ページネーションコントロールの <apex:commmandLink> コンポーネントは、
標準リストコントローラー Previous と Next で提供される 2 つのアクションメソッドを参照します。
2.apex:commandLink action="{! Next }"
ページマークアップは標準リストコントローラー HasPrevious と HasNext で提供される Boolean
プロパティを参照しています。
3.apex:selectOption itemvalue="値1″ itemLabel="値2″
<apex:selectOption> 要素を使用してメニューの値を取得します。
4.apex:actionSupport event="onchange" reRender ="contacts_list"
<apex:actionSupport> タグは選択値が変更された場合にメニューのアクションを実行し、 reRender="contacts_list" を使用して <apex:pageBlock> のみを更新します。
操作例
<apex:page standardController="Contact" recordSetVar="contacts">
<apex:form>
<apex:pageBlock title="Contacts List" id="contacts_list">
検索条件:
<apex:selectList value="{! filterId }" size="1">
<apex:selectOptions value="{! listViewOptions }"/>
<apex:actionSupport event="onchange" reRender="contacts_list"/>
</apex:selectList>
<!-- 取引先リストの取得 -->
<apex:pageBlockTable value="{! contacts}" var="cft">
<!--各項目の表示-->
<apex:column value="{! cft.firstname}"/>
<apex:column value="{! cft.lastname}"/>
<apex:column value="{! cft.Email}"/>
<apex:column value="{! cft.Account.Name}"/>
</apex:pageBlockTable>
<!-- ページナビ-->
<table style="width: 100%">
<tr>
<td>
ページ: <apex:outputText value=" {!PageNumber} of {! CEILING(ResultSize / PageSize) }"/>
</td>
<td align="center">
<!-- 前のページ -->
<!-- active -->
<apex:commandLink action="{! Previous }" value="« 前へ" rendered="{! HasPrevious }"/>
<!-- inactive (no earlier pages) -->
<apex:outputText style="color: #ccc;" value="« 次へ" rendered="{! NOT(HasPrevious) }"/>
<!-- 次のページ -->
<!-- active -->
<apex:commandLink action="{! Next }" value="次へ »" rendered="{! HasNext }"/>
<!-- inactive (no more pages) -->
<apex:outputText style="color: #ccc;" value="次へ »" rendered="{! NOT(HasNext) }"/>
</td>
<td align="right">
<!-- Records per page -->
ページあたりのレコード数:
<apex:selectList value="{! PageSize }" size="1">
<apex:selectOption itemValue="5" itemLabel="5"/>
<apex:selectOption itemValue="20" itemLabel="20"/>
<apex:actionSupport event="onchange" reRender="contacts_list"/>
</apex:selectList>
</td>
</tr>
</table>
</apex:pageBlock>
</apex:form>
</apex:page>