2014-11-21 50 views
0

我一直在努力獲得一個表來重新加載基於ajax url的新數據。fnRedraw&fnReloadAjax不會刷新數據表

我得到表正確加載第一次,但我無法讓它刷新。

$(function() { 
    var datepicker = $("#date-picker"); 
    var table = $("#reports1").dataTable({ 
     sPaginationType: "full_numbers", 
     bJQueryUI: true, 
     ajax: "http://" + window.location.host + "/admin/update_reports/" + datepicker.val(), 
     bProcessing: true, 
     columns: [ 
      { 
       sTitle: "User", 
       data: "user_email" 
      }, 
      ... 
      { 
       sTitle: "Not Interested", 
       data: "notinterested" 
      } 
     ] 
    }); 
    datepicker.datepicker({ 
     dateFormat: "yy-mm-dd" 
    }).attr('readonly','readonly').css("background","white").on('change', function(){ 
     alert("Date changed to " + datepicker.val()); 
     table.ajax.reload(); 
    }); 
}); 

我做第二次得到警報,所以我知道它會遠遠

我想這alert('Data source: ' + table.ajax.url());

,並得到這個錯誤TypeError: table.ajax is undefined

回答

0

這裏是FIX:

var source = "http://" + window.location.host + "/admin/update_reports/" + datepicker.val() 
table.api().ajax.url(source).load(); 
+0

去做正確的方法的時間拉新的日期很簡單:'table.fnDraw()' – markpsmith 2014-11-24 09:41:13

+0

fnDraw()不不更新Ajax URL。它必須是table.api()。fnDraw除非我將dataTable更改爲DataTable – 2014-11-24 17:02:03

+1

確實,您必須使用'fnServerParams'來傳遞日期值。 – markpsmith 2014-11-24 17:03:39

0

也許改變datepicker.val()

ajax: "http://" + window.location.host + "/admin/update_reports/" + datepicker.val(),

不存在!

+0

不應該是每次調用 – 2014-11-21 16:40:04