var table = jQuery('#datatable-responsive').DataTable({
dom: 'Bfrtip',
lengthMenu: [
[ 10, 25, 50, -1 ],
[ '10 rows', '25 rows', '50 rows', 'Show all' ]
],
ajax: {
url: 'getClients.php',
dataSrc: 'aaData',
method:'POST'
},
columns: [
{ data:'client_name'},
{ data:'client_location'},
{ data:'client_region'},
{ data:'client_remarks'},
{ data:'client_status'}
],
select: true
});
以上javascript用于填充DataTable。我的要求是,我需要添加< label>基于client_status值标记到DataTable行单元格。 如果client_status值为0,那么我需要一个类型标签,如果它是1我需要添加另一个标签。
可以通过ajax json在表填充时将html添加到datatable中吗?
答案 0 :(得分:0)
var table = jQuery('#datatable-responsive').DataTable({
dom: 'Bfrtip',
lengthMenu: [
[ 10, 25, 50, -1 ],
[ '10 rows', '25 rows', '50 rows', 'Show all' ]
],
ajax: {
url: 'getClients.php',
dataSrc: 'aaData',
method:'POST'
},
columns: [
{ data:'client_name'},
{ data:'client_location'},
{ data:'client_region'},
{ data:'client_remarks'},
{ data:'client_status',render: function (data, type, full, meta) {
if (data == 'N' ){
return '<label class="bs-label bg-blue">New</label>';
}else if (data =='O'){
return '<label class="bs-label bg-green">On Board</label>';
}else if (data=='I'){
return '<label class="bs-label bg-red">In-Active</label>';
}}
}
],
select: true
});