【发布时间】:2017-09-13 14:09:12
【问题描述】:
嗨, 我需要根据位置(“SB”或“CO”)过滤掉一些公司名称。所以我在ui-grid中使用了自定义过滤器。它仅在完成映射时才返回每个键的整个值。我已经附上了输出。 Plunker 代码演示:link 使用:Angular - v1.4.2 ui-grid - v3.0.7
application.controller('ApplicationController', ['$scope', 'uiGridConstants', 'ApplicationService',
function ($scope, uiGridConstants, ApplicationService) {
$scope.message = "Welcome";
$scope.gridOptions = {
showGridFooter: true,
showColumnFooter: true,
enableFiltering: true
};
$scope.gridOptions.columnDefs = [
{
name: 'company',
field: 'company',
filterHeaderTemplate: '<div class="ui-grid-filter-container" ng-repeat="colFilter in col.filters"><div my-custom-dropdown></div></div>',
filter: {
term: '',
options: [{ id: 'CO', value: 'Navy' }, { id: 'CO', value: 'Army' }, { id: 'SB', value: 'Hp' }]
},
cellFilter: 'mapCompany'
}
];
ApplicationService.getData(function (response) {
if (response) {
$scope.gridOptions.data = response.data;
response.data.forEach(function addDates(row, index) {
var companyName = row.company;
if (companyName === 'Navy')
row.company = 'CO';
else if (companyName === 'Army')
row.company = 'CO';
else if (companyName === 'Hp')
row.company = 'SB';
});
}
else {
$scope.gridOptions.data = null;
}
});
}
])
.filter('mapCompany', function () {
var genderHash = {
'CO': ['Navy'],
'CO': ['Army'],
'SB': ['Hp']
};
return function (input) {
if (!input) {
return '';
}
else {
return genderHash[input];
}
};
})
.directive('myCustomDropdown', function () {
return {
template: '<input ng-model="colFilter.term" >'
};
})
【问题讨论】:
标签: angularjs filter angular-ui-grid ui-grid