Can not read property '_aData' of undefined (Jquery - Datatable)

1

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>');
});
    
asked by Juan Pablo B 12.04.2017 в 16:40
source

2 answers

0

Maybe your problem is that you are not making the request to the server when refreshing for that you can use:

table.ajax.reload();

this uses the same properties that are declared in datatables here more examples

you can also use:

table.ajax.url("URL").load();

it obtains information from the url and replaces the existing one in the table as well as replaces the url set in the properties of datatables here more examples

    
answered by 12.04.2017 в 17:43
0

To refresh a table made with dataTables I do it in the following way: $('#table').DataTable().ajax.reload(); .

Your code would look like this:

$("#frmCreateTmTasks").submit(function (e) {
    e.preventDefault();
    var dataFrm = $(this).serialize();
    $('#dt_tm_tasks').DataTable().ajax.reload();
});
    
answered by 14.04.2017 в 06:31