1

On a vf page i have a picklist. Values are-- ABC, XYZ, PQR and Other. can we have the list in Alphabetical order with "Other" the last option.

I have sorted Picklist when defining it. But i want other to always be last options in picklist

5

Sort the list before adding "other", then add "other".

SelectOption[] options = new SelectOption[0];

for(...) {
    options.add(new SelectOption(value, label));
}

options.sort();
options.add(new SelectOption('-- other --', 'Other'));
return options;

Or, you can embed "other" directly into the list, forcing it to be last:

<apex:selectList ...>
    <apex:selectOptions value="{!myOptions}"/>
    <apex:selectOption itemValue="-- other --" itemLabel="Other"/>
</apex:selectList>
  • How if i am using an input Field. Because this code i have to write it for each and every picklist on vf page. I have 10 picklist on the page.. All picklist has other options – TestNS Dec 9 '13 at 7:00
  • I used the 1st set of code for the picklist values comng from apex class.. It worked charms – TestNS Dec 9 '13 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.