Trying to add rows from json to an existing table... i keep getting ( http://datatables.net/tn/4)
Trying to add rows from json to an existing table... i keep getting ( http://datatables.net/tn/4)
cheetahten2000
Posts: 3Questions: 2Answers: 0
Can't Figure it out....
DataTables warning: table id=lTable - Requested unknown parameter '0' for row 17, column 0. For more information about this error, please see http://datatables.net/tn/4
Console
<table id="lTable" class="testTable dataTable" >
<thead>
<tr>
<th scope='col' class=''>col1</th>
<th scope='col' class='seqCol'>col2</th>
<th scope='col' class='col'>col3</th>
<th scope='col' class='col'>col4</th>
<th scope='col' class='col'>col5</th>
<th scope='col' class='col'>col6</th>
<th scope='col' class='col'>col7</th>
</tr>
</thead>
<tfoot>
<tr>
<th scope='row' colspan='7' class='total'>~Total 14</th>
</tr>
</tfoot>
<tbody>
<tr>
<td> xxx </td>
<td> xxx </td>
<td> xxx </td>
<td title='ccc'>ccc</td>
<td title='ddd'>ddd</td>
<td> xxx</td>
<td> xxx</td>
</tr>
<tr>
...
$('.dataTable').dataTable( {
stateSave: true,
} );
var table = $('#lTable').DataTable();
// var text='{"data" : [' +
// '{"param1":"0.00","param2":"15.00","param3":"0.00","param4":"12","param5":"12","param6":"12","param7":"12"},' +
// '{"param1":"0.00","param2":"15.00","param3":"0.00","param4":"12","param5":"12","param6":"12","param7":"12"},' +
// '{"param1":"0.00","param2":"15.00","param3":"0.00","param4":"12","param5":"12","param6":"12","param7":"12"}]}';
var text='[' +
'{"param1":"0.00","param2":"15.00","param3":"0.00","param4":"12","param5":"12","param6":"12","param7":"12"},' +
'{"param1":"0.00","param2":"15.00","param3":"0.00","param4":"12","param5":"12","param6":"12","param7":"12"},' +
'{"param1":"0.00","param2":"15.00","param3":"0.00","param4":"12","param5":"12","param6":"12","param7":"12"}]';
var response = JSON.parse(text);
console.log(response);
table.rows.add($(response) ).draw();
This discussion has been closed.
Answers
You are adding rows that are objects but you haven't defined them using
columns.data
. Your Datatables configuration is expecting array based data. For more info please see this page:https://datatables.net/manual/data/#Data-source-types
Kevin