3

I do have Vf page which does a search on accounts. The Vf page holds certain filters which the user selects and the query is generated based on the filters in a list of accounts.

Now the user wants an ability to remove certain records from the search result. So i have a wrapper class with a boolean field and the account record so the user can check the accounts not required on the search result and click on remove.

I wanted to have an ability to have the search results in a paged manner so that i dont have too many results displayed in the page.

How do we use standard set controllers on wrapper classes?

2

Just as i posted this question.. i came across this Richards blog

http://richardvanhook.com/2009/08/03/visualforce-pagination-with-apex-lang/

The second code example was exactly what i was looking for...

| improve this answer | |
0

This one is helpfull to you

<script type="text/javascript">

    function doCheckboxChange(cb,itemId){

        if(cb.checked==true){
            aSelectItem(itemId);
        }
        else{
            aDeselectItem(itemId);
        }

    }

</script>

<apex:form >

    <!-- handle selected item -->
    <apex:actionFunction name="aSelectItem" action="{!doSelectItem}" rerender="mpb">
        <apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
    </apex:actionFunction>

    <!-- handle deselected item -->
    <apex:actionFunction name="aDeselectItem" action="{!doDeselectItem}" rerender="mpb">
        <apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
    </apex:actionFunction>

    <apex:pageBlock title="CloudClickware Pagination Sample" id="mpb">

        <!-- table of data -->
        <apex:pageBlockTable title="Contacts" value="{!contacts}" var="c">
            <apex:column >
                <apex:facet name="header">Action</apex:facet>
                <apex:inputCheckbox value="{!c.IsSelected}" onchange="doCheckboxChange(this,'{!c.tContact.Id}')"/>
            </apex:column>
            <apex:column value="{!c.tContact.FirstName}"/>
            <apex:column value="{!c.tContact.LastName}"/>
            <apex:column value="{!c.tContact.Title}"/>
            <apex:column value="{!c.tContact.Phone}"/>
            <apex:column value="{!c.tContact.Email}"/>
        </apex:pageBlockTable>

        <!-- count of selected items -->
        <apex:outputLabel value="[{!selectedCount} records selected]" />

        <br/>

        <!-- next, previous and page info -->
        <apex:commandLink action="{!doPrevious}" rendered="{!hasPrevious}" value="Previous" />
        <apex:outputLabel rendered="{!NOT(hasPrevious)}" value="Previous" />

        <apex:outputLabel value=" (page {!pageNumber} of {!totalPages}) " />

        <apex:commandLink action="{!doNext}" rendered="{!hasNext}" value="Next" />
        <apex:outputLabel rendered="{!NOT(hasNext)}" value="Next" />

        <apex:pageBlockButtons >
            <apex:commandButton value="Delete" action="{!del}"/>
        </apex:pageBlockButtons>

    </apex:pageBlock>

</apex:form>


public with sharing class wrapperpagination{

public PageReference del() {
    return null;
}

public String contextItem{get;set;}

private ApexPages.StandardSetController setCon;

private Set<Id> selectedContactIds;

public wrapperpagination()
{

    this.selectedContactIds= new Set<Id>();

    this.setCon= new ApexPages.StandardSetController( [SELECT Id, FirstName, LastName, Title, Phone, Email FROM Contact] );
    this.setCon.setpageNumber(1);
    this.setCon.setPageSize(10);

}

public void doSelectItem(){

    this.selectedContactIds.add(this.contextItem);

}

public void doDeselectItem(){

    this.selectedContactIds.remove(this.contextItem);

}

public Integer getSelectedCount(){

    return this.selectedContactIds.size();

}

public void doNext(){

    if(this.setCon.getHasNext())
        this.setCon.next();

}

public void doPrevious(){

    if(this.setCon.getHasPrevious())
        this.setCon.previous();

}

public List<CCWRowItem> getContacts(){

    List<CCWRowItem> rows = new List<CCWRowItem>();

    for(sObject r : this.setCon.getRecords()){
        Contact c = (Contact)r;

        CCWRowItem row = new CCWRowItem(c,false);
        if(this.selectedContactIds.contains(c.Id)){
            row.IsSelected=true;
        }
        else{
            row.IsSelected=false;
        }
        rows.add(row);
    }

    return rows;

}

/*
*   return whether previous page exists
*/
public Boolean getHasPrevious(){

    return this.setCon.getHasPrevious();

}

/*
*   return whether next page exists
*/
public Boolean getHasNext(){

    return this.setCon.getHasNext();

}

public Integer getPageNumber(){

    return this.setCon.getPageNumber();

}


Public Integer getTotalPages(){

    Decimal totalSize = this.setCon.getResultSize();
    Decimal pageSize = this.setCon.getPageSize();

    Decimal pages = totalSize/pageSize;

    return (Integer)pages.round(System.RoundingMode.CEILING);
}

public with sharing class CCWRowItem{

    public Contact tContact{get;set;}
    public Boolean IsSelected{get;set;}

    public CCWRowItem(Contact c, Boolean s){
        this.tContact=c;
        this.IsSelected=s;
    }

}

}

Thanks, Raghavendra Reddy.D

| improve this answer | |
  • could you post some useful description to your code? – Sergej Utko Oct 30 '14 at 8:08

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.