0

I got the following method which uses Standardset controller and currently I have assigned a size to display the number of records in each pagination section. I want to make the size a picklist and depending on the value user selects, it should paginate according to that size. How can I do this ?

public void stringSearchValue(){

        setCon = null; // Clears the previous search results
        if(setCon == null){
            size=20; // Records to display for every section

            if( searchStringName.length() >=3 || searchStringPostCode.length() >=3 || searchStringSPID.length() >=3 ){

                string searchquery = 'SELECT Name, Id, Postcode__c, SPID__c, OrgId__c FROM Market_Entity__c WHERE (Name LIKE \'%'+searchStringName+'%\' AND Postcode__c LIKE \'%'+searchStringPostCode+'%\' AND SPID__c LIKE \'%'+searchStringSPID+'%\') AND OrgId__c = \'SWBS\'';

                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(searchquery));
                marketEntity = setCon.getRecords();
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();

                warningMessage = 'No Result Found';
                    if (marketEntity.size() == 0) 
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'No Result Found'));

            }else{
                warningMessage = 'Search text should have atleast 3 characters';
                    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Search text should have 3 characters on atleast one field.'));
            }

        }
    }
1

Created this new getter method and kept the size as it is in the mentioned method.

public List<SelectOption> paginatorSizeList{
        get{
            //List of select options to set the records for a certain number
            paginationSizeOptions = new List<SelectOption>();
                paginationSizeOptions.add(new SelectOption('5','5'));
                paginationSizeOptions.add(new SelectOption('10','10'));
                paginationSizeOptions.add(new SelectOption('20','20'));
                paginationSizeOptions.add(new SelectOption('50','50'));
                paginationSizeOptions.add(new SelectOption('100','100'));

                return paginationSizeOptions;
        }
        set;
    }

did the following VF changes,

<apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus2" reRender="pb"/>

<apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();">
                                                <apex:selectOptions value="{!paginatorSizeList}"/>
                                            </apex:selectList>

<apex:outputPanel >                      
    <apex:actionStatus id="fetchStatus2" >
        <apex:facet name="start" >
        <img src="/img/loading.gif" />                    
            </apex:facet>
    </apex:actionStatus>
</apex:outputPanel>

Found the answer in the following link, very helpful !

http://www.sfdcpoint.com/salesforce/pagination-using-standard-set-controller-salesforce/

| improve this answer | |
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – Jenny B Nov 17 '15 at 17:14
  • Added my answer ! – Tinkerbell Nov 17 '15 at 17:31

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.