I am working with datatables and I want to edit and delete data table records
When I do console.log(row) following output I get:
["user1", "Edit"] (index):274 (2) ["user2", "Edit"] (index):274 (2) ["user3", "Edit"] (index):274 (2) ["user4", "Edit"] (index):274 (2) ["user5", "Edit"]
What I want is to get data-id from render: function (data, type, row) which I have used in datatable script and when click on edit button I want to get specific id in alert but I am unable to extract data-id.
My jQuery code:
$.fn.dataTable.ext.errMode = 'none';
var table = $('#catgeory_list').DataTable({
processing: true,
language: {
emptyTable: 'no result found.'
},
columnDefs: [{
visible: true,
targets: 0,
render: function (data, type, full, meta) {
return data;
}
}, {
visible: true,
targets: 1,
render: function (data, type, row) {
console.log(row);
return '<button id="editBtn" class="btn btn-wrang btn-flat edit" name="editBtn" type="button">Edit</button>' + ' <button id="deleteBtn" class="btn btn-danger btn-flat delete" name="deleteBtn" type="button" >Delete</button>';
}
}
],
});
renderoption doesn't seem to do anything for your first column, so may be skipped; formatting padding around buttons with doesn't seem to be a good practice, you may use CSS for that purpose (e.g., like I did in my answer below)