Redraw datatables after using ajax to refresh the table content?

前端 未结 9 711
遇见更好的自我
遇见更好的自我 2021-01-30 04:22

I am using Datatables and have a button on the page that refreshes the table using AJAX. To be clear the table isn\'t using an ajax source of data, we are just using ajax to ref

9条回答
  •  误落风尘
    2021-01-30 05:04

    Try destroying the datatable with bDestroy:true like this:

    $("#ajaxchange").click(function(){
        var campaign_id = $("#campaigns_id").val();
        var fromDate = $("#from").val();
        var toDate = $("#to").val();
    
        var url = 'http://domain.com/account/campaign/ajaxrefreshgrid?format=html';
        $.post(url, { campaignId: campaign_id, fromdate: fromDate, todate: toDate},
                function( data ) { 
    
                    $("#ajaxresponse").html(data);
    
                    oTable6 = $('#rankings').dataTable( {"bDestroy":true,
                        "sDom":'t<"bottom"filp><"clear">',
                        "bAutoWidth": false,
                        "sPaginationType": "full_numbers",
    "aoColumns": [ 
            { "bSortable": false, "sWidth": "10px" },
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null
            ]
    
    } 
    );
                });
    
    });
    

    bDestroy: true will first destroy and datatable instance associated with that selector before reinitializing a new one.

提交回复
热议问题