0

To all I have the requirement as like below the followingly,

  • I have to provide the accountlist view as like on my developer org listview.
  • That's also having the sorting order functionality of all column in the page.
  • And also to the pagination functionality of all records of the account in the org.
  • And also provide the alphabetic search order to all list of account records.

Here I have done this to the pagination and sorting account (as first try now so I try in the first column only on the sorting function)records as followingly,

My controller:

public class AccountListViewController{
public List<Account> AccountsortList {get; set;}
public String SortingExpression = 'name';
public String DirectionOfSort = 'ASC';

    public AccountListViewController(ApexPages.StandardSetController controller) {
        AccountsortList = new List<Account>();
        ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(AccountsortList);
    }

    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, BillingCountry, 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 followingly,

<apex:page standardController="Account" recordSetVar="Accountvar" 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="{!Accountvar}" 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 What's wrong is,

it's doesn't provide the output as well as error also.

  • My pagination is to be worked perfectly but My sorting is not working it's shown the symbol changing only on the header column area as up and down but the records as not changed.

And I don't know to how to rectify this problem and provide the alphabetic search option for this code.

So please make a changes on provide code to meeting the my requirement.For answer's thanks in advance.

  • which API version Apex Class has? – Patlatus Oct 25 '16 at 12:28
  • @Patlatus thanks for the reply,I am using the API version of Salesforce.com API 38.0 version – MohanRaj Oct 25 '16 at 12:35
2

Your table is using Accountvar which is populated by the standard set controller (and so is unaffected by your sorting logic) because of this:

<apex:page standardController="Account" recordSetVar="Accountvar" ...

    <apex:pageBlockTable value="{!Accountvar}"...

Instead reference the data you are querying and sorting:

    <apex:pageBlockTable value="{!AccountsortList}"...
| improve this answer | |
  • Thanks for the reply, If I change the above changes my sorting is working but my pagination is not working but I want work both. – MohanRaj Oct 25 '16 at 13:12
  • @MohanRaj Yeah that takes a bit of work AFAIK - here is one example - Visualforce Table with Sorting and Pagination. – Keith C Oct 25 '16 at 13:19
  • thanks for the reply I read the link page but I don't work any time in the wrapper class so can you suggest any normal class example page please sir. – MohanRaj Oct 25 '16 at 13:34
  • @MohanRaj The wrapper class idea is not too hard to understand. But Google should reveal other solutions if you don;t like that one... – Keith C Oct 25 '16 at 13:40
  • Okay sir thank you. – MohanRaj Oct 25 '16 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.