数据表-如何停止按数据表中的隐藏字段进行搜索

时间:2018-10-25 07:17:22

标签: jquery search datatables hidden searchable

我有html表,并且在页面加载后添加了datatable类。这里我也有一些隐藏的列。我想防止按隐藏字段搜索。我使用“可搜索”,但无法正常工作。以下是我添加数据表的函数。

function xData() {
    var object_id = document.getElementsByName('object_id')[0].value;
    var object_type = document.getElementsByName('object_type')[0].value;
    var process_id = document.getElementsByName('process_id')[0].value;
    var repeaterControlId = 00202;
    dataTableReload_X = jQuery('#xData').DataTable({
        "orderClasses": false,
        "lengthChange": false,
        "autoWidth": false,
        colReorder: false,
        dom: 'lfrtip',
        "bSort": false,
        responsive: true,
        fixedColumns: true,
        "bProcessing": true,
        "bServerSide": true,
        "iDisplayLength": 10,
        "ordering": true,

        "sAjaxSource": "/test.pl",
        "fnServerData": function (sSource, aoData, fnCallback, oSettings) {

            aoData.push({ "name": "object_id", "value": object_id });
            aoData.push({ "name": "object_type", "value": object_type });
            aoData.push({ "name": "process_id", "value": process_id });
            aoData.push({ "name": "control_id", "value": repeaterControlId });

            jQuery.getJSON(sSource, aoData, function (json) {
                var newJson_imprtdData = {};
                newJson_imprtdData.recordsFiltered = json.rowCount;
                newJson_imprtdData.recordsTotal = json.rowCount;
                newJson_imprtdData.data = [];
                for (var i = 0; i < json.rowData.length; i++) {
                    var dummy = [
                        json.rowData[i]["test_ID"],
                        json.rowData[i]["test_Category_ID"],
                        json.rowData[i]["test_Category_Name"],
                        json.rowData[i]["test_Val"],
                        json.rowData[i]["test_Owner"],
                        json.rowData[i]["test1"],
                        json.rowData[i]["test2"]
                    ];
                    newJson_imprtdData.data.push(dummy);
                }
                fnCallback(newJson_imprtdData);
            });
        },

        "drawCallback": function () {
            jQuery('#xData tbody tr').on('click', function () { editX(this) });
            jQuery("#xData").removeClass("dataTable");
            discardEdit();
            jQuery('#btnAddEdit').removeAttr("disabled");
        },

        "columnDefs": [
            { "searchable":false, "targets": [0,5,6] }, 
            { className: "hiddenItems", "targets": [0,5,6] }, 

        ],

        "language": {
            "emptyTable": "No records found",
            "processing": "Wait...."
        },
    });
}

以下几行有问题吗?

"columnDefs": [
    { "searchable":false, "targets": [0,5,6] }, 
    { className: "hiddenItems", "targets": [0,5,6] }, 
],

0、5、6字段被隐藏。但是仍然使用0个字段数据进行搜索。

1 个答案:

答案 0 :(得分:0)

您是否正在使用旧版本的DataTables?如果是这样,请尝试:

"aoColumnDefs": [
          { 'bSearchable': false, 'aTargets': [ 0,5,6 ] }
       ]