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
VARALAXMI JANGAYVARALAXMI JANGAY 

Sort the values of Custom Setting Data in pageBlockTable

Hi,

Below is the code of custom Setting Data with the sorting the values in the pageBlockTable,
Sort order is not working, Below is my code.
Please can anyone help me,

<apex:page controller="CustomSettingsCon">
    <apex:form>
        <apex:pageBlock id="pageBlock">
             <apex:pageBlockButtons location="top">
      <apex:commandButton value="View" action="{!ViewData}" id="theButton" rerender="pageBlock"></apex:commandButton>
    </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!codes}" var="c" rendered="{!NOT(ISNULL(codes))}" >
             <apex:column >
         <apex:facet name="header">   
           <apex:commandLink action="{!ViewData}" value="Name{!IF(sortExpression=='name',IF(sortDirection='ASC','▼','▲'),'')}" id="cmdSort">
             <apex:param value="name" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
                <apex:outputLink value="/{!c.Id}" target="_blank">{!c.Name}</apex:outputLink>
       </apex:column>
             <apex:column value="{!c.Phone_Number__c}">
         <apex:facet name="header">
           <apex:commandLink action="{!ViewData}" value="Phone_Number__c{!IF(sortExpression=='Phone_Number__c',IF(sortDirection='ASC','▼','▲'),'')}">
             <apex:param value="Phone_Number" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
       </apex:column>
               <apex:column value="{!c.Address__c}">
          <apex:facet name="header">
           <apex:commandLink action="{!ViewData}" value="Address__c{!IF(sortExpression=='Address__c',IF(sortDirection='ASC','▼','▲'),'')}">
             <apex:param value="Address" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
       </apex:column>
                 <apex:column value="{!c.Email__c}">
          <apex:facet name="header">
           <apex:commandLink action="{!ViewData}" value="Email__c{!IF(sortExpression=='Email__c',IF(sortDirection='ASC','▼','▲'),'')}">
             <apex:param value="Email__c" name="column" assignTo="{!sortExpression}" ></apex:param>
           </apex:commandLink>
         </apex:facet>
       </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
===============
public class CustomSettingsCon {
    public List<Account__c> codes{get;set;}
        private String sortDirection = 'ASC';
   private String sortExp = 'name';
   
    public String sortExpression{
   
     get
     {
        return sortExp;
     }
     set
     {
       //if the column is clicked on then switch between Ascending and Descending modes
       if (value == sortExp)
         sortDirection = (sortDirection == 'ASC')? 'DESC' : 'ASC';
       else
         sortDirection = 'ASC';
       sortExp = value;
     }
   }
    
    public String getSortDirection()
 {
    //if not column is selected
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
    else
     return sortDirection;
 }
    
    public void setSortDirection(String value){
   
   sortDirection = value;
 }
 
   public List<Account__c> getcodes(){
       return codes;
   }

    
    public void ViewData(){
           string sortFullExp = sortExpression  + ' ' + sortDirection;
        
       Map<String,Account__c> allcodes = Account__c.getAll();
       codes = allCodes.values();  
    }
}

Thanks,
Varalaxmi
Best Answer chosen by VARALAXMI JANGAY
AvaneeshAvaneesh
Hi VaraLaxmi 

here i post snap of my code use works fine for me 
<apex:pageBlockTable id="list" value="{!storyList}" var="story"  
             width="100%" cellpadding="2" border="1" rendered="{!showTable}">
            <apex:column headerValue="Story Name" width="20%" style="border-right: thin solid grey; ">
                <apex:facet name="header">
                     <apex:commandLink action="{!sort}" value="Story Name{!IF(wikiUTIL_Sorter.column=='Production_deployment_Date__c',IF(wikiUTIL_Sorter.sortDirection='ASC','▼','▲'),'')}">
                        <apex:param value="Estimated_Completion_Date__c" name="column" assignTo="{!wikiUTIL_Sorter.column}" ></apex:param>
                    </apex:commandLink>
                </apex:facet>
                <apex:commandLink value="{!story.Name}" action="{!$Site.Prefix}/WIKI_ViewEpicStory?id={!story.id}&m={!startMonth}&y={!startYear}&n={!selectedNum}&u={!selectedUnit}"><!--{!goViewEpicStoryPage}    {!$Site.Prefix}/WIKI_ViewEpicStory?id={!story.id}&m={!startMonth}&y={!startYear}&n={!selectedNum}&u={!selectedUnit}-->
                    <!--<apex:param name="storyId" value="{!story.id}"/>-->
                </apex:commandLink>
            </apex:column> 
            
            <apex:repeat value="{!months}" var="m">   
                <apex:column width="10%">
                    <apex:facet name="header">
                        <c:WIKI_HeaderValue startDate="{!startDate}" addMonth="{!m}"></c:WIKI_HeaderValue>
                    </apex:facet>
                    <c:WIKI_StatusBar story="{!story}" startDate="{!startDate}" addMonth="{!m}"></c:WIKI_StatusBar>
                </apex:column>
            </apex:repeat>
            
        </apex:pageBlockTable>

and here is the sorting utility class 

 
public class UTIL_Sorter {

    private String column;
    public String sortDirection;
    
    private String defaultSortColumn;
    private String defaultSortDirection;
    
    public final static String SORT_ASC = 'ASC';
    public final static String SORT_DESC = 'DESC';
     
    public UTIL_Sorter(String defaultSortColumn, String defaultSortDirection){
        this.defaultSortColumn = defaultSortColumn;
        this.column = defaultSortColumn;
        this.defaultSortDirection = defaultSortDirection;
        this.sortDirection = defaultSortDirection;
        
    }
    
    public String getSortDirection() {
        return this.sortDirection == null ? defaultSortDirection : this.sortDirection;
    }
    
    public String getColumn() {
        return this.column == null ? defaultSortColumn : this.column;
    }

    public void setColumn(String columnName) {
        if (this.column == null) {
            this.column = columnName;
            sortDirection = defaultSortDirection;
        } else if (column.equalsIgnoreCase(columnName)) {
            sortDirection = (sortDirection.equals(SORT_ASC)) ? SORT_DESC : SORT_ASC;
        } else {
            this.column = columnName;
            sortDirection = defaultSortDirection;
        }
    }
}

if this was helpfull please mark as best answer else let me know ......

Thank you 
Avaneesh Singh