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';
}
7
  • 2
    I suggest you narrow down the problem area by using the techniques in How do I start to debug my own Visualforce/JavaScript?.
    – Keith C
    Commented Jun 9, 2014 at 10:28
  • "pb" is definitely the Id of an outer element?
    – Ray Dehler
    Commented Jun 9, 2014 at 16:18
  • well just to confirm do you have any required feel in the page (doesn't look like you have else reverse order shouldn't be working). and does the actionstatus fire ?
    – Avidev9
    Commented Jun 9, 2014 at 16:38
  • @RayDehler yes, pb is the outer element. Commented Jun 9, 2014 at 23:40
  • @Avidev9 I do not have any required fields. hmm I need to verify if the "onchange" of the selectList is working or not. how? Commented Jun 9, 2014 at 23:42

1 Answer 1

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 !!

2
  • 1
    please mark as an answer so others will know the issue is resolved
    – cropredy
    Commented Aug 10, 2014 at 5: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! Commented Aug 21, 2014 at 7:26

You must log in to answer this question.

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