如何使用REST调用的结果动态初始化CellEditor [英] How to Init CellEditor Dynamically with the result of a REST call
问题描述
我正在开发一个使用Angular和Ag-Grid的应用程序。
I'm working on an app that uses Angular and Ag-Grid.
我有一个定义如下的列:
I have a column defined like following:
columnDefs = [
...
{
headerName: 'LANG', field:'lang',
autoHeight: true,cellClass: 'cell-wrap-text',sortable: false, filter: true, editable: true,
cellEditor : 'agSelectCellEditor',
cellEditorParams : ['English', 'Spanish', 'French', 'Portuguese', '(other)'];
},
...
];
所以一切正常,在编辑模式下,我得到了带有不同选项的组合框(英语 ,西班牙语,法语,葡萄牙语,(其他))。
我的问题是我需要获得调用REST WS的那些选项。
So everything works fine and in edit mode, I get the Combobox with the different options ('English', 'Spanish', 'French', 'Portuguese', '(other)'). My problem is that I need to get those options calling a REST WS.
因此,我尝试在Component(optionValues)中定义变量并填充像这样在 ngOnInit方法中:
So I have tried to define a variable in my Component (optionValues) and populating it in the "ngOnInit" method like this:
optionValues : any;
columnDefs = [
...
{
headerName: 'LANG', field:'lang',
autoHeight: true,cellClass: 'cell-wrap-text',sortable: false, filter: true, editable: true,
cellEditor : 'agSelectCellEditor',
cellEditorParams : this.optionValues,
},
...
];
ngOnInit(){
this.optionValues = this.http.get('http://localhost:8002/myservice');
}
但是没有用,这是什么问题?我必须使用其他方法吗?
But it didn't work, what is wrong here? Do I have to use a different approach?
您能帮我吗?
推荐答案
您可以在http内部初始化网格设置,
you can initialize grid settings inside http,
this.http.get(...).subscribe(v=>{
this.gridOptions = {
columnDefs: [...]
};
this.optionValues=v;
});
这篇关于如何使用REST调用的结果动态初始化CellEditor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!