DataTable not refreshing with new data

DataTable not refreshing with new data

btmbtm Posts: 3Questions: 0Answers: 0

Hi All,

Could use some help.. tried all methods suggested online but cannot make it to work.

After an AJax call, The HTML table is refreshed, but I lose my pagination, sorting and search capabilities from the datatable.
this is my JS code inclusive of the Ajax Call:

<

script>
$(document).ready(function(){
$('#order_table').dataTable();

    $.datepicker.setDefaults({
        dateFormat: 'yy-mm-dd'
    });
    $(function(){
        $("#from_date").datepicker();

    });
    $('#filter').click(function(){
        var from_date = $('#from_date').val();

        if(from_date != '' )
        {
            $.ajax({
                url:"fcheckin.php",
                method:"POST",
                data:{from_date:from_date},
                success:function(data)
                {

                 $('#order_table').DataTable().destroy();
               $('#order_table').dataTable();

               $('#order_table').html(data);



                }
            });
        }
        else
        {
            alert("Please Select Date");
        }
    });
});   

Replies

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    your data is fully formed html rows, not JSON?

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    if it is, reverse DataTable() and HTML() lines

  • btmbtm Posts: 3Questions: 0Answers: 0

    It is fully formed html , I will try the approach, and will let you know!

  • btmbtm Posts: 3Questions: 0Answers: 0

    It worked!!!!

    Thanks a lot!

This discussion has been closed.