Accessing other cells in the same row on click td

Accessing other cells in the same row on click td

RolandHRolandH Posts: 1Questions: 1Answers: 0

When clicking on a cell, I can get the value of the cell and change it. How do I change the value of the cell next to it?

$('#mytable tbody').on( 'click', 'td', function () {
  var table = $('#mytable').DataTable();

  var cell = table.cell( this );
  var val = cell.data();
 console.log(val);  // current value
  
cell.data( 'new value' ).draw(); change the value of the clicked cell.

    
});

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi RolandH,

    The API method .cell().index() can tell you details about the cell you have, then you can tweak it to get the neighbouring cell, as in this example.

    Cheers,

    Colin

This discussion has been closed.