I have a datatable
that processes everything on the server side:
var table = $("#dt_tasks").DataTable({
destroy: true,
processing: true,
serverSide: true,
"ajax": {
"method": "GET",
"url": 'url'
},
"columns": [ ... ]
});
When the table is empty, I add a record and the table automatically refreshes with the following code:
$("#frmCreateTmTasks").submit(function (e) {
e.preventDefault();
var dataFrm = $(this).serialize();
$.ajax({
url: "url",
data: dataFrm,
method: 'POST',
dataType: 'json',
}).done(function (data) {\
loadTmTasksTable();\
});
});
Now, I have an action button in the table to edit and delete each row.
When I add a record and I want to edit or delete that record, I get the error:
Can not read property '_aData' of undefined
but if I press f5
and reload the page, editing and deleting works.
The code to obtain the data to edit and delete are similar, and here is where the error throws if I do not update the page:
$("#dt_tm_tasks tbody").on("click", "a.edit", function () {
//ACA ESTA EL PROBLEMA!!!!
var data = table.row($(this).parents("tr")).data();
$("#frmEditTmTasks #id_tm_task").val(data.id);
$("#frmEditTmTasks #product").val(data.product);
$("#frmEditTmTasks #event").append('<option value="' + data.calendar.event.id + '" hidden selected> ' + data.calendar.event.event + '</option>');
$("#frmEditTmTasks #calendar").append('<option value="' + data.calendar.id + '" hidden selected> ' + data.calendar.start_date + ' al ' + data.calendar.end_date + '</option>');
});