【问题标题】:How to filter ng-Table with multiple values in an array.如何使用数组中的多个值过滤 ng-Table。
【发布时间】:2017-05-29 00:50:14
【问题描述】:

我目前正在实现 angular-selectize.js (https://github.com/machineboy2045/angular-selectize) 以添加一个搜索框,该框将接收多个值并根据这些值过滤 ng-Table 中的所有单元格,而无需指定要过滤的列。类似于使用输入创建搜索框并在 ng-repeat 上执行 filter:search 的结果,但改为使用多个值进行过滤。

Plunker:http://plnkr.co/edit/701op5FQ0PRJ5FOlF5Mq?p=preview

【问题讨论】:

    标签: javascript angularjs filter ngtable selectize.js


    【解决方案1】:

    我创建了一个自定义过滤器并且它有效。 笨蛋:http://plnkr.co/edit/701op5FQ0PRJ5FOlF5Mq?p=preview

      .filter('filterSelectize', function($filter){
        return function(cars, multiArray) {
          if(multiArray.length >= 1){
            var filteredCars = cars;
            for(i=0; i < multiArray.length; i++){
              var filteredCars = $filter('filter')(filteredCars, multiArray[i]);
            }
            return filteredCars;
          }
          else {
            return cars;
          }
        }
      })
    

    【讨论】:

      【解决方案2】:

      您也可以使用过滤键 $ 走“官方” ngTable 方式:

      function applyGlobalSearch(){
            var term = self.globalSearchTerm;
            if (self.isInvertedSearch){
              term = "!" + term;
            }
            self.tableParams.filter({ $: term });
          }
      

      https://codepen.io/christianacca/pen/doEbJW?editors=1010

      【讨论】:

        猜你喜欢
        • 2016-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-18
        • 2017-01-24
        • 1970-01-01
        相关资源
        最近更新 更多