Losing sDom buttons and filter after AJAX refresh

Losing sDom buttons and filter after AJAX refresh

anaganag Posts: 48Questions: 2Answers: 7
edited October 2011 in General
I'm using this AJAX call to refresh my table. I know i need to redraw the table some how but not sure what the code would be for the option in my initialization. Appreciate any help, thanks

[code]
$("#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);
});

});
[/code]

Replies

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    The problem with the approach you've got there is that you are destroying the HTML of the old DataTable without telling DataTables (it doesn't have a listener on the DOM to say that the content has changed). What you want to do is use the API methods: http://datatables.net/api . In particular the fnClearTable and fnAddData methods sound like they would be useful here. If you want to destroy the table completely and recreate it then fnDestory is the method you want.

    Allan
  • anaganag Posts: 48Questions: 2Answers: 7
    Thanks this is what i've done and it gives the error "DataTables warning: Added data does not match known number of columns" still losing the pagination and other sdom elements.

    [code]
    $("#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.fnClearTable(0);
    oTable6.fnAddData(data);
    });
    });
    [/code]
  • anaganag Posts: 48Questions: 2Answers: 7
    Is it possible this php code is causing the error about columns. It's used when our table is created and also in the ajax refresh code. Depending on a condition we are setting a div class. But the programmer wrapped the entire td element instead of just running the if else around the div class inside the td.

    [code]
    <?php if($this->actualChange[$ktid] == 0) { ?>
    <?php echo $this->actualChange[$ktid]; ?>
    <?php } elseif($this->actualChange[$ktid] > 0) { ?>
    <?php echo $this->actualChange[$ktid]; ?>
    <?php } else { ?>
    <?php echo $this->actualChange[$ktid]; ?>
    <?php } ?>
    [/code]
This discussion has been closed.