javascript - Angularjs - Angular UI 网格 : It's possible to filter dynamically dropdown options by rowentity values?

标签 javascript html angularjs angular-ui-grid

我正在尝试使用 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与基本代码。

最佳答案

希望这对你有用,并随时接受它:

Working Plnkr

  1. 设置模板:

    editableCellTemplate: 'dropdown.html'
    
  2. 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>
  1. 测试:

enter image description here

关于javascript - Angularjs - Angular UI 网格 : It's possible to filter dynamically dropdown options by rowentity values?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38611160/

相关文章:

javascript - 如何停止 MVC RedirectToRouteResult JavaScript?

javascript - 通过单击关闭模式弹出窗口

javascript - Angular 指令不适用于点击事件

javascript - AngularJS - 如何获取 ng Repeat 过滤器结果引用

javascript - 仅在 IE 浏览器中发生 Angular 语法错误

javascript - 将 node-sass-json-importer 集成到 Angular CLI 应用程序中

javascript - 我在哪里可以找到 JSHint 数字错误代码的列表?

html - Scala HTML 解析器对象的使用

html - 停止 DIV 相互移动

javascript - 使用我自己的 javascript 功能包装第 3 方 Web 应用程序