【问题标题】:How do I supply cellEditorParams after ag-Grid has been initialized?初始化 ag-Grid 后如何提供 cellEditorParams?
【发布时间】:2019-11-22 09:08:29
【问题描述】:

这是我在文档和在线讨论中看到的经典示例,用于向单元格弹出列表提供“动态”项目列表。但这并不是真正的动态。所有的值和关系都是提前知道的,并被硬编码到源代码中。

cellEditor : 'agSelectCellEditor';
cellEditorParams: function(params) {
    var selectedCountry = params.data.country;
    if (selectedCountry==='Ireland') {
        return {
            values: ['Dublin','Cork','Galway']
        };
    } else {
        return {
            values: ['New York','Los Angeles','Chicago','Houston']
        };
    }
}

如果我正在经营一项扩展业务,并且我每月将新城市添加到我在不同国家/地区保持公司存在的列表中,该怎么办?我不能每次获得新客户时都给程序员打电话。我需要一种方法在运行时动态地提供这个列表,其中包含一组从应用程序数据库中获取的值 - 提前未知。

这个可以吗?

我在此处记录了我在此方面的失败努力:

How do I Bind ag-Grid Dropdown to Array of Strings whose Values are not Known until Run Time?

如果您能在我的其他询问中在这里或那里帮助我回复,将不胜感激!

【问题讨论】:

    标签: angular ag-grid-angular


    【解决方案1】:

    所以这是解决方案。全面披露 - 我不知道它是如何运作或为什么运作的,但互联网是广泛而深入的,如果你撒网的时间足够长,那么你可以挖掘的东西是没有限制的。我在这里找到了解决方案:

    React and Ag-Grid: populating selectcelleditor through fetch gives 'state' of undefined

    该提示适用于反应网格,但该解决方案对我有用。这是我的解决方案的代码:

    这里是返回值列表的函数,我猜是 json 格式:

    private getCategoryArray() {
        return {
            values: this.Categories
        }
    }
    

    这是如何“绑定”到 ag-Grid 列定义的,以便在运行时动态提供值。这里的关键是cellEditorParams的定义。

        {
            headerName: 'Category',
            field: 'payeeCategory',
            sortable: true,
            width: 100,
            checkboxSelection: true,
            editable: true,
            cellEditor: "agSelectCellEditor",
            cellRenderer: ActiveCellRenderer,
            cellEditorParams: this.getCategoryArray.bind(this)
        },
    

    同样,我不知道它是如何或为什么起作用的。如果您想就其工作原理发表解释,我很乐意为您的解释投赞成票。谢谢!

    【讨论】:

      猜你喜欢
      • 2020-08-13
      • 1970-01-01
      • 2020-08-15
      • 2019-08-23
      • 1970-01-01
      • 2016-05-17
      • 2020-01-03
      • 2019-10-24
      • 2020-06-28
      相关资源
      最近更新 更多