【发布时间】:2021-06-17 02:06:53
【问题描述】:
我有一个包含五列的表: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.
}
});
});
【问题讨论】:
-
This example 可能会给您一些关于实现“大于或等于”过滤器的想法。但是,如果您有多种不同的过滤器要用于不同的列,请查看Search Builder。单击“添加条件”按钮以查看它的实际效果。
-
我已经尝试过您的第一个示例,但是每次启动 table.draw () 时都会启动函数 $.fn.dataTable.ext.search.push (...) ;相反,我希望“大于或等于”过滤器仅在我在 column_D 列中输入值时才起作用但是您的第二个示例已经更有趣了!谢谢
标签: jquery datatables