Help with colum render please
Help with colum render please
I am using datatables and would like to over-ride the contents of a cell depending on the value it contains. I am using '1' to flag true in the underlying database and '0' for false. I am attempting to use the Columndefs render function to do this.
Here is my code..
xample_table = $('#treatment_list').DataTable(
{
select: true,
destroy: true,
"order": [ 0, 'desc' ],
data:json,
columns : [
{'data':'treatment_name'},
{'data':'description'},
{'data':'measured_in'},
{'data':'exclusive'}
],
"columnDefs": [
{
"targets":3,
"data" : "exclusive",
"render": function ( data, type, row ) {
if (type === 'display'){
if (row.exclusive == '0')
{
return 'No';
}
else
return 'Yes';
}
}
}
]
}
);
The problem is I get an erro message from datatables that reads..
DataTables warning: table id=treatment_list - Requested unknown parameter 'exclusive' for row 0, column 3....
Apart from the error message, it is in fact working. If anyone can help, I would be very grateful.
Many thanks.. Dave.
Answers
With
columns.render
you always need to return something. Iftype
is unequal todisplay
you aren't returning anything. Addreturn data;
to line 27 after the if statement.Kevin
@starcmr We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
@starcmr - I just noticed you spammed here too - please note you'll be banned if you do that again...
Colin