Append % sign with a column if a condition is true
Append % sign with a column if a condition is true
nyt1972
Posts: 3Questions: 2Answers: 0
Hello,
I have the following fields in a table, id, studentname, fathername, discount, ispercent and I want if the column ispercent value is 1 the add a % sign with column discount else not.
I tried the below code it works but the problem is that it duplicate each row
$('#example').DataTable({
destroy: true,
data : data,
columns: [
{ data: "id"},
{data: "studentname"},
{ data: 'fathername'},
{
"data": null,
render: function(data, type, row) {
var disc = row.ispercent == 0 ? row.discount : row.discount+'%';
return disc;
}
},
],
dom: 'Blfrtip',
buttons: [
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5',
],
search: true
});
Please help.
Answers
Yep, your code looks about right - see working example here. There's no reason why it should duplicate the row with
columns.render
. Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.Cheers,
Colin