0

In my table, I want to redraw table after delete action is completed.

var table = $(".admin-data-table").dataTable(
     ...
     "drawCallback": function( settings ) { // When the draw is completed:

         $(".delete-confirm-yes").click(
                function(){
                    $.ajax({
                        url: apiDeleteUrl,
                        type: "delete",
                        data: {item_id: itemIdToDelete},
                        success: function(data){
                            $('#delete_confirm').modal('hide');
                            table.ajax.url(url).load();         

I get the following error:

Cannot read property 'url' of undefined

What am I missing?

tolga
  • 2,462
  • 4
  • 31
  • 57
  • `table.ajax.url` <<< here's your issue, it's like doing `undefined.url`. So, therefore `console.log(table.ajax)` or start with `console.log(table)`. You'll fix your own issue in no-time. `table` is a jQuery Element, and as far as I know it has not an `.ajax` property. – Roko C. Buljan Jun 10 '20 at 20:22
  • First, I would recommend to populate your table ***properly***, using [`ajax` option](https://datatables.net/reference/option/ajax). That would make [`ajax` API method](https://datatables.net/reference/api/ajax) available to you. Now, as you're using *external* `.$ajax()` to populate your table, `.ajax` is `undefined`. – Yevhen Horbunkov Jun 10 '20 at 20:26
  • Does this answer your question? [Detecting an undefined object property](https://stackoverflow.com/questions/27509/detecting-an-undefined-object-property) – devlin carnate Jun 10 '20 at 20:27
  • Thanks for your answers. Actually the question is not about javascript "undefined", but dataTable library. Documentation of datatable suggests to apply reload that way. – tolga Jun 10 '20 at 20:28

0 Answers0