Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use showLoadingOverlay in ag grid during ngoninit

I am using ag grid to display table in one of my application. I could not able to see the loading message when data is getting loaded during the application initialization. Below is my code,

ngOnInit() {
    this.gridOptions =
{
    columnDefs: this.columnDefs,
    overlayLoadingTemplate:
'<span class="ag-overlay-loading-center">Please wait while your rows are loading</span>',
    rowData: [],
    enableCellChangeFlash: true,
    onGridReady: function (params)
    {
        params.api.setRowData(this.rowData);
        params.api.showLoadingOverlay();
        
    },
    onFirstDataRendered(params)
    {
        params.api.sizeColumnsToFit();
    },
    defaultColDef: {
        flex: 1,
        minWidth: 100,
        resizable: true,
        headerCheckboxSelection: this.isFirstColumn,
        checkboxSelection: this.isFirstColumn,
      },
      suppressRowClickSelection: true,
      rowSelection: 'multiple',
};


    //var user_from_date = this.fromDate
    
    
}
like image 866
User123 Avatar asked Nov 01 '25 11:11

User123


1 Answers

In your code, you set the row data when the grid is ready, which means ag-grid will show the data instantly after initializing the API, that's why you cannot see anything loading. If you delay a bit, you may see the loading overlay.

onGridReady: function (params)
{
   params.api.showLoadingOverlay();
   setTimeout(() => {
      params.api.setRowData(this.rowData);
   }, 500);
},

A small note is that ag-grid tries to handle the overlay for you internally if possible, so you don't have to call GridApi.hideOverlay() when the data is fetched.

Live Demo

like image 181
NearHuscarl Avatar answered Nov 04 '25 02:11

NearHuscarl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!