In my table I have two fields that are 0 or 1. One of "active" and one is "operative".
So I added this code
"columnDefs": [ {
"targets": 3,
"data": "active",
"render": function ( data, type, row, meta ) {
if (data == 1)
{return '<i class="fas fa-check" style="color:green"></i>';}
else
{ return '<i class="fas fa-times" style="color:red"></i>';}
},
"targets": 4,
"data": "operative",
"render": function ( data, type, row, meta ) {
if (data == 1)
{return '<i class="fas fa-check" style="color:green"></i>';}
else
{ return "";}
}
} ]
which should work OK. The column numbers are correct, but the table only render colum 4. If I remove the definition for column 4 it renders column 3 correctly.
Here is a screenshot of the bit in question:
Here is the full definition of the table
<script type="text/javascript">
$(function () {
var table = $('.data-table').DataTable({
"iDisplayLength": 25,
"lengthMenu": [ [10, 25, 50,100,200, -1], [10, 25, 50,100,200, "All"] ],
columnDefs: [
{
targets: -1,
className: 'dt-right'
}],
processing: true,
serverSide: true,
ajax:"{{ route('AllUsersData') }}",
columns: [
{data: 'name', name: 'name'},
{data: 'email', name: 'email'},
{data: 'company',name: 'company'},
{data: 'active', name:'active'},
{data: 'operative', name: 'operative'},
{data: 'superAdmin', name:'superAdmin'},
{data: 'action', name: 'action', orderable: false, searchable: false},
],
"columnDefs": [ {
"targets": 3,
"data": "active",
"render": function ( data, type, row, meta ) {
if (data == 1)
{return '<i class="fas fa-check" style="color:green"></i>';}
else
{ return '<i class="fas fa-times" style="color:red"></i>';}
},
"targets": 4,
"data": "operative",
"render": function ( data, type, row, meta ) {
if (data == 1)
{return '<i class="fas fa-check" style="color:green"></i>';}
else
{ return "";}
},
"targets": 5,
"data": "superAdmin",
"render": function ( data, type, row, meta ) {
if (data == 1)
{return '<i class="fas fa-check" style="color:green"></i>';}
else
{ return "";}
}
} ]
});
});
</script>
Here is a sample of the returned data from the ajax call:

