【发布时间】:2017-05-31 10:19:56
【问题描述】:
我正在尝试制作一个条件语句,它不仅将数据替换到我的目标列,而且还会根据所选目标的值替换第二个列。
setTimeout(function() {
$('#invoices-table').DataTable({
responsive: true,
columnDefs: [{ orderable: false, targets: [-1, -2, -3] }, {
targets: 0, // statement is based on first column data
render: function(data, type) {
// if data in col0 is "1" then replace data in col0 and col5 (pay button)
if (type == 'display' && data == '1') {
return [
{ data: '<i class="fa fa-3 fa-check-circle-o datatable-paid-1"></i>', target: 0 },
{ data: '<button class="pay-btn btn btn-sm btn-success disabled">Paid</button>', target: 5 }
]
} else {
return [
{ data: '<i class="fa fa-3 fa-exclamation-circle datatable-paid-0"></i>', target: 0 }
]
}
},
}],
"lengthMenu": [
[100, 5, 25, 50, -1],
[100, 5, 25, 50, "All"]
],
dom: 'Bfrtip',
initComplete: function() {
var api = this.api();
// my actions upon complete
}
});
}, 1500); // delay is needed due to needed time of mySQL for passing results
编辑
由于目标编号错误,更新了 post 和 codepen 上的代码
【问题讨论】:
标签: javascript jquery datatables