Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript DataTables-stateSaveCallback和单击即可激活的其他函数_Javascript_Jquery_Datatables - Fatal编程技术网

Javascript DataTables-stateSaveCallback和单击即可激活的其他函数

Javascript DataTables-stateSaveCallback和单击即可激活的其他函数,javascript,jquery,datatables,Javascript,Jquery,Datatables,如何实现stateSaveCallback/“colReorder”/“buttons”:['colvis']在用户单击按钮时启用 基本上,我需要用户能够编辑数据表,只有当他点击一个编辑按钮和更改时,他按下保存按钮保存。。。如果用户不按“保存”按钮,则不会保存任何更改,如果用户不单击“编辑”按钮,则无法进行任何更改。。。有什么办法吗 目前,我的dataTable有以下代码 $('#resultsTable').DataTable({ "stateSave": true, // "

如何实现stateSaveCallback/“colReorder”/“buttons”:['colvis']在用户单击按钮时启用

基本上,我需要用户能够编辑数据表,只有当他点击一个编辑按钮和更改时,他按下保存按钮保存。。。如果用户不按“保存”按钮,则不会保存任何更改,如果用户不单击“编辑”按钮,则无法进行任何更改。。。有什么办法吗

目前,我的dataTable有以下代码

$('#resultsTable').DataTable({
    "stateSave": true,
    // "serverSide": true,

    // Rows per page
    "lengthMenu": [
        [25, 50, 100, 150, 200, 250, -1],
        [25, 50, 100, 150, 200, 250, "All"]
    ],
    "dom": '<"top"Bfi>rt<"bottom"lp><"clear">', // Show entries on bottom

    // Scrolling table
    "scrollY": 600,        // Constrain the DataTable to the given height
    "deferRender": true,   // Elements will be created only when the are required
    "scroller": true,      // Enable vertical scrolling in DataTables
    "scrollX": true,       // Scroll horizontal
    "colReorder": true,    // Column reordering
    "buttons": ['colvis'], // Enable column visibility button

    // Grouping table
    "columnDefs": [{ "visible": false, "targets": 0 }], // Mades target column hidden // if commented ---> Uncaught TypeError: Cannot read property 'style' of undefined
    "order": [
        [0, 'asc']
    ], // Sorting based on column
    'stateSaveParams.dt': function(e, settings, data) {
        data.search.search = "";
        // table.columns.visible();
    },

    // SaveState
    'stateSaveCallback': function(settings, data) {
        $.ajax({
            'url': 'saveDtableState.php',
            'data': { name: 'resultsTable', 'state': data },
            'dataType': 'json',
            'method': 'POST',
            "success": function() {},
            error: function(xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });
    },
    'stateLoadCallback': function(settings, callback) {
        $.ajax({
            'url': 'loadDtableState.php',
            'data': { name: 'resultsTable' },
            'dataType': 'json',
            'type': "POST",
            success: function(data) {
                callback(data);
                console.log('test: ' + data);
            },
            error: function(xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });
    }
})

或者每次我进行更改时,它都会保存表的状态吗?(我不想那样)。以及如何实施其他事情*有什么建议吗*

问得好。。不幸的是,dataTables的文档非常糟糕
var run = false;
run = true;
table.state.save(run); // runs the state save function

// SaveState
'stateSaveCallback': function (settings, data) {
    if (run == true) {
        $.ajax({
            'url': 'hfdjs.php',
            'data': data,
            'dataType': 'json',
            'method': 'POST',
            "success": function () {},
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });
    }
    run = false;
}
var run = false;
run = true;
table.state.save(run); // runs the state save function

// SaveState
'stateSaveCallback': function (settings, data) {
    if (run == true) {
        $.ajax({
            'url': 'hfdjs.php',
            'data': data,
            'dataType': 'json',
            'method': 'POST',
            "success": function () {},
            error: function (xhr, ajaxOptions, thrownError) {
                console.log(thrownError);
            }
        });
    }
    run = false;
}