fnRedraw&fnReloadAjax不会刷新数据表

问题描述:

我一直在努力获得一个表来重新加载基于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

这里是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

也许改变datepicker.val()

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

不存在!

+0

不应该是每次调用 – 2014-11-21 16:40:04