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();
                noOfRecords = setCon.getResultSize();

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

                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.'));


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

public List<SelectOption> paginatorSizeList{
            //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;

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:outputPanel >                      
    <apex:actionStatus id="fetchStatus2" >
        <apex:facet name="start" >
        <img src="/img/loading.gif" />                    

Found the answer in the following link, very helpful !


| 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.