function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Adding a filter to a Blocktable in Visualforce page

This is a follow up to a challenge I had yesterday.
I have a created a "General Landing Page" for a user. There are two links at the bottom of the page, depending on what "track" they want to follow.
I have a VF page for one track and a VF page for the other track. Both VF pages are pulling data from the same Custom Object "Guidance University". That object is where the Marketing dept. will add all the Videos for the different tracks. There is a picklist field on the object with either a Sales Certification Track or an Engineer Certification Track.
When the user clicks a specific track, I need the BlockTable to display only the Videos that are associated with that specific track.
Here is the code I have now, without the filter...

<apex:page standardController="Guidance_University__c" recordSetVar="Guidance_University__c" sidebar="false">
    <h1> Welcome to the Guidance University Sales Certification Courses </h1>
            <apex:pageBlock title="Guidance University Sales Certification Training Videos">
                     <apex:pageBlockTable value="{!Guidance_University__c}" var="a">
                            <apex:column value="{!}"/>
                            <apex:column value="{!a.Course_Code_v2__c}"/>
                             <apex:column value="{!a.Course_Level__c}"/>
                             <apex:column value="{!a.Topic_Subject__c}"/>
                              <apex:column value="{!a.Video_Link__c}"/>
William TranWilliam Tran
Videos that are associated with that specific track --> what variable determines this?

Where do they choose the track? dropdown? checkboxes? radio buttons? what?

All the columns are the same? just the records displayed are different?

It's recommended that you create method in your controller/extension to return your filtered list.

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you. 

Hi William,
There is a field called "Course Track". It's a pick list, and so the filter would need to look at this field before it listed the records in the DataTable.

William TranWilliam Tran
So create an extensions = "GuidanceController"

Create a public variable to return the FilteredList

Do an action support on the dropdown
<apex:actionSupport event="onclick" action="{!displayCourseTrackFilters}"/>

Create the method:  displayCourseTrackFilters - to set the FilteredList variable accordingly.

The Apex page should be 

 <apex:pageBlockTable value="{!FilteredList}" var="a">

Hey William,
Thank you very much. I am very new and just learning how to code. I have no idea what you answer means, could you please break it down for me a little more? I am really sorry, I'm not trying to be difficult, and coming from a purely SFDC Admin. position for 5 years, coding can be difficult.
Do I need to create an APEX Class (Custom Controler) or do I just need to drop that last line of code ( <apex:pageBlockTable value="{!FilteredList}" var="a">) into my VF page code somewhere.
Again, I'm very sorry for being such a pain.