This would definitely have to be custom. To do this, you would need to repeat over a List<SelectOption>
using an <apex:repeat>
to generate out a list of <apex:selectOption>
while inside an <apex:selectList>
. Unfortunately, <apex:selectOption>
had style and styleClass deprecated in API 17, so the only way to apply the proper formatting is by injecting HTML into the value and ensuring the HTML is not escpaed (which it should not be by default). Now, for this, you can either do this as part of your Visualforce or do this in your controller. If you do this in your controller, you can just use the <apex:selectOptions>
. I would probably do it as part of the controller since it would be a bit easier.
...
public List<SelectOption> getOptions(){
List<SelectOption> options = new List<SelectOption>();
options.add(1, '<span style="font-weight:bold;">Value 1 bucket</span>');
options.add(2, 'Value 1.0');
options.add(3, 'Value 1.1');
options.add(4, '<span style="font-weight:bold;">Value 2 bucket</span>');
options.add(5, 'Value 2.0');
options.add(6, 'Value 2.1');
return options;
}
...
...
<apex:selectList multiselect="true" size="4">
<apex:selectOptions value="{!options}"/>
</apex:selectList>
...
With all of that said, I would suggest maybe considering a dependent picklist. Allow your users to select the grouping as one picklist and then only display their available options based on that selection in a multi-picklist after their selection. This will bypass custom coding a solution.