3 Replies Latest reply on Apr 14, 2010 3:04 PM by [Jongware]

    Table Column is Empty

    frameexpert Level 4

      Hi All,

       

      I have a table where I am trying to see if a particular column is empty, meaning the it does contain any text or anchored frames. I am thinking the best approach is to check each cell in the column, but if there is a shorthand way of doing it, I would appreciate any pointers. Thank you very much.

       

      Rick

        • 1. Re: Table Column is Empty
          [Jongware] Most Valuable Participant

          What do you consider 'empty'?

           

          alert (app.selection[0].parent.columns[0].contents.join('').length);

           

          (this is supposed to return '0' for an empty column, some other positive value otherwise). This will not work with columns that only seem to be empty (i.e., containing a single space). And sometimes the cells are empty but their shading indicates data.

          • 2. Re: Table Column is Empty
            frameexpert Level 4

            This works fine for a column that contains more than one cell, but the join method fails for a single-cell column. This appears to be a good workaround.

             

            <pre>

            function colOrRowIsEmpty(colOrRow) {
               
                if (colOrRow.cells.length == 1) {
                    if (colOrRow.contents.length == 0) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    if (colOrRow.contents.join("").length == 0) {
                        return true;
                    } else {
                        return false;
                    }
                }
            }

            </pre>

             

            Thank you very much for the generous help.

             

            Rick

            • 3. Re: Table Column is Empty
              [Jongware] Most Valuable Participant

              The one thing I did not try -- but your solution seems perfect. And it's a function, returning a boolean! Well done!