fnRedraw& fnReloadAjax不会刷新数据表

时间:2014-11-21 16:29:38

标签: javascript ajax datatables

我一直在努力让表格根据ajax网址重新加载新数据。

我第一次正确加载表格,但我无法刷新它。

$(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

2 个答案:

答案 0 :(得分:0)

也许在第二次改变datepicker.val()

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

不存在!

答案 1 :(得分:0)

以下是FIX:

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