When I open my table, I get an error.
When I open my table, I get an error.
The error is DataTables warning: table id=example - Requested unknown parameter '1' for row 0, column 1. For more information about this error, please see http://datatables.net/tn/4. I know that this has been discussed ad nauseum, but I can't seem to find the magic combination.
My data is an array of objects and is valid JSON:
{
"data": [
{
"DT_RowId": "row_1",
"category": "HTTP Methods",
"test": "API responses MUST use appropriate HTTP status codes.",
"automatable": "Yes",
"priority": "High",
"explanation": "A complete list of codes can be found in the HTTP 1.1 specificataion ."
}, ...
Here's my initialization code:
/* Formatting function for row details - modify as you need */
function format ( d ) {
// d
is the original data object for the row
return '
Explanation: | '+ ''+d.explanation+' | '+ '
';
}
$(document).ready(function (){
var table = $('#example').DataTable({
'ajax': '../ajax/data/demoObjects.txt',
'columns': [
{
'className': 'details-control',
'orderable': false,
'data': null,
'defaultContent': ''
},
{
'orderable': false,
'className': 'select-checkbox',
'targets': 0
},
{ 'data': 'category' },
{ 'data': 'test' },
{ 'data': 'automatable' },
{ 'data': 'priority' }
],
'select': {
'style': 'multi',
'selector': 'td:not(:first-child)'
},
'order': [[1, 'asc']]
} );
// Add event listener for opening and closing details
$('#example tbody').on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
var row = table.row( tr );
if ( row.child.isShown() ) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child( format(row.data()) ).show();
tr.addClass('shown');
}
} );
} );
Any help would be greatly appreciated.
This question has an accepted answers - jump to answer
Answers
Looks like the error is referring to column 1 which is a
select-checkbox
. You don't have a data source defined. Try addingdata: null,
to that column.Kevin
Thanks! I had already tried that, and it didn't work; but I must not have put a comma after the preceding assignment. So the warning is gone.
Unfortunately, all the check boxes in the table now have [object Object] written on top of them.
Sorry, missed that you also need
columns.defaultContent
. For example:defaultContent: "",
You also don't need
'targets': 0
. This is used withincolumnDefs
plus you don't want the checkbox in column 0 but in 1. You can remove this line.Kevin
Thanks! Things look good now.