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
DoondiDoondi 

Column sorting and alpha sorting are conflicting

Hi,
I have below code for custom list view
I am using this class as extension 
When column sorting works, the alpha sort doens't work. and vice versa
any anyone tell where I am goinng wrong? 
public class AccountListViewController {
    public static string Selectedview{get;set;}
    private Integer total;
    //column sorting
    private List<Accounting__c> accounts; 
	private String sortDirection = 'ASC';
	private String sortExp = 'name';
	//public static string Selectedview{get;set;}
	public static integer PageSize {get;set;}
	//private Integer total;
	private string inputQuery = 'Select Name, Account_Name__c, Account_Category__c,  Statement_Type__c from Accounting__c ';

	public AccountListViewController(ApexPages.StandardSetController controller ){
		Selectedview='All';
    
	    PageSize = 25;
    	accounts = Database.query(inputQuery + 'limit '+ PageSize);
        }
    //column sorting start
    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;
        System.debug('Hi'+sortExp+' '+sortExp +'!');
    }
}

public String getSortDirection()
 {
    //if not column is selected 
    if (sortExpression == null || sortExpression == '')
      return 'ASC';
     
    else
     return sortDirection;
     
 }

 public void setSortDirection(String value)
 {  
   sortDirection = value;
     system.debug('value'+''+value);
 }
  
   public List<Accounting__c> getAccounts() {
       return accounts;
   }
    
   public PageReference ViewData() {
       //build the full sort expression
       string sortFullExp = sortExpression  + ' ' + sortDirection;
      
       //query the database based on the sort expression
       accounts = Database.query(inputQuery + ' order by ' + sortFullExp + ' limit ' +  PageSize);
       system.debug('srini'+''+'srini');
       return null;
       
   }
    
    public PageReference PageSizeData() {
       PageSize = 25;
        system.debug('pagesize'+''+'pagesize');
       return null;
   }
    public Integer getTotal() {
        total = [SELECT count() FROM Accounting__c]; 
   		system.debug('total');
        return total; }
    //column sorting ending
    
    
list<Accounting__c> acclist = [Select Name, Account_Name__c, Account_Category__c, Statement_Type__c from accounting__c]; 
public list<String> alphabet{
    get{                                                                                                                    //To display a list of alphabets on vf page 
        alphabet = new list<string>{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Others','All'};
            return alphabet;         
            }
    set;
    
} 
public String alphaSearchAcc{get;set;}                                                    // To get commandlink parameter for alphabet selected
public Pagereference getalphaSearch(){                                                              //To update account list as per the alphabet selected by the user

    if (alphaSearchAcc=='All'){
        system.debug('All');
        accList = [Select Name, Account_Name__c, Account_Category__c,  Statement_Type__c from Accounting__c];
    system.debug('acclist');
        
    }
    else{
            accList = [Select Name, Account_Name__c, Account_Category__c,  Statement_Type__c from Accounting__c WHERE Name LIKE :('%' + alphaSearchAcc + '%') ]; 
    system.debug('acclist');
    } 
    ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(accList);
   // stdSetController= ssc;
    return null;
   
}           
}