I can't add Column
I can't add Column
Hi,
I am working on a dataTable with three data columns, id, ref and name, so I have this code:
$(document).ready(function () {
$('#Table').DataTable( {
"ajax": $('#Table').data('json'),
"columns": [
{
"data": "id"
},
{
"data": "ref"
},
{
"data": "name"
}
],
"deferRender": true
} );
});
But as soon as I try adding a column for an edit button just like in the example here, it doesn't work anymore: https://datatables.net/reference/option/columns.defaultContent
Here is the new code:
$(document).ready(function () {
$('#Table').DataTable( {
"ajax": $('#Table').data('json'),
"columns": [
{
"data": "id"
},
{
"data": "ref"
},
{
"data": "name"
},
{
"data": null,
"defaultContent": "<button>Edit</button>"
}
],
"deferRender": true
} );
});
My json file is just having id, ref and name as properties so maybe it is the problem... But I would rather not change this file,
thanks in advance for your answers!
This question has an accepted answers - jump to answer
Answers
Hi,
Do you get any errors when you add that extra column? Did you add an extra column into your table's HTML (specifically the
thead
)?Allan
Yep, good shot! It was the table's head that I was missing, thanks a lot!