yanivk1984
6/18/2019 - 8:19 AM

delete tables rows not including the table header in javascript

        // delete all the table rows not including the header
        var myTable = document.getElementById("table");
        var rowCount = myTable.rows.length;
        for (var x=rowCount-1; x>0; x--) {
           myTable.deleteRow(x);
        }
<table id="table" class="table"  style="display: inline; position: relative" >
  <thead class="thead-dark" >
      <tr>
          <th scope="col"> Object Name </th>
          <th scope="col"> Type </th>
          <th scope="col"> IP/Network </th>
       </tr>
  </thead>

  <tbody>
      {% for device in devices %}

            <tr>
                <td>{{device.checkpointName}}</td>
                <td>{{device.deviceName}}</td>
                <td id="deviceId" >{{device.deviceId}}</td>
                <td>Waiting</td>
                <td>{{device.lastSuccessfulBackupDate}}</td>
                <td>Waiting</td>
                <td> <button id={{ device.deviceId }} class="btn btn-primary btn-lg" onclick="runBackup(this.id)" > Run </button> </td>
            </tr>
      {% endfor %}
   </tbody>
</table>