我想在jQuery Datatable中添加row.add个条目,并在添加时(或之后,如果添加时不可能),根据内容更改outer <td>
的类.
var mTableROH = $('.mm-table.ROH').DataTable(
{
dom: 'Bfrtip',
"stateSave": true,
}
);
for(let i = 0; i < 10; i++)
{
mTableROH.row.add(
[
(Math.random() * 10).toFixed(2),
(Math.random() * 10).toFixed(2),
(Math.random() * 10).toFixed(2),
(Math.random() * 10).toFixed(2),
(Math.random() * 10).toFixed(2),
(Math.random() * 10).toFixed(2),
(Math.random() * 10).toFixed(2),
(Math.random() * 10).toFixed(2),
]
);
}
mTableROH.columns.adjust().draw();
.color-red{
color: red;
}
color-green{
color: green;
}
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css">
<table id="mm-table-roh" class="table table-striped table-bordered mm-table ROH">
<thead>
<tr>
<th>Value 1</th>
<th>Value 2</th>
<th>Value 3</th>
<th>Value 4</th>
<th>Value 5</th>
<th>Value 6</th>
<th>Value 7</th>
<th>Value 8</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
如何在这样添加新行的同时添加这些类?