Quantcast
Channel: DataTables 1.10 — DataTables forums
Viewing all articles
Browse latest Browse all 2366

Best way to update cell in row based on data in another cell?

$
0
0

I'm trying to loop through the rows, updating all the data in cells in a certain column based on the data in the associated cell in another column. Not sure the best way to do that, and am having trouble figuring out how to do it at all. After a couple of hours of struggling with this feel it's time to ask the forum :)

I'm sure there's a better way to do this. I tried starting at the cell level but didn't see how to select the parent to get to the a column data. Probably best done using raw jQuery, but I'm struggling

See http://codepen.io/louking/pen/adaXLY for my non-working example

table = $('#tbl').DataTable({
  columns: [{ name: 'a' }, 
            { name: 'b' }, 
            { name: 'c' }]
})

var andx = table.column('a:name').index();
var bndx = table.column('b:name').index();

table.rows().every ( function () {
  var adata = this.cells( andx ).data();
  this.cells( bndx ).data('xx' + adata);
} );
<table id=tbl>
  <thead>
    <tr>
      <th>col0</th>
      <th>col1</th>
      <th>col2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>a0</td>
      <td>b0</td>
      <td>c0</td>
    </tr>
     <tr>
      <td>a1</td>
      <td>b1</td>
      <td>c1</td>
    </tr>
  </tbody>
</table>

Viewing all articles
Browse latest Browse all 2366

Trending Articles