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
sonaperthsonaperth 

[help] visualforce page for searching and filtering

hi guys, i need some help.

im trying to make a visualforce page that can do filtering and searching.

 

the interface looks like this:

 

 

 

can anyone tell me how to create the 'Location' picklist at the top to filter the list, and how to pass the picklist value into the controller?

or maybe a link or an article or something that i can read to solve this?

 

it should filter the list to just show classes that taking place in that location.

i made it using apex:inputField to make the screenshot, and im confuse on how to pass the value into controller.

 

the values inside the picklist should have the same value with the 'Location' field, as 'Location' field is using Picklist as Datatype.

 

and im planning to just rerender the 'Data' pageBlock rather than rerender the whole page.

 

any help would be greatly appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Is your page backed by an sObject, or is it just capturing filtering criteria and executing the search?

 

If the latter, you won't be able to use and inputField, as these must be backed by a field from an object.

 

 

You can use  a SelectOption component in the page to generate this.  You will need to use a nested selectOptions to hold the actual options that appear, and provide a controller method to back this.

 

You can then use a String property from your controller as the value attribute for the SelectOption, which will allow you to capture the user's selection.

 

 

The Standard Component Reference of the VisualForce Developer's Guide has examples of using this.

 

Turning picklist values into select options can be done as follows:

 

 

List<SelectOption> myOptions=new List<SelectOption>(); Schema.DescribeFieldResult fieldDesc = MyObject__c.getDescribe(); List<Schema.PicklistEntry> plEntries = fieldDesc.getPicklistValues(); for (Schema.PickListEntry plEntry : plEntries) { SelectOption option=new SelectOption(plEntry.getValue(), plEntry.getLabel()); myOptions.add(option); }

 

 

 

All Answers

bob_buzzardbob_buzzard

Is your page backed by an sObject, or is it just capturing filtering criteria and executing the search?

 

If the latter, you won't be able to use and inputField, as these must be backed by a field from an object.

 

 

You can use  a SelectOption component in the page to generate this.  You will need to use a nested selectOptions to hold the actual options that appear, and provide a controller method to back this.

 

You can then use a String property from your controller as the value attribute for the SelectOption, which will allow you to capture the user's selection.

 

 

The Standard Component Reference of the VisualForce Developer's Guide has examples of using this.

 

Turning picklist values into select options can be done as follows:

 

 

List<SelectOption> myOptions=new List<SelectOption>(); Schema.DescribeFieldResult fieldDesc = MyObject__c.getDescribe(); List<Schema.PicklistEntry> plEntries = fieldDesc.getPicklistValues(); for (Schema.PickListEntry plEntry : plEntries) { SelectOption option=new SelectOption(plEntry.getValue(), plEntry.getLabel()); myOptions.add(option); }

 

 

 

This was selected as the best answer
sonaperthsonaperth

it works!

thank you bery much bob!  :)