Visualforce リストへのリストビューの検索条件の追加方法

環境
Salesforce

構文
1.<apex:selectList value="{! filterId }
{! filterId } を使用して、標準リストコントローラーの結果に使用するリストビュー検索条件を設定します。

2.{! listViewOptions }
{! listViewOptions } を使用して、オブジェクトで使用可能なリストビュー検索条件のリストを取得します。
listViewOptions は、標準リストコントローラーで提供されるプロパティです。

3.apex:actionSupport event="onchange" reRender="contacts_list"
onchange が起動すると、filterId プロパティに新しい項目を送信することで、新しく選択されたリストビューがページから戻され、
<apex:selectList> に設定されます。

操作例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
</apex:pageBlock>
</apex:form>
</apex:page>
<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> </apex:pageBlock> </apex:form> </apex:page>
<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>
    </apex:pageBlock>
    </apex:form>
</apex:page>

 

Salesforce

Posted by arkgame