如何在ui-grid中过滤多个值?(angularjs) [英] How to filter with multiple values in ui-grid? (angularjs)

查看:27
本文介绍了如何在ui-grid中过滤多个值?(angularjs)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个过滤器,为过滤器传递多个值,但只有一个返回值.

I'm trying to make a filter with passing multiple values for the filter but have only a single return.

field: 'name',
    filter: {
       condition: function(searchTerm, cellValue) {
        var strippedValue = (searchTerm).split(';');
        //console.log(strippedValue);
        for (i = 0; i < strippedValue.length; i++){
          if (cellValue.indexOf(strippedValue[i]) == -1)
            return false;    
          return true;
        }
        //return cellValue.indexOf(strippedValue) >= 0;
      }
    }, headerCellClass: $scope.highlightFilteredHeader

在此处找到测试代码 http://plnkr.co/edit/UVDWfucjclXl4Ij9Ylm7?p=preview

推荐答案

已解决,我也做了一些调整以改进代码.

Resolved, I made some adjustments to improve the code as well.

 condition: function(searchTerm, cellValue) {
    var separators = ['-', '/', ':', ';', ','];
    var strippedValue = searchTerm.split(new RegExp(separators.join('|'), 'g'));
    var bReturnValue = false;
    //console.log(strippedValue, "teste");
    for(iIndex in strippedValue){
        var sValueToTest = strippedValue[iIndex];
        sValueToTest = sValueToTest.replace(" ", "");
        if (cellValue.toLowerCase().indexOf(sValueToTest.toLowerCase()) >= 0)
            bReturnValue = true;
    }
    return bReturnValue;
}

在链接中查看代码:http://plnkr.co/edit/UVDWfucjclXl4Ij9Ylm7?p=preview

这篇关于如何在ui-grid中过滤多个值?(angularjs)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆