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';
}