Is there a way to group options in an apex:selectList
I have in my page
<apex:selectList styleclass="form-control rec" size="1" id="country" >
<apex:selectOption itemValue="" itemLabel="--Please Select--"/>
<apex:selectOptions value="{!CountryName}" />
<apex:actionSupport event="onchange" reRender=""/>
</apex:selectList>
In the controller I have
public List<SelectOption> getCountryName(){
List<SelectOption> options = new List<SelectOption>();
for(Country__c con :[select Id,Name from Country__c where Region__c=:'Americas' order by Name]){
options.add(new SelectOption(con.Name,con.Name));
}
Is there a way I can group the selectOptions based on region like with a grouping label
similar to html <optgroup label="Americas">
Also is it possible to do something like the below code in case I'm not able to group them using salesforce
<select id="country" >
<option value="">--Please Select--</option>
<optgroup label="Americas">
<apex:selectOptions value="{!CountryName}" />
</optgroup>
</select>