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
Cory CowgillCory Cowgill 

StandardSetController getSelected() - How can I retain Sort Order from List View?

I have a controller extension for a list view.

 

The user selects a subset of the items in the list and clicks a button that goes to my custom VF Page.

 

I want to retain the order they were selected in the list from top to bottom. So if Selected Item A is before Selected Item B when the button is clicked, that is the order I WANT them passed to the controller.

 

However, the method getSelected() on the StandardSetController does not return the items in a sorted list the same as the screen.

 

Does anyone know how to keep the selected items sorted from the previous pages list view?

rsoesemannrsoesemann

Hy Cory,

 

have you found an answer to your question? I am struggling with selection in StandardSetController-managed PageBlockTables for weeks.

 

My currently unanswered post is here:

http://boards.developerforce.com/t5/Visualforce-Development/Select-rows-in-PageBlockTable-when-using-ApexPages/m-p/387199

 

Best regards

 

Rsoese

rsoesemannrsoesemann

Hy Cory,

 

have you ever tried to use a Map instead of Wrapper classes when it comes to selecting rows of a StandardSetController? Something like this:

 

Controller:
...
 public Map<Id, Boolean> isSelected {
        get {
            if(isSelected.get(recordSet.getRecords().get(0).Id) == null) {
                for(SObject so : recordSet.getRecords()) {
                    isSelected.put(so.Id, false);
                }
            }
            return isSelected;
        }
        set;
    }
...

Page:
<apex:pageBlockTable value="{!recordSet.records}" var="record" id="table"> <apex:column> <apex:inputCheckbox value="{!isSelected[record.Id]}" /> </apex:column> <apex:repeat value="{!fieldsToDisplay}" var="fieldName"> <apex:column> <apex:inputField value="{!record[fieldName.value]}" /> </apex:column> </apex:repeat>

 

craigmhcraigmh

That's odd, the getSelected() method returns a list of sObjects, which should be ordered...maybe it's generating a second list that doesn't preserve the same order?

Nitish Bansal 46Nitish Bansal 46
Anybody managed to get a solution for this one?
Joseph DindingerJoseph Dindinger
Please upvote my idea if this affects you as well.  https://success.salesforce.com/ideaView?id=0873A000000lFRxQAM
Paul Redmond 7Paul Redmond 7
I too am trying to figure this out.  You'd assume it would just retain the sort order. 

Does anyone know how to capture the current list views sort order?  If I could do that then just apply it to the selected collection set.