Javascript Angularjs-AngularUI网格:它';是否可以按行实体值动态筛选下拉选项?

Javascript Angularjs-AngularUI网格:它';是否可以按行实体值动态筛选下拉选项?,javascript,html,angularjs,angular-ui-grid,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'

我正在尝试使用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”

我该怎么做?使用
细胞过滤器


使用基本代码。

希望这能为您解决问题,并接受它。它确实:

  • 设置模板:

    editableCellTemplate: 'dropdown.html'
    
  • dropdown.html
    添加到项目中:

  • 
    
  • 测试:

  • 在从KreepN获得解决方案后,我对代码进行了一些升级,因为我在选择一个选项时没有得到行的值

    我在select上添加了
    ui网格编辑下拉列表
    ,这就解决了问题


    再次感谢KreepN提供的解决方案。

    这是一个很好的解决方案!非常感谢。老兄,你多跑了一英里真不错。我也学到了一些东西:)+1
    <select ng-model="MODEL_COL_FIELD" ng-options="item as item.value for
    item in col.colDef.editDropdownOptionsArray | filter : { code:
    row.entity.code}"></select>