如何在Ag-grid单元格编辑器中显示动态值 [英] How to show dynamic values in ag-grid cell editor select

查看:767
本文介绍了如何在Ag-grid单元格编辑器中显示动态值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to show dynamic drop down options for each row of ag-grid.

假设每一行的部门可能有所不同,因此我打算过滤主题列表(用户可以在下拉列表中选择的选项)

Suppose for each row, department might be different and based on that I plan to filter list of subjects (available option for users to select in dropdown)

这是我的代码:

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。

I am using free version of ag-grid with Angular 2.

有人对此有任何想法吗?

Does someone have any idea about it?

推荐答案

如果我正确理解,您希望能够根据所选的部门在cellEditor中具有不同的值。如果正确的话,那么您可能需要处理单元格编辑器。这是我制作的 plnkr ,它检查名称是否以J开头,如果是,则为允许第三个选项。

If I understand correctly, you want to be able to have different values in the cellEditor based on which department is selected. If that is correct, then you will likely need to do something more complicated dealing with cellEditors. Here is a plnkr that I made that checks if the name starts with a J, if so then it allows a third option.

请参考 plnkr 作为完整示例,以及文档,以确保在正确的位置导入/导出所有内容。除了文档上的内容外,这对您来说还有什么重要的重要性:

Please refer to the plnkr for full example, as well as the docs to make sure that you get everything imported/exported in the right places. Here is what is the key importance for you beyond what is on the docs:

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

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

agInit gets called any time editing is started. params has a complicated object, (I suggest console.log()ing it just to see everything that is available to you) but basically the node is referring to the row that the cell is on, and the data is the data for that row, and judging by your colDefs you can get the value of the Department from financingCurrency.

这篇关于如何在Ag-grid单元格编辑器中显示动态值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆