问题描述
我正努力在订阅可观察项目时刷新ag-grid。
我有以下一段很好的代码。
I have following piece of code which works well.
this.marketConfigs = this._regionProductConfigService.getMarketConfig();
this.gridOptions.columnDefs = this.createColumnDefs();
this.gridOptions.rowData = this.marketConfigs;
但是由于我试图在ag-grid列中添加下拉菜单,因此我希望接收数据后将创建的列配置。因此,我将代码更改为:
But since I am trying to put a drop-down in columns of ag-grid, I wanted the column config to be created once we receive data. So I changed the code to following :
this._refDataService.getAllCurrencies().subscribe(
(data: ICurrency[]) => {
this.financingCurrencies = data;
this.marketConfigs = this._regionProductConfigService.getMarketConfig();
this.gridOptions.columnDefs = this.createColumnDefs();
this.gridOptions.rowData = this.marketConfigs;
this.gridOptions.enableColResize = true;
this.gridOptions.api.refreshView();
},
err => console.log(err)
);
但是它不会在网格中显示任何东西。有人可以帮忙吗?
But it doesnt show any thing in grid. Can someone help?
推荐答案
gridOptions.colDefs和gridOptions.rowData是读取一次属性-在网格初始化时读取而不要再次查看。
gridOptions.colDefs and gridOptions.rowData are "read once" properties - they're read on Grid initialization and not looked at again.
要对行或列进行动态初始设置,您需要使用API。
To do dynamic post-init setting of row or columns, you need to use the API.
更改
this.gridOptions.columnDefs = this.createColumnDefs();
this.gridOptions.rowData = this.marketConfigs;
到此:
this.gridOptions.api.setColumnDefs(this.createColumnDefs());
this.gridOptions.setRowData(this.marketConfigs);
它应该能按预期工作。请注意,如果您按照上述方式使用API,则无需调用refreshView-上面的方法将为您实现。
And it should work as expected. Note if you use the API as per the above you won't need to call refreshView - the methods above will do it for you.
这篇关于在Observable订阅上刷新ag-grid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!