Bootstrap in Data table master doesn't refresh

2019-08-09 09:43发布

问题:

I'm using data table master with bootstrap.(https://www.datatables.net/manual/styling/bootstrap). When I delete data, i need to refresh that table. But it doesn't work. Only one time it could refresh. Then I have to reload that page. Please help me, and suggest me a good data table for bootstrap. My code is

$("form").on('submit',(function(e) {
    e.preventDefault();

    var id_value= <?php echo $id ?>

    $.post('actions/driver/driver-delete.php',{id:id_value},function(data)
    {
        if(data)
        {           
                $("table").load(location.href + ' table');
                $('#myModal').modal('hide');

        }
    })  

data-table code

<script>
    $(document).ready(function() {
        $('#driver-list').dataTable();
    } );    
</script>

回答1:

First destroy the table after successful your delete operation

datatable.destroy();

then draw the table again

datatable.fnDraw();

or

$("#YortableID").dataTable().destroy();
$("#YortableID").dataTable().fnDraw();