我有html表,一旦页面加载,我就会添加数据表类。在这里,我也有一些隐藏的列。我想防止按隐藏字段搜索。我使用了"可搜索",但它不起作用。以下是我添加数据表的函数。
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 字段数据进行搜索。
您是否正在使用旧版本的 DataTables?如果是这样,请尝试:
"aoColumnDefs": [
{ 'bSearchable': false, 'aTargets': [ 0,5,6 ] }
]