0

to all I am trying to provide the sorting and pagination on standard controller with extension by followingly,My controller

public class StandardPaginationSorting {

    // Variables required for Sorting.
    public String soql {get;set;}
    public List <Account> CandidateList1 = New List <Account>();
    public String soqlsort {get;set;}
    public List <Account> CandidateList2 = New List <Account>();

                // List used in to display the table in VF page.
                public List<Account> getCandidateList() {
                    // Passing the values of list to VF page.
                    return con.getRecords();
                }

                // instantiate the StandardSetController from a query locator
                public ApexPages.StandardSetController con {
                    get {
                                                if(con == null) {
                                                                // String Query to have a list of cases for a respective End-user.
                                                                soql = 'SELECT Name, Email, Website,BillingCountry, Phone, Type, Owner.Name FROM Account';

                                                                // Passing the String array to a list with Selected field sorting.
                                                                CandidateList1 = Database.query(soql + ' order by ' + sortField + ' ' + sortDir ); 

                                                                // setting values of List in StandardSetController.
                                                                con = new ApexPages.StandardSetController(CandidateList1);

                                                                // sets the number of records in each page set
                                                                con.setPageSize(5);
                                                }
                                                return con;
        }
        set;
    }

    // indicates whether there are more records after the current page set.
    public Boolean hasNext {
        get {
            return con.getHasNext();
        }
        set;
    }

    // indicates whether there are more records before the current page set.
    public Boolean hasPrevious {
        get {
            return con.getHasPrevious();
        }
        set;
    }

    // returns the page number of the current page set
    public Integer pageNumber {
        get {
            return con.getPageNumber();
        }
        set;
    }

    // returns the first page of records
    public void first() {
        con.first();
    }

    // returns the last page of records
    public void last() {
        con.last();
    }

    // returns the previous page of records
    public void previous() {
        con.previous();
    }

    // returns the next page of records
    public void next() {
        con.next();
    }

    // returns the PageReference of the original page, if known, or the home page.
    public void cancel() {
        con.cancel();
    }

    // Method for Constructor is used for Test Class.
    public StandardPaginationSorting(){
    }

   //Toggles the sorting of query from asc<-->desc
    public void toggleSort() {
        // simply toggle the direction
        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';

                                // run the query again for sorting other columns
                                soqlsort = 'SELECT Name, Email, Phone, BillingCountry, Website, Owner.Name, Type FROM Account'; 

                                // Adding String array to a List array
                                CandidateList2 = Database.query(soqlsort + ' order by ' + sortField + ' ' + sortDir ); 

                                // Adding Caselist to Standard Pagination controller variable
                                con = new ApexPages.StandardSetController(CandidateList2);

                                // Set Page Size to 5
                                con.setPageSize(5);

    }

    // the current sort direction. defaults to asc
    public String sortDir {
        // To set a Direction either in ascending order or descending order.
                                get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;}
        set;
    }

    // the current field to sort by. defaults to last name
    public String sortField {
        // To set a Field for sorting.
                                get  { if (sortField == null) {sortField = 'Name'; } return sortField;  }
        set;
    } 

}

and My Page

<apex:page standardController="Account" extensions="StandardPaginationSorting" showHeader="false" sidebar="false"> 

    <!-- CSS added to display alternate row colors and Center align Text in PageblockTable -->
    <style type="text/css">
        .oddrow{background-color: #00FFFF; } 
        .evenrow{background-color: #7FFFD4; } 
        .textalign{text-align:center; } 
    </style>

    <apex:form id="form">
        <!-- Tabstyle attribute is used to assign the color scheme to the pageblock.Here Candidate Object color scheme is used for the pageblock-->
        <apex:pageBlock id="pgblock" tabStyle="Account">
            <apex:pageBlockSection title="Candidate Details -  Page #{!pageNumber}" columns="1" collapsible="false">   
                <!-- Rowclasses attribute is used to define different CSS classes for different rows. 
                     Rules attribute is used: borders drawn between cells in the page block table.
                     Title attribute will be used as a help text when a user hovers mouse over the Page Block table.
                     Styleclass, HeaderClass attributes are used to Center align Table Text in Page Block table --->
                <apex:pageBlockTable value="{!CandidateList}" var="CadList" rowClasses="oddrow,evenrow"   rules="groups"  title="Click Column Header for Sorting"  styleclass="textalign" headerClass="textalign" >
                    <apex:column >
                        <apex:facet name="header">
                           <apex:commandLink value="Name" action="{!toggleSort}" rerender="pgblock">
                                <!-- Value attribute should have field (API Name) to sort in asc or desc order -->
                                <apex:param name="sortField" value="Name" assignTo="{!sortField}"/>
                           </apex:commandLink>
                        </apex:facet>
                        <apex:outputField value="{!CadList.Name}"/>
                    </apex:column> 

                    <apex:column >
                        <apex:facet name="header">
                            <apex:commandLink value="Phone" action="{!toggleSort}" rerender="pgblock">
                                <apex:param name="sortField" value="Phone" assignTo="{!sortField}"/>
                            </apex:commandLink>
                        </apex:facet>
                        <apex:outputField value="{!CadList.Phone}"/>
                    </apex:column>

                    <apex:column >
                        <apex:facet name="header">
                            <apex:commandLink value="Email" action="{!toggleSort}" rerender="pgblock">
                                <apex:param name="sortField" value="Email" assignTo="{!sortField}"/>
                            </apex:commandLink>
                        </apex:facet>
                        <apex:outputField value="{!CadList.Email}"/>
                    </apex:column>

                    <apex:column >
                        <apex:facet name="header">
                            <apex:commandLink value="Type" action="{!toggleSort}" rerender="pgblock">
                                <apex:param name="sortField" value="Type" assignTo="{!sortField}"/>
                            </apex:commandLink>
                        </apex:facet>
                        <apex:outputField value="{!CadList.Type}"/>
                    </apex:column>

                    <apex:column >
                        <apex:facet name="header">
                            <apex:commandLink value="Owner.Name" action="{!toggleSort}" rerender="pgblock">
                                <apex:param name="sortField" value="Owner.Name" assignTo="{!sortField}"/>
                            </apex:commandLink>
                        </apex:facet>
                        <apex:outputField value="{!CadList.Owner.Name}"/>
                    </apex:column>

                    <apex:column >
                        <apex:facet name="header">
                            <apex:commandLink value="Website" action="{!toggleSort}" rerender="pgblock">
                                <apex:param name="sortField" value="Website" assignTo="{!sortField}"/>
                            </apex:commandLink>
                        </apex:facet>
                        <apex:outputField value="{!CadList.Website}"/>
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>

            <apex:panelGrid columns="4">
                <apex:commandLink action="{!first}">First</apex:commandlink>
                <apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandlink>
                <apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandlink>
                <apex:commandLink action="{!last}">Last</apex:commandlink>
            </apex:panelGrid>

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

But Unfortuntely I get the following error

Error: Unknown constructor 'StandardPaginationSorting.StandardPaginationSorting(ApexPages.StandardController controller)'

during saving time of my visual page So Can you please give the solution to remove the error and get the output.

1

Create a Constructor that includes a ApexPages.StandardController parameter.

i.e.

public StandardPaginationSorting(ApexPages.StandardController controller){
}
| improve this answer | |

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.