Changing cell data by javascript

Changing cell data by javascript

zx81zx81 Posts: 9Questions: 2Answers: 0
edited November 2020 in Free community support

I have the current function

function setcoldata(tab,row,col,data){
$('#'+tab+' tr:nth-child('+row+') td:nth-child('+col+')').html(data);
}

It works but if one more row before the targeted row is displaying a child row then the actual targeted row should be incremented.

Example:
Row 1
--Child Row
Row 2

I want to change the first column of row2
setcoldata('mytable';2;1;'data') will not work because the row #2 is actually the the information child row.

Not exactly sure how to proceeed.
Counting the child rows before the targeted row ?
Or is there a way to omit certain classes when using nth-child ?
I'm still a beginner in Javascript...

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    edited November 2020 Answer ✓

    Changing the data in the DOM wouldn't be reflected in DataTables - since it caches its data. It would be best to use cell().data() or row().data() to change the data.

    Colin

  • zx81zx81 Posts: 9Questions: 2Answers: 0

    Thanks. Got it to work with cell().data.

This discussion has been closed.