Get DataTables to work with rows added dynamically?

Get DataTables to work with rows added dynamically?

whalerwhaler Posts: 1Questions: 1Answers: 0

I have a table that I can add rows and columns to using jQuery. However, when I add a new row, this doesn't get updated with DataTables and the row is removed once I sort any of the columns or perform any DataTables action. I can provide the code, but it's basically just adding a "<tr><td> </td>... etc </tr>" to the table after the last row.

Any suggestions?

Answers

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

    Hi @whaler ,

    Once you've initialised the table, if you add a row to the DOM, DataTables won't be aware of it by default. There's two things you can do:

    1. add the row with row().add()
    2. once you've added the row, call rows().invalidate() to re-read the DOM

    Cheers,

    Colin

This discussion has been closed.