How to export actual data after javascript update?

How to export actual data after javascript update?

arny88arny88 Posts: 1Questions: 1Answers: 0
edited November 2018 in Free community support

Hello!
I use DataTable to export spreadsheet to excel and pdf.
My table is updated by Ajax. But without using DataTable. After filtering or paging, non-updated data is exported. Those that were in the table when the page was loaded and the DataTable was initialized.
table.rows (). invalidate ('dom'). draw (); also brings the table to its original form.
table.destroy (); and re-initialization also inserts the original data. I ask for help, I will be very grateful.

My code is:

 <script>
    $(document).ready(function() {
        
         var table;
         init_table();
        
    $('#update_d').on("click", function(){
        
     update_data();
        
    })
        
} );
 
     function init_table(){
         
       setTimeout(function(){ 
       table = $('.datagrid_wrapper > table').DataTable( {
        dom: 'Bfrtip',
        paging: false,
        searching: false,
        bRetrieve: true,
        info: false,
        buttons: [
             'csv', 'excel', 'pdf', 'print'
        ]
    });
   },1000);  
         
     }
     
     function update_data(){
         
     table.rows().invalidate('dom').draw();
         
     }
     
</script>

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @arny88 ,

    That looks fine if the data is being added into the DOM. We're happy to take a look. As per the forum rules, if you could link to a running test case showing the issue we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.