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
Mont MontMont Mont 

Change pageblocktable value by clicking checkbox

Hello. I need to use checkbox like a filter for rows from my table. How to do that? For example, show only "А" names, when checkbox is true, and return all names, when it's false.
Ajay K DubediAjay K Dubedi
Hi Mont,

You can try the following code where clicking on checkbox includes the only account that has 'a' in them.
 
<apex:page Controller="CheckBoxActionExt">
    <apex:pageBlock >
        <apex:form >
            <apex:inputCheckbox id="chkBox" value="{!ifChecked}">
            <apex:actionSupport event="onchange" action="{!checkBoxChecked}"/>
            </apex:inputCheckbox>
            <apex:pageBlockTable value="{!accList}" var="a" id="list">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.billingstreet}"/>
                <apex:column value="{!a.billingCity}" />
                <apex:column value="{!a.billingCountry}" />
                <apex:column value="{!a.billingPostalCode}"/>
                <apex:column value="{!a.createdById}"/>
            </apex:pageBlockTable>
        </apex:form>
    </apex:pageBlock>
</apex:page>

public class CheckBoxActionExt {
    public string searchstring = 'a';
    public List<Account> accList {get;set;} 
    public boolean ifChecked {get;set;}
    
    public CheckBoxActionExt() {     
        string searchquery ='select name,billingstreet,billingCity,billingCountry,billingPostalCode,createdById from Account limit 10';  
        accList = Database.query(searchquery); 
    }   
    
    public void checkBoxChecked()
    {   
        if(ifChecked)
        {
            string searchquery ='select name,billingstreet,billingCity,billingCountry,billingPostalCode,createdById from Account where name like \'%'+searchstring+'%\' limit 10';  
            accList = Database.query(searchquery); 
        }else
        {
            string searchquery ='select name,billingstreet,billingCity,billingCountry,billingPostalCode,createdById from Account limit 10';  
            accList = Database.query(searchquery); 
        }
    }
}

Hope it will help you, Mark it as Best answer if find helpful.

Thank you 
Ajay Dubedi