按特定列的角度可调过滤器? [英] Angular-footable filter by specific column?
问题描述
我还没有找到有关如何按特定列过滤的angular-footable文档.但是,在此链接 http://fooplugins.github.io/FooTable/docs/examples/component/filtering.html footable支持按特定列进行过滤.有谁知道用角脚可实现相同的结果吗?
I haven't found on the docs of angular-footable on how to filter by a specific column. However, in this link http://fooplugins.github.io/FooTable/docs/examples/component/filtering.html footable has support to filter by specific column. Does anyone know if it is possible to achieve the same result with the angular-footable?
推荐答案
在互联网上搜索后,我找到了一个代码,并对有角度的工作过滤器的方式进行了一些更改.
After searching through the internet, I found a code and made some changes on the way the filter of angular-footable works.
因此,要按特定的列进行过滤,在我的情况下,要查找与您键入的内容匹配的所有内容,则应将此代码放在控制器中:
So, to filter by specific column and in my case, wants to find everything that matches what you have typed, you should put this code in your controller:
window.footable.options.filter.filterFunction = function(index) {
var $t = $(this),
$table = $t.parents('table:first'),
filter = $table.data('current-filter'),
columns = $t.find('.filterByMe');
var row = $(this).parents('tr:first');
var someColumn = $('td',row)[1];
var regEx = new RegExp("\\b" + filter + "\\b");
var result = false;
for (var i = 0; i < columns.length; i++) {
var text = $(columns[i]).text();
result = text.indexOf(filter) >= 0;
if (result === true)
break;
if (!$table.data('filter-text-only')) {
text = $(columns[i]).data("value");
if (text)
result = text.indexOf(filter) >= 0;
}
if (result === true)
break;
}
return result;
};
columns = $t.find('.filterByMe');
行是您应该在html中放置另一个逻辑的地方.就我而言,我添加了与表的每一列相关的复选框.如果用户在搜索字段上选中了一个复选框,则表示他/她想根据该列/列查找数据.
The line columns = $t.find('.filterByMe');
is where you should put another logic in your html. In my case, I added checkboxes that are related with each column of my table. If the user checks a checkbox on the search field, it means he/she wants to look for data based on that column/columns.
当用户单击复选框时,类 filterByMe 被添加到表的标签<td>
中.
When the user clicks on the checkbox, the class filterByMe is added to the tag <td>
of my table.
这样做,您将可以按特定的列进行搜索.
Doing that, you will be able to search by specific column.
我希望这对那些使用angular-footable并一直希望按特定列进行过滤的人有帮助
I hope this helps anyone who is using the angular-footable and always wanted to filter by a specific column
这篇关于按特定列的角度可调过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!