How can I dynamically add a row that contains HTML elements?
How can I dynamically add a row that contains HTML elements?
Hello,
I'm adding a new entry to my database with AJAX and then adding it to the datatable like this:
let href = $('<a href="/an/amazing/url" class="btn btn-light-danger"><i class="bx bx-trash"></i>'<span>Delete</span></a>');
$(table).DataTable().row.add([
data.id,
data.name
href
]).draw();
The row is added successfully.
My problem is with the "href" element. Instead of rendering as an HTML element, only the URL is displayed in plain text. How can I rend the whole "href" as HTML?
Answers
Could make sense to use defaultContent in this case:
https://datatables.net/reference/option/columns.defaultContent
That works.