我有一个有角度的ui网格,其中有一列“note”,可以是空白的,也可以是非空白的。我试图创建一个自定义过滤器来过滤空白和非空白。我无法滤除栏中的空白。该列可能包含null、未定义或“”。所有这些在ui网格中显示为空白。
注释列如下:
{
displayName: 'Note',
enableSorting:true,
enableFiltering: true,
enableCellEdit: false,
width: '10%',
field: 'note',
visible: false,
filterHeaderTemplate: '<div class="ui-grid-filter-container" ng-repeat=\
"colFilter in col.filters"><div my-custom-dropdown2></div></div>',
filter: {
options: ['Blanks','Non-blanks'] // custom attribute that goes with custom directive above
}
.directive('myCustomDropdown2', function() {
return {
template: '<select class="form-control" ng-model="colFilter.term" ng-change="filterNotes(colFilter.term)" ng-options="option for option in colFilter.options"></select>',
controller:'NoteController'
};
})
.controller('NoteController',function($scope, $compile, $timeout){
$scope.filterNotes = function(input){
var field = $scope.col.field;
var notes = _.pluck($scope.col.grid.options.data,field);
$scope.colFilter.listTerm = [];
var temp = notes.filter(function(val){if(val && val!=''){return val}});
$scope.colFilter.listTerm = temp;
$scope.colFilter.term = input;
if(input=='Blanks'){
$scope.colFilter.condition = new RegExp("[\\b]");
}
else{
//for Non-blanks
$scope.colFilter.condition = new RegExp($scope.colFilter.listTerm.join('|'));
}
console.log("$scope.colFilter.condition",$scope.colFilter.condition);
// console.log("temp",temp);
}
})
我已经试过了
this