我正在使用jQuery DataTables 1.10.9。我想禁用contains
的默认搜索功能并添加equals
。我想添加以下代码:
var oTable = $('.datatable').dataTable();
var oSettings = oTable.fnSettings();
oSettings.aoPreSearchCols[iCol].sSearch = "^\\s*"+'1'+"\\s*$";
oSettings.aoPreSearchCols[iCol].bRegex = false;
oSettings.aoPreSearchCols[iCol].bSmart = false;
以下是我获取上述共享代码的链接:https://www.datatables.net/forums/discussion/4096/filtering-an-exact-match/p1
但是我在这一行收到错误:
oSettings.aoPreSearchCols[iCol].sSearch = "^\\s*"+'1'+"\\s*$";
错误:
无法获取未定义或空引用的属性'aoPreSearchCols
如何解决此错误?
更新
$.ajax({
type: "POST",
url: "Default.aspx/ConvertDatadttoString",
data: '{"appName":"' + appName + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function OnSuccess(response) {
dataObject = eval(response.d);
var oTable = $('#JDatadt').dataTable({
"order": [],
"dom": "Bfrtip",
"buttons": ["csv", "excel", "pdf"],
"columnDefs": [{ "className": "dt-center", "orderable": false, "width": 20 }],
"bInfo": false,
"paging": true,
"processing": true,
"columns": dataObject[0].columns,
"data": dataObject[0].Griddata
});
var oSettings = oTable.fnSettings();
oSettings.aoPreSearchCols[ iCol ].sSearch = "^\\s*"+'1'+"\\s*$";
oSettings.aoPreSearchCols[ iCol ].bRegex = false;
oSettings.aoPreSearchCols[ iCol ].bSmart= false;
},
failure: function Onfailure(response) {
}
});