简体   繁体   English

jQuery Datatable服务器端重新加载新的发布数据

[英]jQuery Datatable serverside reload with new post data

I have common function for all the server-side data-tables which accepts the table object, url and the post data. 我对所有接受表对象,URL和发布数据的服务器端数据表都有通用功能。 The post data consists of the values from the select boxes that are in the filter area. 过帐数据由过滤器区域中选择框的值组成。

UTIL.serverDatatable = function (table, api, data) {
        var token = "Bearer " + JSON.parse(UTIL.getItemLocalStorage('token'));
        return table.DataTable({
            "processing": true,
            "serverSide": true,
            "paging": true,
            "ajax": {
                url: api,
                type: "post",
                beforeSend: function (request) {
                    request.setRequestHeader("Authorization", token);
                },
                "data": data
            }
        });
    };

And another function to reload the datatable 还有另一个功能来重新加载数据表

UTIL.datatableReload = function(table) {
    table.ajax.reload();
};

This worked fine before these functions were made common. 在使这些功能通用之前,此方法运行良好。 The post data was changing when the filters changes and the reload function was called after that. 过滤器发生变化时,后数据发生了变化,之后调用了reload函数。 But now when the data is changed, the post is not getting updated. 但是现在,当数据更改时,帖子不会得到更新。 Is there any solution for this? 有什么解决办法吗? How to post the changed data via the ajax call? 如何通过ajax调用发布更改的数据?

Change the code as below 更改代码如下

UTIL.serverDatatable = function (table, api, callback) {
    var token = "Bearer " + JSON.parse(UTIL.getItemLocalStorage('token'));
    return table.DataTable({
        "processing": true,
        "serverSide": true,
        "paging": true,
        "ajax": {
            url: api,
            type: "post",
            beforeSend: function (request) {
                request.setRequestHeader("Authorization", token);
            },
            "data": callback
        }
    });
};

Then call the util function as below 然后按如下所示调用util函数

UTIL.serverDatatable(tablename, apiname, function(data){
   data.key= $('#input1').val();
});

And then call the function as 然后将函数调用为

UTIL.datatableReload = function(table) {
    table.ajax.reload();
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM