table.data after table.ajax.reload(); shows data from before the reload

table.data after table.ajax.reload(); shows data from before the reload

mrd05dmrd05d Posts: 45Questions: 6Answers: 3

I am using DataTables and the TableTools extension. Im using an ajax button to send selected rows to be deleted from the db. On success i am using table.ajax.reload();. Then after I am trying to see if the result set is empty or not if it is i want to reload the page.

I tried to use table.data() but it is seeing what was in the table prior to the reload not after?

This question has an accepted answers - jump to answer

Answers

  • mrd05dmrd05d Posts: 45Questions: 6Answers: 3
    edited June 2015

    So i decided to attach an xhr event handler instead of waiting for the table to reload in order to then try and evaluate for empty.

    This works well:

     table = $('#example').on('xhr.dt', function ( e, settings, json ) {
                                if ("data" in json) {
                                    if (json['data']===""){
                                        location.reload();
    
                                    }
                                }
                                
    
    
                            } ).DataTable( {
                            "processing": true,
                            "serverSide": false,
                            "lengthMenu": [[10,15, 20, 30, -1], [10, 15,20, 30, "All"]],
                            "pageLength":15,
    ...
    
  • allanallan Posts: 61,920Questions: 1Answers: 10,153 Site admin
    Answer ✓

    That is the correct thing to do :-). The other option is to use initCallback at initialisation time, or the callback for reload.ajax() if you are using that method.

    Allan

This discussion has been closed.