jquery - How can I pass a html table row into DataTable.net fnAddData -


I'm using the DataTable.net plugin and I'm thinking how can I add a line dynamically to the current table?

I'm looking at this example and they see it like this

Global Variables for Tables Object * / var oTable; Global var / var giCount = 2 for Counter * $ (Document) .ready (function () {oTable = $ ('# example'). DataTable ();}); Function fnClickAddRow () {oTable.fnAddData ([giCount + "1", giCount + "2", giCount + "3", giCount + ". 4"]); GiCount ++; }

But I'm wondering what happens if I want that the table row has already been given to me?

This is my desk.

  & lt; Table range = "1" & gt; & Lt; TR & gt; & Lt; Td> Line 1, cell 1 & lt; / Td> & Lt; Td> Line 1, cell 2 & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td> Line 2, cell 1 & lt; / Td> & Lt; Td> Line 2, cell 2 & lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt;  

I now have this

  var newRow = '& lt; Tr & gt; & Lt; Td> Line 3, cell 1 & lt; / Td> & Lt; Td> Line 3, cell 2 & lt; / Td> & Lt; / Tr & gt; ';  

How can I add it through addRow?

I tried oTable.fnAddData (newRow); But it does not seem to work.

So I'm not sure how to do this.

call as you want to add, with one array of fnAddData

  oTable.fnAddData (["row3, cell 1", "row3, cell2"]);  

Version 1.10 from is used by the row.add () method

, here is the argument :

  1. Array string : The data to be added to the table. This array must be of the same length as the number of columns on the basic HTML table.
    or
    array array string : The 2D array of data to be added to the table should be of the same length as the number of columns on the basic HTML table.
  2. Boolean : Optional - New or new data after adding new data (default)
/ Html>

Comments