Newer Version Available
Using List Views with Standard List Controllers
Many Salesforce pages include list views that allow you to filter the records displayed on the page. For example, on the opportunities home page, you can choose to view a list of only the opportunities you own by selecting My Opportunities from the list view drop-down. On a page that is associated with a list controller, you can also use list views.
1<apex:page standardController="Account" recordSetvar="accounts">
2 <apex:pageBlock title="Viewing Accounts">
3 <apex:form id="theForm">
4 <apex:panelGrid columns="2">
5 <apex:outputLabel value="View:"/>
6 <apex:selectList value="{!filterId}" size="1">
7 <apex:actionSupport event="onchange" rerender="list"/>
8 <apex:selectOptions value="{!listviewoptions}"/>
9 </apex:selectList>
10 </apex:panelGrid>
11 <apex:pageBlockSection >
12 <apex:dataList var="a" value="{!accounts}" id="list">
13 {!a.name}
14 </apex:dataList>
15 </apex:pageBlockSection>
16 </apex:form>
17 </apex:pageBlock>
18</apex:page>When you open that page, you'll see something like the following:
This page is associated with the standard account controller and the <apex:selectlist> component is populated by {!listviewoptions}, which evaluates to the list views the user can see. When the user chooses a value from the drop-down list, it is bound to the filterId property for the controller. When the filterId is changed, the records available to the page changes, so, when the <apex:datalist> is updated, that value is used to update the list of records available to the page.
1<apex:page standardController="Opportunity" recordSetVar="opportunities"
2 tabStyle="Opportunity"
3 sidebar="false">
4 <apex:form>
5 <apex:pageBlock>
6 <apex:pageMessages/>
7 <apex:pageBlock>
8 <apex:panelGrid columns="2">
9 <apex:outputLabel value="View:"/>
10 <apex:selectList value="{!filterId}" size="1">
11 <apex:actionSupport event="onchange" rerender="opp_table"/>
12 <apex:selectOptions value="{!listviewoptions}"/>
13 </apex:selectList>
14 </apex:panelGrid>
15 </apex:pageBlock>
16
17 <apex:pageBlockButtons>
18 <apex:commandButton value="Save" action="{!save}"/>
19 </apex:pageBlockButtons>
20 <apex:pageBlockTable value="{!opportunities}" var="opp" id="opp_table">
21 <apex:column value="{!opp.name}"/>
22 <apex:column headerValue="Stage">
23 <apex:inputField value="{!opp.stageName}"/>
24 </apex:column>
25 <apex:column headerValue="Close Date">
26 <apex:inputField value="{!opp.closeDate}"/>
27 </apex:column>
28 </apex:pageBlockTable>
29 </apex:pageBlock>
30 </apex:form>
31</apex:page>