如何使用 REST 调用的结果动态初始化 CellEditor
How to Init CellEditor Dynamically with the result of a REST call
我正在开发一个使用 Angular 和 Ag-Grid 的应用程序。
我有一列定义如下:
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)'];
},
...
];
所以一切正常,在编辑模式下,我得到了具有不同选项的组合框('English'、'Spanish'、'French'、'Portuguese'、'(其他)')。
我的问题是我需要获得那些调用 REST WS 的选项。
所以我尝试在我的组件 (optionValues) 中定义一个变量并在 "ngOnInit" 方法中填充它,如下所示:
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');
}
但是没有用,这里有什么问题吗?我必须使用不同的方法吗?
你能帮帮我吗?
您可以在 http 中初始化网格设置,
this.http.get(...).subscribe(v=>{
this.gridOptions = {
columnDefs: [...]
};
this.optionValues=v;
});
我正在开发一个使用 Angular 和 Ag-Grid 的应用程序。
我有一列定义如下:
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)'];
},
...
];
所以一切正常,在编辑模式下,我得到了具有不同选项的组合框('English'、'Spanish'、'French'、'Portuguese'、'(其他)')。 我的问题是我需要获得那些调用 REST WS 的选项。
所以我尝试在我的组件 (optionValues) 中定义一个变量并在 "ngOnInit" 方法中填充它,如下所示:
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');
}
但是没有用,这里有什么问题吗?我必须使用不同的方法吗?
你能帮帮我吗?
您可以在 http 中初始化网格设置,
this.http.get(...).subscribe(v=>{
this.gridOptions = {
columnDefs: [...]
};
this.optionValues=v;
});