+ Start a Discussion
Mohan Raj 33Mohan Raj 33 

Pagination and sorting not worked together

I have the code to be provide the output like the accountList view as in the developer org.But in here the pagination and the sorting is to be not working together.it's working here the vise versa . here mt code is followingly,
My controller:
public class AccountListViewController{
public List<Account> AccountsortList {get; set;}
public String SortingExpression = 'name';
public String DirectionOfSort = 'ASC';
public Integer NoOfRecords {get; set;}
public Integer Size{get; set;}

    public AccountListViewController(ApexPages.StandardSetController controller) {
        AccountsortList = new List<Account>();
        ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(AccountsortList);
        
    }
    
    /*public Integer pageNumber {
        get {
        return ssc.getpageNumber();
        }
        set;
    }*/
    public String ExpressionSort {
        get {
            return SortingExpression;
        }
        set {
            If(value == SortingExpression) {
                DirectionOfSort = (DirectionOfSort == 'ASC')? 'DESC' : 'ASC';
            }
            else {
                DirectionOfSort = 'ASC';
                SortingExpression = value;
            }
        }
    
    }
    
    public String getDirectionOfSort() {
        If(SortingExpression == Null || SortingExpression == '') {
            return 'DESC';
        }
        else {
            return DirectionOfSort;
        }
    }
    
    public void setDirectionOfSort(String value) {
        DirectionOfSort = value;
    }
    
    public List<Account>getAccounts() {
        return AccountsortList;
    }
    
     public PageReference ViewData() {
        String FullSortExpression = SortingExpression + ' ' + DirectionOfSort;
        system.debug('SortingExpression:::::'+SortingExpression);
        system.debug(DirectionOfSort);
        
       String Queryitem = ' SELECT Id, Name, Phone, BillingState, Type, Owner.Name, Website FROM Account WHERE Account.Name != Null ORDER BY ' + FullSortExpression +' Limit 1000';
       system.debug(Queryitem);
       
        AccountsortList = DataBase.query(Queryitem);
        system.debug(AccountsortList);
        return Null;
    }
}

and My page is:
<apex:page standardController="Account" recordSetVar="AccountsortList" action="{!ViewData}" extensions="AccountListViewController">

<apex:sectionHeader title="My Accounts" subtitle="Account List View"/>
    <apex:form >
        <apex:pageBlock >
          <apex:pageMessages id="error" />
          
           <apex:panelGrid columns="7" id="buttons" >
           <!---<apex:pageBlockButtons>---->
                <apex:commandButton reRender="error,blocktable,buttons" action="{!Save}" value="Save"/>
                <apex:commandButton reRender="error,blocktable,buttons" action="{!Cancel}" value="Cancel"/>
                <apex:inputHidden />
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasprevious}" action="{!First}" value="First"/>
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasprevious}" action="{!Previous}" value="Previous"/>
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasnext}" action="{!Next}" value="Next"/>
                <apex:commandButton reRender="error,blocktable,buttons" disabled="{!!hasnext}" action="{!Last}" value="Last"/>
           <!---</apex:pageBlockButtons>--->
           </apex:panelGrid>
           
           <apex:pageBlockSection id="blocktable" >
           
                <apex:pageBlockTable value="{!AccountsortList}" var="t" rendered="{!NOT(ISNULL(AccountsortList))}" id="cmdsort">
                                          
                        <apex:column >
                            <apex:facet name="header">   
                                <apex:commandLink action="{!ViewData}" value="Account Name{!IF(ExpressionSort=='name',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}">
                                    <apex:param value="name" name="column" assignTo="{!ExpressionSort}" ></apex:param>
                                </apex:commandLink>
                            </apex:facet>
                            <apex:outputLink value="/{!t.Id}" target="_blank">{!t.Name}</apex:outputLink>
                        </apex:column>
                        
                                                
                        <apex:column headerValue="BillingState/Province" value="{!t.BillingState}"/> 
                        <apex:column headerValue="Phone" value="{!t.Phone}"/>
                        <apex:column headerValue="Type" value="{!t.Type}"/>                   
                        <apex:column headerValue="Account Owner Alias" value="{!t.Owner.Name}"/>
                        <apex:column headerValue="Website" value="{!t.Website}"/>
                   
                    <apex:inlineEditSupport event="onClick"/>
                   
                    
                </apex:pageBlockTable>

           </apex:pageBlockSection>   
           
           
        </apex:pageBlock>
    </apex:form>
</apex:page>

Here I am using the extension controller for providing the sorting functionality I don't know why the both is working together Can any one know the help me to rectify this problem in here.For answer's thanks in advance.
sandeep madhavsandeep madhav
Hi,

Please add rerender to commandlink for sorting  - reRender="error,blocktable,buttons"

rerender complete form/pageblock

<apex:commandLink action="{!ViewData}" value="Account Name{!IF(ExpressionSort=='name',IF(DirectionOfSort == 'ASC', '▼', '▲'),'')}" reRender="Form id/PageBLock id">
             <apex:param value="name" name="column" assignTo="{!ExpressionSort}" ></apex:param>
</apex:commandLink>

Mark this as best answer if it helps