Adding a select box with row.add
Adding a select box with row.add
bbrindza
Posts: 316Questions: 73Answers: 1
I am having a problem with adding a select checkbox to my table using row.add. I am getting this error
'DataTables warning: table id=machineTaskTable - Requested unknown parameter '0' for row 0, column 0. '
<table id="machineTaskTable" class="table table-striped table-bordered hover" style="width:100%">
<thead>
<tr>
<th></th>
<th>Task</th>
<th>WO Number</th>
<th>Last PM Date</th>
<th>PM Scheduled</th>
<th>PM Type</th>
<th>Next PM Date</th>
<th>PM Interval</th>
<th>Meter Reading</th>
<th>Meter Threshold</th>
</tr>
</thead>
</table>
$('#copyTasksMachineSelectionDialogModal').modal('hide');
machineTaskTable = $('#machineTaskTable').DataTable({
pageLength: 10,
searching: false,
paging: false,
info: false,
ordering: false,
columnDefs: [
{
targets: 0,
checkboxes: {selectRow: true}
}
],
});
var selectedRows = copyMachineTasksTable.rows({ selected: true }).data();
var count = copyMachineTasksTable.rows( { selected: true } ).count();
for ( var i = 0; i < count; i++) {
machineTaskTable.row.add( [
selectedRows[i].null,
selectedRows[i].doc_link,
selectedRows[i].scheduled_pm_number,
selectedRows[i].last_pm_date,
selectedRows[i].pm_scheduled,
selectedRows[i].type_of_pm,
selectedRows[i].next_pm_date,
selectedRows[i].interval_to_next_pm,
selectedRows[i].meter_reading,
selectedRows[i].meter_scheduled_amount,
] ).draw();
};
Answers
Looks like your source table is using object, ie, using
columns.data
. Objects are easier to manage, My suggestion would be to usecolumns.data
in themachineTaskTable
table and just use the following to add the rows:Whether you change to using objects or stick with what you have you will likely need to use
columns.defaultContent
, set it to""
, andcolumns.data
set tonull
for the checkbox column.Kevin