jquery datatable losing fnCreatedCell after on click event
jquery datatable losing fnCreatedCell after on click event
here is a fiddle that shows the problem jsfiddle.net/LkqTU/32602/
if you go to the fiddle you will notice the last column is a link. if you click the checkbox on the first column you lose the link. I would like to keep the link.
I am creating the link in the datatable like so...
{data: 'dept',
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("<a href='Freight_ITN.aspx?scn=" + oData.dept + "' target='_blank'>" + "ITN ENTRY" + "</a>");
}
the onclick event of the checkbox is where I am losing my link (I think)
$('#mytable tbody').on('click', 'input[type="checkbox"]', function (e) {
var active = $(this).prop('checked');
var $row = $(this).closest('tr');
console.log($row);
var record = oTable.row($row).data();
record.active = active;
//console.log(record);
oTable.row($row).data(record).draw(false);
});
I noticed that datatables has a fndrawcallback https://datatables.net//forums/discussion/comment/11260/#Comment_11260 however it appears to be deprecated, and I'm unsure how to use it to get my link back.
This question has an accepted answers - jump to answer
Answers
Use
columns.render
rather thancolumns.createdCell
(or its legacyfnCreatedCell
name).The render function will run every time the cell is updated, while the created will only run once.
Allan