2 Replies Latest reply: Jul 20, 2012 1:37 AM by 943068 RSS

    Check all checkboxes in a column of a tabular form

    943068
      Hi,
      I think this can be useful for some people.. I have a tabular form with several columns containing checkboxes. I wanted to be able to check or uncheck a whole column. The problem is that I didn't find a function to do this. So I modified (and renamed) the $f_CheckFirstColumn(pNd) function.

      In "edit page > JavaScript Function and Global Variable Declaration", add this :
      function $f_CheckNthColumn(c,n){
           var e=$x_UpTill(c,"TABLE");
           for(var d=0,a=e.rows.length;d<a;d++){
                var b=$x_FormItems(e.rows[d],"CHECKBOX")[n];
                if(b){
                     if(b.checked != c.checked) {
                          b.click();
                     }
                }
           }
           return;
      }
      EDIT : The status of the checkboxes checked with the function below is not passed when submitting the form (it is passed when clicking on every checkbox). This is why I had to use the click() function (so that onClick is triggered).
      --
      function $f_CheckNthColumn(c,n){
           var e=$x_UpTill(c,"TABLE");
           var f=[];
           for(var d=0,a=e.rows.length;d<a;d++){
                var b=$x_FormItems(e.rows[d],"CHECKBOX")[n];
                if(b){
                     f[f.length]=b;
                }
           }
           $f_CheckAll(false,c.checked,f);
           return f;
      }
      --

      And in the report column header :
      <input type="checkbox" onClick="$f_CheckNthColumn(this, NUMBER);" />
      NUMBER being the column number (1st column containing checkboxes = 0, 2nd column containing checkboxes = 1, etc.)

      I'm using APEX 4.1.1.00.23, so I can not guarantee It'll work on other versions.

      Hope this can help !

      Edited by: ben0123 on Jul 13, 2012 12:12 AM

      Edited by: ben0123 on Jul 13, 2012 1:17 AM
        • 1. Re: Check all checkboxes in a column of a tabular form
          swesley_perth
          Awesome! Thanks for posting this, exactly what I was looking for this morning ;-)

          My only curly is I have some rows where the checkbox is conditional, it treats the next column as the nth checkbox for that row - if that makes sense.
          I'll see what happens if I work how how to hide the checkbox post-render.
          • 2. Re: Check all checkboxes in a column of a tabular form
            943068
            Glad it helped :)

            If you have only one checkbox that is conditional, you could change the $f_CheckNthColumn function by adding this kind of condition :
            if ($x_FormItems(e.rows[d],"CHECKBOX").length == max_number_of_checkboxes || n < position_of_conditional_checkbox) toggle checkbox(n); // all the checkboxes are displayed, or the nth checkbox is before the conditional checkbox
            else // one (or more?) checkbox is missing
              if (n == position_of_conditional_checkbox) do nothing;
              else toggle checkbox(n-1);