table.row.add() ignores column, when column has a data-sort attribute in first data row
table.row.add() ignores column, when column has a data-sort attribute in first data row
Link to test case:
https://live.datatables.net/keqowaka/1/edit
Debugger code (debug.datatables.net):
Error messages shown:
none in live.datatables.net, but triggers
DataTables warning: table id=deliverables-table-form - Requested unknown parameter '[object Object]' for row 56, column 0. For more information about this error, please see https://datatables.net/tn/4"
in my own project, unless I use
columnDefs: [{
defaultContent: "-",
targets: "_all"
}]
Description of problem:
If the first <tr> in the body contains <td>(s) with a data-sort attribute, the column can't be added via the row.add() API.
If you check the test case and add data-sort attributes to the first row, the respective column content will disappear from the row added with row.add()
This doesn't happen if any of the following rows have data-sort attributes. It only seems to happen with the first row.
I would say it's a bug ![]()
Replies
Hi,
When you use a
data-*attribute, DataTables needs to store the data from the attribute and the cell's content - so it isn't a simple string like you are trying to add. Rather it uses an object such as:Using that structure with
row.add()allows everything to work as expected: https://live.datatables.net/keqowaka/3/edit .So not a bug, but just a change in how you are using it. If you weren't using
data-*attributes, then yeah, a simple string would be fine for the data value.For more information, see this part of the manual which explains this.
Allan
Ah thank you @allan ! I was not aware that the use of data-sort "kinda" turns the "flat" HTML-sourced column into orthogonal structure. I am aware of orthogonal data and use it in ajax-sourced / JSON situations, but didn't think of it here.
Thank you so much, no issues anymore.