datatables ajax重新加载不更新传递的参数

时间:2017-06-15 11:12:35

标签: jquery datatables

使用ajax.relaod不会更新传递给控制器​​的值。 每次进入函数时变量都具有正确的值,但我不确定如何重新加载以查看/接受更新的变量。 我是否每次都需要销毁和重建表格?

if (!$.fn.DataTable.isDataTable('.workorder-table')) {
    $('.workorder-table').DataTable({
        "initComplete": function () {
            hidePleaseWait();
        },
        rowCallback: function (row, data, index) {
            --row classes added here based on data
        },
        columns: [
            { "data": "Facility", "name": "Facility", "title": "Facility" },
            { "data": "ShortDescription", "name": "ShortDescription", "title": "Short Description" },
            { "data": "Created", "name": "Created", "title": "Created" },
            { "data": "Completed", "name": "Completed", "title": "Completed" },
            { "data": "Status", "name": "Status", "title": "Status" }
        ],
        ajax: {
            url: "/Facility/WorkOrderSearch",
            type: "POST",
            data: { status: $('#Status').val(), facilityID: $('#FacilityID').val(), quickView: $('#QuickView').val() }
        },
        -- options here
    });
} else {
    $('.workorder-table').DataTable().ajax.reload(hidePleaseWait);
}

1 个答案:

答案 0 :(得分:5)

如果将data变成可以执行的功能

data: function(data) {
  data.status = $('#Status').val();
  data.facilityID = $('#FacilityID').val();
  data.quickView = $('#QuickView').val();
}

然后,每个请求都会执行此函数,即调用ajax.reload()时。