更新时间:2023-12-06 15:58:28
您可以使用 createdRow()检查详细信息单元格(或多个单元格)的内容,并在该单元格不为空的情况下有条件地添加 details-control
类.
You can use createdRow() to check the content of the detail cell (or cells), and conditionally add the details-control
class if that cell is not empty.
例如,它检查 extn
字段是否具有非空值
For example, this checks to see if the extn
field has a non-empty value
$(document).ready(function() {
var table = $('#example').DataTable({
"data": data.data,
"columns": [{
"orderable": false,
"data": null,
"defaultContent": ''
}, {
"data": "name"
}, {
"data": "position"
}, {
"data": "office"
}, {
"data": "salary"
}],
"order": [
[1, 'asc']
],
"createdRow": function(row, data, dataIndex) {
if (data.extn !== "") {
$(row).find("td:eq(0)").addClass('details-control');
}
}
});