jQuery DataTables Editor:避免在内联编辑后重新加载表



我使用数据表编辑器插件(https://editor.datatables.net/(在内联模式下编辑带有远程数据的表(https://datatables.net/examples/data_sources/server_side.html https://editor.datatables.net/examples/inline-editing/simple.html(

在编辑、提交某些字段并返回来自编辑器服务器处理程序的响应后,表始终完全重新加载,向服务器发送额外的 AJAX 请求,即使不需要这样做,因为只更改了一行中的一个字段,并且重绘表行所需的所有数据已在上一个内联编辑响应中收到。

所以问题是是否有可能摆脱额外的 AJAX 调用并仅重绘编辑的行,而不是完全刷新整个表。

负责重新加载的代码段是:

// dataTables.editor.js
Editor.prototype._submit = function ( successCallback, errorCallback, formatdata, hide )
{
...
    // Submit to the server (or whatever method is defined in the settings)
    this._ajax(
        submitParams,
        function (json) {
        ...
            // the following line forces the table to completely reload
            that._dataSource( 'commit', action, modifier, json.data, store );
        ...
        }
    )
...
}

以下是Datatables Forum的答案:

是的,

您可以在表单选项对象中将drawType选项设置为none(例如,传递给inline((的第二个可选参数(。这将阻止 DataTables 执行重绘(在涉及 Ajax 请求的服务器端处理的情况下(。这确实意味着由数据更改引起的任何排序或筛选更改都不会立即显示。
艾伦

尝试使用状态保存:truehttps://datatables.net/reference/option/stateSave

$(document(.ready(function(( {

        var table = $('#table_name').DataTable(
            {
                columnDefs: [{
                    orderable: false,
                    targets: [0, 1, 8, 9]
                }],
              ,
               stateSave: true,
                "lengthMenu": [[10, 50, 100, 500, -1], [10, 50, 100, 500, "all"]]
            }
         )
    });

最新更新