DataTables - columns.render
DataTables Examples
by snavarro81
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.js"></script>
<table class="display" id="example">
<thead>
<tr>
<th>Information</th>
<th>Link</th>
<th>Id</th>
</tr>
</thead>
</table>
JavaScript
var tabla = null;
$(document).ready( function () {
var responseObj = [
{ "information": "A1", "weblink": true, "id":"433434"},
{ "information": "A2", "weblink": false, "id":"43334" },
{ "information": "A3", "weblink": true , "id":"444"},
{ "information": "A4", "weblink": true , "id":"555"}
];
tabla = $('#example').dataTable({
"data": responseObj,
"bDestroy": true,
"deferRender": true,
"columnDefs": [
{
"data": "information",
"targets": 0
},
{
"data": "id",
"targets": 2
},
{
"data": "weblink" ,
"targets": 1,
"render" : function(data, type, row, meta){
if(type === 'display'){
if (data){
return $('<span class="glyphicon glyphicon-ok">')
.wrap('<div></div>')
.parent()
.html();
}
else
{
return $('<span class="glyphicon glyphicon-ban-circle">')
.wrap('<div></div>')
.parent()
.html();
}
} else {
return data;
}
}
}
]
});
} );