我试图使用一个搜索栏和名为“Description”的列中的另一个搜索栏搜索“部件编号”和“内部引用”:

就在我尝试在html中使用这个时侯:
...
<th class="code">Part Number</th>
<th class="keyword">Description</th>
<th class="code">Internal Reference</th>
...这一点在.js中是:
$('#keyword-search').keyup(function() {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
oTable.columns('.keyword').search('^' + val, true, false).draw();
});
$('#code-search').keyup(function() {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
oTable.columns('.code').search('^' + val, true, false).draw();
});我希望能够在“部件编号”或“引用”列中搜索,但不能同时在这两个列中搜索,只是为了显示表达式存在于第一列或第二列中的列。
我需要解决这个问题,我尝试了不同的方法,但我找不到解决办法。
编辑1:我希望得到这样的最终结果:

但是该搜索不起作用,没有最终的过滤结果,这两列之间存在冲突,因为它同时在‘部件号’和列‘内部引用’中搜索'NUM1‘。我的意思是,它所做的代码是和搜索,而不是或搜索,这就是我想要的。
发布于 2016-12-02 08:40:28
与此类似的东西应该能发挥作用:
$('#keyword-search').keyup(function() {
var searchText = $(this).val().toLowerCase();
$.fn.dataTable.ext.search.push(function(settings, data, dataIndex) {
//Assuming part number and internal reference are 1st and 3rd columns
if((~data[0].toLowerCase().indexOf(searchText)) || (~data[2].toLowerCase().indexOf(searchText))) {
return true;
}
return false;
}https://stackoverflow.com/questions/40927162
复制相似问题