jquery datatable losing fnCreatedCell after on click event

jquery datatable losing fnCreatedCell after on click event

BryanDellingerBryanDellinger Posts: 1Questions: 1Answers: 0

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

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    Answer ✓

    Use columns.render rather than columns.createdCell (or its legacy fnCreatedCell name).

    The render function will run every time the cell is updated, while the created will only run once.

    Allan

This discussion has been closed.