我正在尝试使用 rowEntity 值过滤下拉选项。
$scope.data = [{
'id_a': 1,
'code': 1,
'line': 'Line 1 '
}, {
'id_a': 2,
'code': 2,
'line': 'Line 2'
}, {
'id_a': 3,
'code': 1,
'line': 'Line 3'
}, {
'id_a': 4,
'code': 3,
'line': 'Line 4'
}];
$scope.opts = [{
id: 1,
value: 'A',
code: 1
}, {
id: 2,
value: 'B',
code: 2
}, {
id: 3,
value: 'C',
code: 1
}, {
id: 4,
value: 'D',
code: 1
}, {
id: 5,
value: 'E',
code: 3
}, {
id: 6,
value: 'F',
code: 2
}];
$scope.columns = [{
field: 'line',
enableCellEdit: false,
enableFiltering: false
}, {
field: 'code',
enableCellEdit: false,
enableFiltering: false
}, {
field: 'value',
enableFiltering: false,
width: 500,
editableCellTemplate: 'ui-grid/dropdownEditor',
editDropdownIdLabel: 'id',
editDropdownValueLabel: 'value',
editDropdownOptionsArray: $scope.opts
}];
$scope.gridOptions = {
enableCellEditOnFocus: true,
enableFiltering: true,
onRegisterApi: function(gridApi) {
$scope.gridApi = gridApi;
},
columnDefs: $scope.columns
};
$scope.gridOptions.data = $scope.data;
我想做的是在 editDropdownOptionsArray
中加载一个数组,然后使用一个值动态过滤这个数组。
如果我在“第 1 行”,则只能显示具有相同“代码”值的选项。
在这种情况下,“第 1 行”的代码为“1”,然后下拉选项为“A”、“C”、“D”
我该怎么做?使用 cellFilter
?
Here is a plunker与基本代码。
最佳答案
希望这对你有用,并随时接受它:
设置模板:
editableCellTemplate: 'dropdown.html'
将
dropdown.html
添加到您的项目中:
<select ng-model="MODEL_COL_FIELD" ng-options="item as item.value for item in col.colDef.editDropdownOptionsArray | filter : { code: row.entity.code}"></select>
- 测试:
关于javascript - Angularjs - Angular UI 网格 : It's possible to filter dynamically dropdown options by rowentity values?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38611160/