How to Init CellEditor Dynamically with the result of a REST call

橙三吉。 提交于 2019-12-03 00:04:56

问题


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)'];


        },
       ...

        ];

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.

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?

Can you please help me?


回答1:


you can initialize grid settings inside http,

this.http.get(...).subscribe(v=>{
  this.gridOptions = {
    columnDefs: [...]
  };
  this.optionValues=v;
});


来源:https://stackoverflow.com/questions/54535862/how-to-init-celleditor-dynamically-with-the-result-of-a-rest-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!