I'm using DataTables to populate a table with results from a JSON request.
$.ajax({
type: "POST",
contentType: "application/json;",
...,
success: function(data){
var dataTblValues=$('#someTable').dataTable({
"aaData": data.someList,
"aoColumns": [
{
// Date
"mData": "date"
},
{
// Severity (I want some HTML output here depending on the severity)
"mData": "severity"
},
{
// Type
"mData": "type"
},
],
"columnDefs" :[
{
"targets": 3,
"data": null,
"defaultContent": '<a href="#">Some link</a>'
}
]
});
},
error: function(data){
console.log(data);
},
});
The value of the second column ("Severity") is numeric, such as 1 or 2. Instead of just populating the value (1, 2 etc) directly in the column, I want to output something like:
<div class="severity-one">High</div>
...or
<div class="severity-two">Medium</div>
...depending on the severity.
How do I do this?
for column 2 "severity"
"columnDefs" : [
{
"targets" : 1, // 1 because column count in dt starts from 0.
"render" : function(data, type, row) {
if(data==1)
{
return "<div class='severity-one'>High</div>"
}
if(data==2)
{
return "<div class='severity-two'>Medium</div>"
}
}
}
]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments