3 Replies Latest reply on Jul 27, 2012 3:09 AM by csm_phil

    How delete row in table by java script ?

    Axel44FR

      hello,

       

      i have a big table of thousands lines and i have to delete the blank row

       

      How do i this ?

       

      thanks

       

      Axel

        • 1. Re: How delete row in table by java script ?
          thinkink_es Level 1

          You need to select a Table, and then select a row in the table, and apply remove();

           

           

          //myTable --> [table object]
          n=0 // index of rows in the table
          myTable.rows[n].remove();
          
          

           

           

          You can try this example . Insert the mouse in the table cell or select a cell or row and then click on the script . this script remove the first row of a table if the selection is inside a table.

           

          selection = app.selection[0].parent;
          
          
          if(selection.toString() == "[object Table]")
          selection.rows[0].remove();
          else if(selection.parent.toString() == "[object Table]")
          selection.parent.rows[0].remove();
          
          
          • 2. Re: How delete row in table by java script ?
            Axel44FR Level 1

            thanks for the reply,

             

            now, how can i select the blank row ?

            • 3. Re: How delete row in table by java script ?
              csm_phil Level 4

              Hi Axel,

               

              Please try the below JS code.

               

              First you have to select the entire table and then run the script. This script will delte the row if the the words count is 0.

              Note: If, your table have any space in the any cells this script will not delete.

               

               

               

              var myTable = app.selection[0].parent.tables[0];

              for(i=myTable.rows.length-1; i>=0; i--){

                  if(myTable.rows[i].cells.everyItem().words.length==0){

                      //If you need select the row use the below line

                      myTable.rows[i].select();

                      //If you need to delete the blank row use the below line.

                      myTable.rows[i].remove();

                      }

                  }

               

              thx

              csm_phil