0

I have a VF page in which Im displaying set of records in pageblocktable.

There is a dropdown List (Sort By) with values. Name, Program and a commandButton named 'Reverse Order'. So, when I select Name in the dropdown list, the pageblock table should sort By Name, similarly with Program duration. And when I click reverse order button, the order should change.

The reverse order button is working fine. The onchange of SelectList is not working. Below is my code.

VF Page

Sort By                                          
<apex:selectList value="{!sortExpression}" multiselect="false" size="1" onchange="doSearch();return false;" title="Sort By">
       <apex:selectOptions value="{!SortBy}"/>                                                
</apex:selectList>

<apex:commandLink action="{!reverseOrder}" value=" Reverse Order" reRender="pb" status="waitMsg" />    

<apex:actionFunction name="doSearch" action="{!searchStudentsList}" status="waitMsg" reRender="pb"/>

Apex class

public string sortExpression{get;set;}
public string sortDirection{get;set;}

public void ReverseOrder(){     
      sortDirection = (sortDirection =='DESC')? 'ASC' : 'DESC';//changes order by direction
      searchStudentsList();//calls search method
}

public void searchStudentsList(){
   //I use dynamic soql query using sortExpression and sortDirection in the query.
}

public ClassName{
In the constructor
    // Initializing stuff...
    SortBy = new list<SelectOption>();
    SortBy.add(new SelectOption('Name', 'Name'));
    SortBy.add( new SelectOption('Program__c', 'Program'));

    sortExpression = 'Name';
    sortDirection = 'ASC';
}
sfdcFanBoy
  • 4,064
  • 7
  • 43
  • 85

1 Answers1

1

Crazy. The picklist value sorting will be based on how it is setup at the Field level irrespective of what we code. Just read in Salesforce notes.

So, all I had to do was sort the picklist value in Alhabetical order at Field level. All ok now !!

sfdcFanBoy
  • 4,064
  • 7
  • 43
  • 85
  • 1
    please mark as an answer so others will know the issue is resolved – cropredy Aug 10 '14 at 05:48
  • Yes, I couldn't mark it as solved immediately. I had to wait for a day to do it as per the rules. And I forgot the next day. Thanks for the reminder though. Cheers! – sfdcFanBoy Aug 21 '14 at 07:26