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
Harsha ShriHarsha Shri 

Pagination for wrapper Search results - emergency

Hi All,
I want pagination functionality for wrapper list which dynamically showing results based search text.
Here is my code
<apex:page controller="CategorySearchController">  
 <apex:form >
        <apex:pageBlock >

            <apex:pageBlockButtons >
                <apex:commandButton action="{!back}" value="Back"/>
            </apex:pageBlockButtons>
            <apex:pageMessages />

            <apex:pageBlockSection title="You Selected" columns="1">
                <apex:pageBlockTable value="{!selectedCategories}" var="c">
                    <apex:column value="{!c.cat.Name}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>           

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

controller class
 
public class CategorySearchController {

    // the results from the search. do not init the results or a blank rows show up initially on page load
    public List<categoryWrapper> searchResults {get;set;}
    // the categories that were checked/selected.
    public List<categoryWrapper> selectedCategories {
        get {
            if (selectedCategories == null) selectedCategories = new List<categoryWrapper>();
            return selectedCategories;
        }
        set;
    }      

    // the text in the search box
    public string searchText {
        get {
            if (searchText == null) searchText = 'acc'; // prefill the serach box for ease of use
            return searchText;
        }
        set;
    } 

    // constructor
    public CategorySearchController() {}

    // fired when the search button is clicked
    public PageReference search() {

        if (searchResults == null) {
            searchResults = new List<categoryWrapper>(); // init the list if it is null
        } else {
            searchResults.clear(); // clear out the current results if they exist
        }
        // Note: you could have achieved the same results as above by just using:
        // searchResults = new List<categoryWrapper>();

        // dynamic soql 
        String qry = 'Select c.Name, c.Id From account c Where c.Name LIKE \'%'+searchText+'%\' Order By c.Name';
        
        for(account c : Database.query(qry)) {
            //new wrapper by passing it the category in the constructor
            CategoryWrapper cw = new CategoryWrapper(c);
            // wrapper to the results
            searchResults.add(cw);
        }
        return null;
    }   

    public PageReference next() {

        // clear out the currently selected categories
        selectedCategories.clear();

        // add the selected categories to a new List
        for (CategoryWrapper cw : searchResults) {
            if (cw.checked)
                selectedCategories.add(new CategoryWrapper(cw.cat));
        }

        // ensure they selected at least one category or show an error message.
        if (selectedCategories.size() > 0) {
            return Page.Category_Results;
        } else {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least one Category.'));
            return null;
        }       

    }       

    // fired when the back button is clicked
    public PageReference back() {
        return Page.Category_Search;
    }       

}
public class CategoryWrapper {

    public Boolean checked{ get; set; }
    public account cat { get; set;}

    public CategoryWrapper(){
        cat = new account ();
        checked = false;
    }

    public CategoryWrapper(account c){
        cat = c;
        checked = false;
    }

   

}

I want pagination for the records which are showing in dynamic wrapper list.
Please help me. Its urgent
Thanks in Advance