2016-12-05 34 views
0

我使用datatable插件並希望通過ajax刷新表。我讀過here以使我的ajax返回表中顯示,但它不起作用。這裏是我的html代碼:通過ajax和json重新加載數據表

<button type="button" onclick="rld()">test</button> 
<table id="sample_1"> 
     <thead> 
      <tr> 
      <th> 1 </th> 
      <th> 2 </th> 
      <th> 3 </th> 
      </tr> 
     </thead> 
</table> 

我的Java功能:

我不能得到的是什麼問題。有沒有警報,但在控制檯我得到TypeError:f是undefined 和TypeError:c是undefined 我不知道爲什麼導致我的json返回是正確的(在[JSONLint] [3]中檢查)。 在此先感謝。

+0

http://stackoverflow.com/a/33651126/244811? – sweaver2112

+0

您使用的是哪個版本的數據表? – Kisaragi

+0

table.api()。ajax.reload(null,false); https://datatables.net/reference/api/ajax.reload() –

回答

0

謝謝大家的關注:) 發現我沒有調用數據時返回的json和json字段的名稱不等於列數據字段名稱。所以做這個調整:

function reload_table(){ 
var table = $('#sample_1').DataTable(); 
    table.destroy(); 
    var table = $('#sample_1').DataTable({ 
     "processing": true, 
     "dataType": 'json', 
     ajax: '<?php echo site_url('admin/relaod_table'); ?>', 
     deferRender: true, 
     columns: [ 
      { data: 'user_firstname' }, 
      { data: 'user_lastname' }, 
      { data: 'user_status' }, 
      { data: 'user_created_date' }, 
     ], 
     dom: 'Bfrtip', 
     buttons: [ 
      { 
       text: 'Reload table', 
       action: function() { 
        table.ajax.reload(); 
       } 
      } 
     ] 
    }); 
} 
相關問題