Wahyu Artadianto
Wahyu Artadianto

Reputation: 117

how to clear datatable before ajax load from another ajax

need help i have 3 ajax where - data from ajax A have button if click will show ajax B - data from ajax B have button if click will show ajax C problem is when datatable from ajax A if i looking a new search data from ajax B still the OLD how to clear data from ajax B dan C before ajax A load this my code for ajax A :

<script type="text/javascript">
var save_method; //for save method string
var table; //for ajax A
var table2; // for ajax B
var table3;  // for ajax C
var base_url = '<?php echo base_url()?>';
   // table2 = $('#table_id2').clear();
  //  table2 = $('#table_id2').rows.add(response.data);
  //  table2 = $('#table_id2').draw();
    $(document).ready(function() {
    //datatables
    table = $('#table_id').DataTable({         
        "lengthMenu": [[5, 10, 25, -1], [5, 10, 25, "All"]],
        "deferLoading": 0,
        "processing": true, //Feature control the processing indicator.
        "language": {
            "processing": "<span><img src='images/Preloader_3.gif'/></span>"
            }, // you can put text or html here in the language.processing setting.            
        "serverSide": true, //Feature control DataTables' server-side processing mode.
        "order": [], //Initial no order.
        // Load data for the table's content from an Ajax source
        "ajax": {
            "url": "<?php echo base_url('infoemployee/ajax_list')?>",            
            "type": "POST",
        },      
        //Set column definition initialisation properties.
        "columnDefs": [
            {
                "targets": [ -1 ], //last column
                "orderable": false, //set not orderable
            },                  
        ],
    }); });

Upvotes: 1

Views: 2324

Answers (1)

Ivan Barayev
Ivan Barayev

Reputation: 2055

After this block

    "ajax": {
        "url": "<?php echo base_url('infoemployee/ajax_list')?>",            
        "type": "POST",
    }, 

add this above line

"destroy" : true,

Upvotes: 2

Related Questions