ui-网格字段返回数组
ui-grid field returning array
Output
你好,
我需要根据位置过滤掉一些公司名称('SB' 或 'CO')。所以我在 ui-grid 中使用了自定义过滤器。它 returns 每个键的全部值,并且仅当它完成映射时。我附上了输出。
Plunker 代码演示:link
使用:Angular - v1.4.2
ui-网格 - 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" >'
};
})
您写道:
var genderHash = {
'CO': ['Navy'],
'CO': ['Army'],
'SB': ['Hp']
};
更改为:
var genderHash = {
'CO': 'Navy',
'CO': 'Army',
'SB': 'Hp'
};
另外请记住,您使用相同的键创建了地图 "CO"
filter: {
condition: function(searchTerm,cellValue) {
if( !searchTerm || searchTerm === '') {
return true;
}
if(searchTerm === 'CO') {
if(cellValue === 'Navy' || cellValue === 'Army') {
return true;
}
}
if(searchTerm === 'SB') {
if(cellValue === 'Hp') {
return true;
}
}
return false;
}
}
我应该在 gridOptions 中使用 filter 参数而不是 cellFilter with Hashmap
Output
你好, 我需要根据位置过滤掉一些公司名称('SB' 或 'CO')。所以我在 ui-grid 中使用了自定义过滤器。它 returns 每个键的全部值,并且仅当它完成映射时。我附上了输出。 Plunker 代码演示:link 使用:Angular - v1.4.2 ui-网格 - 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" >'
};
})
您写道:
var genderHash = {
'CO': ['Navy'],
'CO': ['Army'],
'SB': ['Hp']
};
更改为:
var genderHash = {
'CO': 'Navy',
'CO': 'Army',
'SB': 'Hp'
};
另外请记住,您使用相同的键创建了地图 "CO"
filter: {
condition: function(searchTerm,cellValue) {
if( !searchTerm || searchTerm === '') {
return true;
}
if(searchTerm === 'CO') {
if(cellValue === 'Navy' || cellValue === 'Army') {
return true;
}
}
if(searchTerm === 'SB') {
if(cellValue === 'Hp') {
return true;
}
}
return false;
}
}
我应该在 gridOptions 中使用 filter 参数而不是 cellFilter with Hashmap