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
DavserDavser 

Column with "Select All" Checkbox

I'd like to have the "Select All" functionality on a column in a pageBlockTable. It exists in various parts of Salesforce, where it is a checkbox beside the column title, which will select all or deselect all checkboxes in that column. How would I go about doing this for the following code:
 
Code:
<apex:pageBlockTable value="{!allIOs}" var="io">
 <apex:column headerValue="Select">
  <apex:inputCheckbox value="{!io.mfd}"/>
 </apex:column>

 
Thanks for any tips in advance!
jwetzlerjwetzler
I think the way I would do this is instead of giving a headerValue of "Select" I'd give it a headerFacet with another inputCheckboxes.  I have not tried this out but I'd think it would be something like this:

Code:
<apex:pageBlockTable value="{!allIOs}" var="io" id="table">
 <apex:column>
  <apex:facet header="name">
    <apex:inputCheckbox value="{!allSelected}">
      <apex:actionSupport event="onchange" rerender="table"/>
    </apex:inputCheckbox>
  </apex:facet>
  <apex:inputCheckbox value="{!io.mfd}"/>
 </apex:column>

 and then in setAllSelected, you'd loop through getAllIOs and call setMfd(true).

TehNrdTehNrd
Just a heads up. I noticed some strange behavior in IE6 if you use the event="onchange" with a check box. At least when rerendering it doesn't do anything until you click the check box and then click away, almost like an onblur event. Using onclick seemed to do the trick.
DavserDavser
Thanks guys. The onchange issue is a "feature" of Internet Explorer in general (including IE7) and with a checkbox I use "onclick" instead. Thanks for the feedback guys