2015-12-14 27 views
1

我正在使用jQuery數據表插件。我正在嘗試獲取記錄計數並基於使用jQuery進行一些HTML操作的計數。jQuery數據表重裝

到目前爲止,我已經使用這個代碼

$('#tb').on('init.dt', function() { 
     var totalRecords = table.page.info().recordsTotal; 
     if(totalRecords != 0) { 
      $('#tb_div').show(); 
      table.columns.adjust().draw(); 
     }else{ 
      $('#tb_div').hide(); 
      $('#no_rec_msg').show(); 
     } 
    }); 

但這init.dt得到公正執行一次,並沒有對table.ajax.reload();工作,將解決這個問題的任何API方法?

回答

1

使用xhr事件代替將在Ajax請求完成時觸發。

$('#tb').on('xhr.dt', function() { 
    var totalRecords = table.page.info().recordsTotal; 
    if(totalRecords != 0) { 
     $('#tb_div').show(); 
     table.columns.adjust().draw(); 
    } else { 
     $('#tb_div').hide(); 
     $('#no_rec_msg').show(); 
    } 
});