2014-10-03 5 views
0

데이터 드롭 다운이 처음에 채워지고 데이터 테이블이 표시됩니다. 데이터는 json 배열에서옵니다. 드롭 다운이 변경되면 다시 초기화 오류가 발생하고 수정하는 데 문제가 있습니다.Datatables가 변경 이벤트에서 다시로드됩니다.

나는 table.ajax.reload와 table.fnReloadAjax()를 시도했다. 나는 그들과 함께 가장 큰 것은 아니지만에서 datatables와 함께 작동합니다.

function Population() { 
var table = $('#Population').dataTable(); 

$("#quickStats").change(function() { 

    var optionValue = $("#quickStats").val(); 
    console.log(optionValue); 

    if (optionValue == 1) { 
     $("#display").append('<table cellpadding="0" cellspacing="0" border="0" class="display" id="Population">' +    
     '<thead><tr><th>Demographic</th><th>Total</th></thead>' 
     + '</table>'); 


    $('#Population').dataTable({ 
     "data": usPopulation, 
     "bJQueryUI":true, 
     "columns": [ 
      { "data": "Demographic" }, 
      { "data": "Total" } 

     ], 
    }); 
} 
    table.ajax.reload(); 

}); 
} 

답변

1

새로운 작성하기 전에 이전을 파괴 시도 :이 같은

$('#Population').dataTable().fnDestroy(); 


$('#Population').dataTable({ 
     "data": usPopulation, 
     "bJQueryUI":true, 
     "columns": [ 
      { "data": "Demographic" }, 
      { "data": "Total" } 

     ], 
    }); 

또는 수행

var table = $('#Population').dataTable({ 
      "data": usPopulation, 
      "bJQueryUI":true, 
      "columns": [ 
       { "data": "Demographic" }, 
       { "data": "Total" } 

      ], 
     }); 

table.draw(); 
+0

(가) 테이블보다 더 나은 일을 쳐부 여기

는 코드입니다. 다시 그리기() –

관련 문제