1

Right now SelectOption is sorting my selection of documents based on the TimeStamp of the document that has been uploaded, but I want to be able to have my list to be same order as what I select and not based on TimeStamp Here Ill try to explain this better.

So I am showing bunch of documents to the user. User will pick the documents in any order they would like. I need to get the same arbitrary order of the pick list that I have in docNames and pass it to BLST list . currently the system is sorting the BLST List based on TimeStamp, but I need it bast on docNames or (User) entry order not timestamp

public List<String> selectedDocuments {get; set;}
for (Document d :documents = [SELECT Id, Name , Body
                         from Document Where (FolderId =: UserInfo.getUserId() OR FolderId =: '00lG0000001bBXb') AND ContentType = 'application/pdf']){
            docNames.add(new SelectOption(d.Id,d.Name));

         }

for (Document d :documents = [SELECT Id, Name , Body
                         from Document Where Id in:selectedDocuments ]){

            BLST.add(Docments)


         }

Component

<apex:inputTextarea id="newDesc" value="{!Name}"/><p/>

            <apex:selectList value= "{!selectedDocuments}" multiselect="true">
                <apex:selectOptions value = "{!docNames}"/>
                </apex:selectList>
            <apex:commandButton action="{!Save}" value="Click" reRender="frm"/>
11
  • 2
    What do you mean by "Same order as what you select"? You are building a select option list here so what are you trying to base your sort on??
    – Eric
    Commented Dec 28, 2015 at 20:02
  • Hi @Eric. I just added some more code. So the I am selecting Document 1 and 2 and 3 out of 5 documents . Document 1 was uploaded before 2 and 3 and so on. so no matter how I am inserting the record document 1 2 and 3 are being inserted based on the timestamp, I cant insert document 3 , 1 , 2 . I need 2,3,1 or 4,2,
    – Metawaa
    Commented Dec 28, 2015 at 20:10
  • 2
    Reading between the lines it sounds like you have a picklist with a bunch of doc names and ids for keys. Then you build a list of actual documents that you do something else with. Then you want the second list to appear in the arbitrary order that someone selects them in? You need to write your question assuming we know nothing, explain your use case, maybe show a mock-up of what you want...I think you have a valid question, you just need to help us help you. :-)
    – pchittum
    Commented Dec 28, 2015 at 21:38
  • Hi @Peter Thank you for reply. I am sorry if the question is too broad. Ill try to rewrite it. but you are absolutely correct. I show a list that the person is picking them in any order I want. I need to my second list to be in the same order is the pick list
    – Metawaa
    Commented Dec 28, 2015 at 21:54
  • @Peter I just edited the question
    – Metawaa
    Commented Dec 28, 2015 at 21:59

1 Answer 1

2

First of all, the VF selectList control has no documentation that says that order of items clicked will be the order of items presented in the corresponding controller's list variable.

As such, I can think of two alternatives and others may have additional suggestions

Option 1 Don't use the multi-select picklist

A more predictable-to-the-user interface might be one where the order of items to be presented is done through a drag-drop interface such as in jQuery UI sortable widget, Or, there's always the Netflix DVD Queue user interface where items to be ordered are given an entry box where the user can enter integers representing delivery order (yes, I'm old enough to remember DVDs on demand). It is hard to imagine that without some user feedback how click order actually commits the user to some resulting action sequence.

Option2 - Use a more powerful multi-select control like Chosen or Select2.

Some examples of this are covered in Stackoverflow. I've used these before (although not to retain click order) and they provide a nifty, space-saving multi-select picklist control - especially as compared to the OOB VF apex:inputField

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .