【发布时间】:2017-10-30 13:32:55
【问题描述】:
我想在我的树表中实现一个搜索过滤器。我正在使用 JQuery treetable 库,这是我到目前为止所做的,但它似乎没有工作。有人知道为什么吗?
这是我的 HTML:
<table id="example">
<tbody>
<thead>
<tr>
<th>Tree data</th>
</tr>
<input class="search" placeholder="Search" />
<p class="log"></p>
</thead>
</tbody>
这是我为搜索过滤器实现的功能:
var $rows = $('#example tr').treetable({expandable: true});
$('#search').keyup(function() {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$rows.show().filter(function() {
var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(val);
}).hide();
});
【问题讨论】: