Yos*_* G. 5 angular ag-grid-angular
这是我在文档和在线讨论中看到的经典示例,用于向单元格弹出列表提供“动态”项目列表。但这并不是真正的动态。所有的值和关系都是提前知道的,并被硬编码到源代码中。
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']
};
}
}
Run Code Online (Sandbox Code Playgroud)
如果我正在经营一家不断扩张的业务,并且每月将新城市添加到我在不同国家/地区保持企业业务的列表中,该怎么办?我不能每次获得新客户时都给程序员打电话。我需要一种在运行时动态提供此列表的方法,其中包含从应用程序数据库中获取的一组值 - 提前未知。
这可以做到吗?
我在这里记录了我不成功的努力:
如何将 ag-Grid 下拉列表绑定到其值在运行时才知道的字符串数组?
如果您能在我的其他询问中在这里或那里帮助我回复,我将不胜感激!
所以这就是解决方案。全面披露——我不知道它是如何或为什么起作用的,但互联网既广泛又深入,如果你撒网足够长的时间,你可以挖掘到的东西是没有限制的。我在这里找到了解决方案:
React 和 Ag-Grid:通过 fetch 填充 selectcelleditor 会给出未定义的“状态”
该技巧适用于反应网格,但该解决方案对我有用。这是我的解决方案的代码:
我认为这是返回 json 格式的值列表的函数:
private getCategoryArray() {
return {
values: this.Categories
}
}
Run Code Online (Sandbox Code Playgroud)
以下是如何将其“绑定”到 ag-Grid 列定义,以便在运行时动态提供值。cellEditorParams 的定义是这里的关键项。
{
headerName: 'Category',
field: 'payeeCategory',
sortable: true,
width: 100,
checkboxSelection: true,
editable: true,
cellEditor: "agSelectCellEditor",
cellRenderer: ActiveCellRenderer,
cellEditorParams: this.getCategoryArray.bind(this)
},
Run Code Online (Sandbox Code Playgroud)
再说一次,我不知道这是如何或为什么有效的。如果您想发布其工作原理的解释,我很乐意为您的解释投赞成票。谢谢!
| 归档时间: |
|
| 查看次数: |
10169 次 |
| 最近记录: |