如何在 ag-grid 单元格编辑器中显示动态值 select

How to show dynamic values in ag-grid cell editor select

我想为 ag-grid 的每一行显示动态下拉选项。

假设每一行的部门可能不同,基于此我计划过滤主题列表(用户可以在下拉列表中选择 select)

这是我的代码:

this.gridOptions.columnDefs = {
            headerName: 'Department',
            field: 'financingCurrency',
            editable: false,                            
            suppressSorting: false,
            cellClass: 'grid-align'
        },

        {
            headerName: 'Subject',
            field: 'subject',
            editable: true,
            cellEditor: 'select',
            filter: 'text',
            cellEditorParams: {
                values: this.subjects;                    
            },
            suppressSorting: false,
            cellClass: 'grid-align'
        }
}

我正在使用带有 Angular 2.

的免费版 ag-grid

有人知道吗?

如果我理解正确的话,您希望能够根据选择的部门在 cellEditor 中具有不同的值。如果这是正确的,那么您可能需要做一些更复杂的处理 cellEditors. Here is a plnkr ,我检查名称是否以 J 开头,如果是这样,那么它允许第三个选项。

请参阅 plnkr for full example, as well as the docs 以确保您在正确的地方获得所有内容 imported/exported。除了文档中的内容之外,以下是对您来说最重要的内容:

agInit(params: any): void {
    if (params.node.data.financingCurrency == 'Your Super Department') {
        subjects = [...super options...]
    } else {
        subjects = [...different options...]
    }
}

agInit 在编辑开始时被调用。 params 有一个复杂的对象,(我建议 console.log() 只是为了查看所有可用的东西)但基本上节点指的是单元格所在的行,数据是该行的数据,并根据您的 colDefs 判断,您可以从 financialCurrency 中获得 Department 的值。

尝试类似的东西:

  {
    headerName: ' MEDICINE NAME ', 
    field: 'medicine',
    cellEditor: 'autoComplete',
    cellEditorParams:params => {
         return  {
          'propertyRendered' : 'name',
          'rowData':  this.medicineList, 
          'columnDefs' : [{headerName: 'Medicine', field:'name'}]
      } 
    } 
  },