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
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'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();
    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;
       String Queryitem = ' SELECT Id, Name, Phone, BillingState, Type, Owner.Name, Website FROM Account WHERE Account.Name != Null ORDER BY ' + FullSortExpression +' Limit 1000';
        AccountsortList = DataBase.query(Queryitem);
        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: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: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:outputLink value="/{!t.Id}" target="_blank">{!t.Name}</apex:outputLink>
                        <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"/>


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

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>

Mark this as best answer if it helps