DataTables not getting refreshed with change of JSON data thru jQuery ajax()

DataTables not getting refreshed with change of JSON data thru jQuery ajax()

Ajith86Ajith86 Posts: 7Questions: 0Answers: 0
edited October 2012 in DataTables 1.9
I have started using DataTables recently,got stuck with the below mentioned issue
I am populating DataTables using the JSON data thru jQuery ajax(). The data is loaded based on the few dropdown filters. But while changing the filter values the DataTables is not getting refreshed with new values.
This is the code I am using ,
HTML:-
[code]


[/code]
Script:-
[code]
$.ajax({
type : "POST",
url : url,
data:MODEL,
success : function(data)
{
ddTable=$('#ex_table').dataTable({
"aaData" : data.response,
"aoColumns" : [
{ "sTitle": "Col1", "bSortable": true},
{ "sTitle": "Col2", "bSortable": true },
{ "sTitle": "Col3", "bSortable": true },
{ "sTitle": "Col4", "bSortable": true},
{ "sTitle": "Col5", "bSortable": true },
{ "sTitle": "Col6","bSortable": true }],
"bFilter" : false,
"bLengthChange" : false,
"bPaginate" : true,
"bInfo" : true,
"iDisplayLength" : 5,
"bRetrieve":true,
"bDestroy ":true,
"fnInitComplete": function()
{
this.fnAdjustColumnSizing(true);
}
});
}
});
[/code]

Replies

  • allanallan Posts: 63,394Questions: 1Answers: 10,451 Site admin
    Try removing `"bRetrieve":true,` that is checked internally in DataTables before bDestroy . The two are mutually exclusive.

    Allan
  • Ajith86Ajith86 Posts: 7Questions: 0Answers: 0
    I tried removing "bRetrieve":true, but it's still not working
  • Ajith86Ajith86 Posts: 7Questions: 0Answers: 0
    UPDATE:This is now working . I tired something like this,
    [code]
    $.ajax({
    type : "POST",
    url : url,
    data:MODEL,
    success : function(data)
    {
    if (typeof ddTable == 'undefined')
    {
    ddTable=$('#ex_table').dataTable({
    "aaData" : data.response,
    "aoColumns" : [
    { "sTitle": "Col1", "bSortable": true},
    { "sTitle": "Col2", "bSortable": true },
    { "sTitle": "Col3", "bSortable": true },
    { "sTitle": "Col4", "bSortable": true},
    { "sTitle": "Col5", "bSortable": true },
    { "sTitle": "Col6","bSortable": true }],
    "bFilter" : false,
    "bLengthChange" : false,
    "bPaginate" : true,
    "bInfo" : true,
    "iDisplayLength" : 5,

    });
    }
    else
    {
    ddTable.fnClearTable( 0 );
    ddTable.fnAddData(data.response);
    }
    }
    });
    [/code]
    Thanks Allan for your help and time on this. It is appreciated.
This discussion has been closed.