dimanche 12 mai 2019

Query Clone table row with selected drop down value using checkbox

I want clone checked row's selected option value and paste to the entire table .

When I cloned and pasted, the selected option value only gets pasted to the last row of the column and the previous row's drop down changes but selected drop down option value does not changed.

<table id="dataTable" class="table table-bordered,table table-striped fixed_headers">
  <thead>
        <tr>
      <th></th>
            <th>Name</th>
            <th>Job</th>
            <th>Year Joined</th>
            <th>Mission</th>
    </thead>
  <tbody>
    <tr style="text-align: center" *ngFor="let data of Table;let i = index">
    <td>
      <input type="checkbox">
    </td>
        <td>
            <span></span>
        </td>
        <td>
            <span></span>
        </td>
        <td>
            <span></span>
        </td>
        <td>
            <select>
             <option *ngFor="let mission of data.missions">
                
             </option>
          </select>
        </td>
  </tr>
  </tbody>
</table>
<div class="row">
    <input id="copy" type="submit" name="copy" value="Copy" (click)="copy()" class="btn btn-flat"/>
    <input id="pasteall" type="submit" name="pasteall" value="Paste All" (click)="pasteall()" class="btn btn-flat"/>
</div>

  copy(){
      var srcrow = $('#dataTable tr').has('input:checked');
      this.Row = srcrow.clone();
      this.Row.find('select').val(function(index, value) {
        return srcrow.find('select').eq(index).val();
      });
      console.log(this.Row);
  }

  pasteall(){
    $('#dataTable tbody tr').replaceWith(this.Row);
  }




Aucun commentaire:

Enregistrer un commentaire