首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Angular - Smart-table - OR in filter

Angular - Smart-table - OR in filter
EN

Stack Overflow用户
提问于 2015-03-05 21:02:18
回答 2查看 4K关注 0票数 1

我正在使用非常好的Smart-table库来显示我的数据。我已经制作了一个自定义的过滤器指令,允许我为按钮分配过滤器,这样用户就可以很容易地按行状态(即“新建”、“完成”、“失败”等)。这可以很好地工作,但我希望能够复合筛选器,这样我就可以根据state列中包含两个值之一的行进行筛选(例如,“New”和“Failed”)。

我的自定义过滤器看起来像....

代码语言:javascript
复制
app.directive('stCustomFilter', function() {
    return {
        restrict: 'A',
        require: '^stTable',
        scope: true,
        link: function(scope, element, attr, ctrl) {
            var tableState = ctrl.tableState();
            var searchText = attr.stCustomFilter;
            var searchColumn = attr.stCustomFilterColumn;

            element.on('click', function(data) {
                tableState.search.predicateObject = {};
                ctrl.search(searchText, searchColumn);
                //console.log(tableState);
                scope.$apply();
            })
        }
    };
});

并在st-table的标题中使用,如下所示。

代码语言:javascript
复制
<div class="btn-group  btn-group-sm">
    <button st-custom-filter="" st-custom-filter-column="status">All</button>
    <button st-custom-filter="New" st-custom-filter-column="status">New</button>
    <button st-custom-filter="Done" st-custom-filter-column="status">Done</button>
    <button st-custom-filter="Failed" st-custom-filter-column="status">Failed</button>
</div> 

因此,理想情况下,我希望能够通过稍微修改指令在st-custom-filter中使用"New||Failed“之类的东西,但我感觉答案可能在于编写涉及st-pipe方法的更复杂的东西。

有人能提供一两个建议吗?非常感谢。

EN

回答 2

Stack Overflow用户

发布于 2015-03-16 22:37:48

对于默认角度过滤器不支持的OR过滤器,您必须设置一个自定义过滤器,并告诉smart table使用此过滤器来代替默认过滤器

代码语言:javascript
复制
angular.filter('myCustomFilter',function(){
return function(array, predicteObject){
//the predicate object is forwarded by smart table whenever a directive call the search method.. for example :{ myProp1:'myInput1',myProp2:'myInput2
//process the array with your OR logic
}})

然后告诉smart table使用您的自定义筛选器来代替默认筛选器

代码语言:javascript
复制
<table st-table="myCollection" st-set-filter="myCustomFilter"></table>
票数 0
EN

Stack Overflow用户

发布于 2017-01-28 06:26:13

代码语言:javascript
复制
scope.displayClients  = [].concat(scope.clients);
scope.predicates = ['col1', 'col2', 'col3'];
scope.selectedPredicate = scope.predicates[0];

app.filter('myStrictFilter', function($filter){
 return function(input, predicate){
    return $filter('filter')(input, predicate, false);  //false -if contains     string, true if matches string
}})




scope.displayClients  = [].concat(scope.clients);
scope.predicates = ['col1', 'col2', 'col3'];
scope.selectedPredicate = scope.predicates[0];

app.filter('myStrictFilter', function($filter){
    return function(input, predicate){
        return $filter('filter')(input, predicate, false); // true for exact match 
}})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28878509

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档