我正在使用组件文件中的 onGridReady 方法从html初始化ag-grid。
I am initialising the ag-grid from the html using an onGridReady method in the component file.
<div style="flex-grow:1;"> <ag-grid-angular style="float:left;width: 100%; height: 201px;margin-top:10px;" class="ag-theme-balham" [gridOptions]="gridOptions" [columnDefs]="columnDefs" (gridReady)="onGridReady($event)" [rowData]="rowData" #grid > </ag-grid-angular> </div>在我正在处理的 .ts 文件中 onGridReady 如下:
In my .ts file i am handling the onGridReady like below :
onGridReady(params?: any) { console.log("onGridReady"); var datasource = { getRows: (params: IGetRowsParams) => { this.info = "Getting datasource rows, start: " + params.startRow + ", end: " + params.endRow; console.log(this.info); this.getRowData().then(data => { if (this.stopApiCalls) { var lastRow = this.allTableData.length; params.successCallback(data, lastRow) } else { params.successCallback(data) } }) } }; console.log(">>",datasource); params.api.setDatasource(datasource); }this.getRowData 用于使用http从后端服务获取数据。
this.getRowData is used to get the data from the backend service using http.
我现在需要重新启动并在不同组件文件中处理的某个事件上使用 onGridReady 。我可以访问我的ag-grid组件中的方法。但是如何从其他组件调用 onGridReady 事件?
I now need to reinitalise and use onGridReady on a certain event handled in a different component file. I am able to access the methods in my ag-grid component. But how can i call the onGridReady event from the other component?
推荐答案gridReady 事件恰好在网格初始化之后发生,所以如果您想要获得动态组件,将需要更复杂的解决方案。
gridReady event occurs exactly after grid initialization, so if you wanna to get dynamic component it would require a more complex solution.
可能的破解:通过带有动态参数的路由器重新渲染视图
possible hack: rerender the view, via router with dynamic parameters
更多推荐
用数据重新填充农业网格
发布评论