Angularjs ui-grid过滤复杂表达式

时间:2016-02-09 11:51:04

标签: angularjs angular-ui-grid

如何过滤复杂的表达式映射,例如" brand.title"。这是我的文件初始化:

$scope.gridOptions2.columnDefs = [
    { field: 'code', displayName: "Code" },
    { field: 'brand.title', displayName: "Brand", resizable: true },
];

过滤器:

$scope.singleFilter = function(renderableRows) {
    var matcher = new RegExp($scope.selectedBrand);
    renderableRows.forEach(function(row) {
        var match = false;
        ['code', 'brand.title' ].forEach(function(field) {
            if (row.entity[field].match(matcher)) {
                match = true;
            }
        });
        if (!match) {
            row.visible = false;
        }
    });
    return renderableRows;
};

代码字段上的Filtring工作正常,但brand.title给出以下错误: TypeError:无法读取属性'匹配'未定义的

1 个答案:

答案 0 :(得分:0)

替代方案是:

$scope.gridOptions2 = {
    columnDefs : [
                  { field: 'code', displayName: "Code", enableFiltering: true },
                  { field: 'brand.title', displayName: "Brand", resizable: true, enableFiltering: true, filter: {
                      term : $scope.term }}
                ],
    onRegisterApi : function(gridApi) {
          $scope.gridApi = gridApi;
    }
};

 $scope.singleFilter = function() {
    $scope.gridApi.grid.columns[2].filter.term = $scope.term;
 };