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
GL-WorkForceGL-WorkForce 

How to check all the checkbox in a pageBlockTable on a outPutPanel

Hi,

        I am new to Apex development and i have a problem which i am stuck on. I have a control on my APEX page which opens a new Popup window having all the contacts. This table has three columns checkboxes, Names and email ids. Now my problem is that when i click on the checkbox in the header of the table, all the checkboxs in the column should be selected. I have gone through many bolgs and didn't found any suitable approch to do this. Please help me here. Thanks in advance.

 

bob_buzzardbob_buzzard
You would do this via Javascript rather than Apex.  Add an onchange event to the checkbox in the header that calls a JS function.  In the JS function, locate all the checkboxes in the table and check them.
Ispita_NavatarIspita_Navatar

You can achieve this functionality for selecting and deselecting all check-boxes through javascript function.


select_deselect_checkbox_Header(value) // called on onclick event of header checkbox
{
if(value) //value is true when checkbox is checked else false
get all the ids of the checkboxes which say you assign
in such a way say with element id like chkbox1, chkbox2 upto the records that are there and if value is true check all the checkboxes else uncheck them
}
select_deselect_checkbox(value1) // called on onclick event of individual checkboxes in the pageblock table
{
value1 is the true if the checkbox is checked and false if it is unchecked
if value1 is false uncheck header checkbox
else check if all the checkboxes are selected then
select the header checkbox
else
do nothing
}

Christopher_Alun_LewisChristopher_Alun_Lewis

Check out the following link for a solution involving a javascript function.

 

I have also developed a solution that doesn't use any script tags, where the selection process is handled inside the controller.

 

 

see The Christopher Alun Lewis Blog for Salesforce news, comment and development tips and tricks