Adding a row to a table - providing the entire row HTML (As opposed to each column value in array)

Adding a row to a table - providing the entire row HTML (As opposed to each column value in array)

jLinuxjLinux Posts: 981Questions: 73Answers: 75
edited July 2015 in Free community support

Hey guys, so I have a table that I add rows to via jQuery/DataTables, as well as via PHP (Before the rable is rendered). The rows are a bit complicated, so im going to use Mustache to supply the template. Is there a way to provide the entire row to add? As opposed to each column?

Right now, its: t.api().row.add( ['Col1','Col2','Col3']);

Id like to use: Right now, its: t.api().row.add('<tr><td>Col1</td><td>Col2</td><td>Col3</td></tr>');

That would make life soo much easier, thanks!

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    P.S. I know I could use something like this:
    $("#data-table > tbody").append('<tr><td>Col1</td><td>Col2</td><td>Col3</td></tr>');

    But then when I delete a row using the DataTables code, it deletes all rows that werent inserted using the row.add array

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited July 2015

    I was able to figure this out by parsing the HTML.. if anyone wants to see how, here ya go.

    EDIT: Posting code in here doesnt work well

    http://pastebin.com/U4sjnW41

This discussion has been closed.