简体   繁体   English

如何在 ngoninit 期间在 ag 网格中使用 showLoadingOverlay

[英]How to use showLoadingOverlay in ag grid during ngoninit

I am using ag grid to display table in one of my application.我正在使用 ag 网格在我的一个应用程序中显示表格。 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
    
    
}

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.在您的代码中,您在网格准备就绪时设置行数据,这意味着 ag-grid 将在初始化 API 后立即显示数据,这就是您看不到任何加载的原因。 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.需要注意的一点是,如果可能,ag-grid 会尝试在内部为您处理叠加层,因此您不必在获取数据时调用GridApi.hideOverlay()

Live Demo 现场演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM