There are two different situations where there are no rows to display. And I want to change the template each time depending on the situation.
I am updating the overlayNoRowsTemplate
but the template cannot replaced after the grid has been loaded.
Refreshing the grid doesn't refresh the overlayNoRowsTemplate
.
Asked
Active
Viewed 4,636 times
3

Community
- 1
- 1

user3292624
- 180
- 2
- 10
2 Answers
3
You can use Grid API's private methods to do this as follows,
onGridReady(params: any) {
this.gridApi = params.api;
}
In your private method
(this.gridApi as any).gridOptionsWrapper.setProperty('overlayNoRowsTemplate', 'newTemplate');

Rajantha Fernando
- 308
- 4
- 12
-
This solution did not work for me in the case where I am catching a response error and want to use the template to say 'Error retrieving data'. I printed this.gridApi's value after the setProperty() call, and it is modified, but the grid does not refresh with the updated template value (and continues to have the initial template shown). – aspergillusOryzae Jan 05 '22 at 21:04
2
You can handle it dynamically only via own Overlay Component
, cuz overlayNoRowsTemplate
same as other gridOptions
doesn't support dynamic changes.
import { Component } from '@angular/core';
import { INoRowsOverlayAngularComp } from "ag-grid-angular";
@Component({
selector: 'app-no-rows-overlay',
template: `<div class="ag-overlay-loading-center" style="background-color: lightcoral; height: 9%">` +
` <i class="fa fa-frown-o"> {{this.params.noRowsMessageFunc()}} </i>` +
`</div>`
})
export class CustomNoRowsOverlay implements INoRowsOverlayAngularComp {
private params: any;
agInit(params): void {
this.params = params;
}
}
As you can see it's not hard to set up and also, you will be able to access all related things via params.api
and gridOptions.noRowsOverlayComponentParams
.

un.spike
- 4,857
- 2
- 18
- 38
-
It is set overlay on grid init, how to change text after grid load ? – Shailendra Sharma Jun 18 '21 at 12:03