2
votes

I have a datatable which is originally populated server-side. Users may interact with the datatable by adding row data in a modal-popup. I recently added the data attribute data-order='' so that we can better handle date sorting. Now, our call to fnAddData dies with either of the following errors:

DataTables warning: table id=dtTable - Requested unknown parameter '[object Object]' for row 3, column 0. For more information about this error, please see http://datatables.net/tn/4

OR

DataTables warning: table id=dtTable - Requested unknown parameter '1' for row 6, column 1. For more information about this error, please see http://datatables.net/tn/4

Simple example: https://jsfiddle.net/shanabus/2yu7mLL3/

I checked out the support documentation on datatables.net but they don't address this specific issue. How do you use fnAddData if you are also using data-order?

1

1 Answers

1
votes

You can try constructing tr node and use newer row.add() API method that accepts node as an argument.

For example:

$("#btnAddRow").on("click", function() {    
   var newRow = ['4/4/2014', '<test> Name'];
   var newRowOrder = 999;
   var $row = 
      $('<tr><td data-name="ReadingDate" data-order="' + newRowOrder + '">' 
      + $('<div>').text(newRow[0]).html() 
      + '</td><td data-name="Name">' 
      + $('<div>').text(newRow[1]).html() 
      + '</td></tr>');

   $("#dtTable").DataTable().row.add($row).draw();
});

See updated example for code and demonstration.

I have created an issue #987 proposing to improve documentation regarding this use case.