Add data to each cell in a row

Add data to each cell in a row

adrian22adrian22 Posts: 6Questions: 3Answers: 0

Hi,

I have a strange setup. Have not used the ajax stuff. I get data from mysql and loop out the td's. Not
the best way, but I need <span> etc I do not like having that in the server code.

Anyway, I get the results and everything is great. Then I save some data back to mysql and retrieve the new data back from server. Here comes the problem. If I added a search to the table the list have changed from the initial way with much more data from server. So I thought ok. I have the current searched rows and each index. So I want to change one row. But it should affect the hole datatable object not only the visible stuff. If I have a large paginated list this must work.

How can I do this?

Here is my current code:

pl.adata.cell(0, 1).data('hello');
pl.adata.rows().invalidate().draw();

Nothing happens when I do this. Please help :)

Answers

  • glendersonglenderson Posts: 231Questions: 11Answers: 29

    Try something like this in your javaScript

      var table = $("#example").DataTable()
        var d = table.row("#yourrowid").data();
        d[0]="No Span here";
        d[1]="<span style=\"color:red\" >Just A test<\span>";
        d[2]="<span style=\"blue:red\" >Update me<\span>";
        table.row("#yourrowid").data(d).draw();
    
  • adrian22adrian22 Posts: 6Questions: 3Answers: 0

    Oh thank you! Great stuff. But what if I only want to chance some of them not all?
    And also for a hidden row on the next page? Thanks man!

This discussion has been closed.