【发布时间】:2018-06-02 05:19:45
【问题描述】:
我正在使用 DataTables 和 jQuery 创建一组复选框,以使用搜索框过滤表格。这在http://www.lynden.com/about/brochures-test.html 完全实现。基本上,当您选择带有复选框的选项时,它将将该选项作为字符串并将其插入 DataTables 搜索框中。它工作得很好,除了在没有任何事先过滤的情况下将输入输入到搜索框中时,不区分大小写的功能直接不起作用,这很奇怪。更奇怪的是,当使用“mi”搜索时,它会拉出三个带有 Dynamic 一词的结果,但会完全忽略 Milky Way 公司类别。有谁知道为什么它可以不区分大小写但忽略大写单词的开头?
$('.dropdown-container')
.on('click', '.dropdown-button', function () {
$('.dropdown-list').toggle();
})
.on('input', '.dropdown-search', function () {
var target = $(this);
var search = target.val().toLowerCase();
console.log(search);
if (!search) {
$('li').show();
return false;
}
$('li').each(function () {
var text = $(this).text().toLowerCase();
var match = text.indexOf(search) > -1;
$(this).toggle(match);
});
})
.on('change', '[type="checkbox"]', function () {
var numChecked = $('[type="checkbox"]:checked').length;
$('.quantity').text(numChecked || 'Any');
});
$(document).ready(function () {
table = $('#brochure').DataTable({
"search": {
"caseInsensitive": true
},
"pageLength": 25,
"order": [
[2, "desc"]
],
"lengthMenu": [
[25, 50, 75, -1],
[25, 50, 75, "All"]
],
"columnDefs": [{
"targets": [2, 4, 5],
"visible": false
}]
});
var pID = location.search; //grab everything after and including the "?" in the URL
console.log(pID);
mloc = pID.indexOf("=") + 1; //identify the location of the actual value
pID = pID.slice(mloc) // captures the value of the parameter
table.search(pID, [1, 2, 3, 4], true, false, false, true).draw(); // assigns the parameter to the hidden input tag's value
})
function filter() {
//build a industry string
var filters = $('input:checkbox[name="filter"]:checked').map(function () {
return this.value;
}).get().join(' ');
console.log(filters);
//now filter in column 3, with a regular expression, no smart filtering, no inputbox, not case sensitive
table.search(filters, [1, 2, 3, 4], true, false, false, true).draw();
}
我很想在这个问题上得到一些帮助!
【问题讨论】:
标签: jquery filter datatable datatables case-insensitive