我有一个包含五列的表:A-B-C-D-E
每列都有自己的过滤器。
A、B、C和E列过滤器工作正常。A、B、C具有简单的输入文本搜索,而E具有在两个值之间进行搜索的选择类型。
问题出在D列。D是一个只包含数字的列,搜索规则是:查找搜索输入的等于或大数的所有值。
我该如何构建该过滤器?
这是我的示例代码:
$('#reportstock thead tr').clone(true).appendTo('#reportstock thead');
$('#reportstock thead tr:eq(1) th.input').each(function (i) {
var title = $(this).text();
$(this).html('<input type="text" class=\"form-control\" id="column_' + $(this).text() + '" placeholder=" cerca in ' + title.toLowerCase() + '" />');
$('input', this).on('keyup change', function () {
if ($(this).attr("id") != "column_D") {
if (table.column(i).search() !== this.value) {
table.column(i)
.search(this.value)
.draw();
}
}
else {
//??? find all values equal or major of search input.
}
});
});
发布于 2021-03-20 01:26:36
尝尝这个
if ($(this).attr("id") != "column_D") {
if (table.column(i).search() !== this.value) {
table.column(i)
.search(this.value)
.draw();
}
}
else {
table.column(i).search() >= this.value ) {
table.column(i)
.search(this.value)
.draw();
}
发布于 2021-03-22 17:04:17
对于可能和我有同样问题的后人,我最终决定解决这个问题:
$('#reportstock thead tr').clone(true).appendTo('#reportstock thead');
$('#reportstock thead tr:eq(1) th.input').each(function (i) {
var title = $(this).text();
$(this).html('<input type="text" class=\"form-control\" id="column_' + $(this).text() + '" placeholder=" cerca in ' + title.toLowerCase() + '" />');
$('input', this).on('keyup change', function () {
if ($(this).attr("id") != "column_D") {
if (table.column(i).search() !== this.value) {
table.column(i)
.search(this.value)
.draw();
}
}
else {
table.draw();
}
});
});
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
var min = parseInt($('#column_D').val(), 10);
var stock = parseFloat(data[3]) || 0;
if (isNaN(min) || (min <= stock))
return true;
return false;
}
);
这可能不是最优雅的解决方案,但它是有效的!
https://stackoverflow.com/questions/66712001
复制相似问题