本文介绍了如何在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

Look code in link: http://plnkr.co/edit/UVDWfucjclXl4Ij9Ylm7?p=preview

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

10-19 18:49