2017-02-16 104 views
0

我正努力在订阅observable时刷新ag-grid。Observable订阅刷新ag-grid

我有以下一段代码,效果很好。

 this.marketConfigs = this._regionProductConfigService.getMarketConfig();    
      this.gridOptions.columnDefs = this.createColumnDefs(); 
      this.gridOptions.rowData = this.marketConfigs; 

但因为我试图把在AG-格列下拉,我想列配置,一旦我们收到的数据被创建。所以我改变了以下代码:

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

但它不显示任何东西在网格中。有人可以帮忙吗?

+0

你可以检查是否有draw()方法吗?所以有点像this.gridOptions.draw() –

+0

不,没有draw()方法。理想情况下,this.gridOptions.api.refreshView()应该强制网格重绘自己。 –

回答

0

gridOptions.colDefs和gridOptions.rowData是“只读一次”的属性 - 它们是在网格初始化时读取的,而不是再次查看。

要执行行或列的动态post-init设置,您需要使用API​​。

变化

this.gridOptions.columnDefs = this.createColumnDefs(); 
this.gridOptions.rowData = this.marketConfigs;  

要这样:

this.gridOptions.api.setColumnDefs(this.createColumnDefs()); 
this.gridOptions.setRowData(this.marketConfigs); 

和预期它应该工作。请注意,如果您按照以上所述使用API​​,则不需要调用refreshView - 上述方法将为您执行此操作。

+0

它像魔术一样工作:)谢谢.. –