Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ag-Grid - serverside row model params.failCallback

Tags:

We're using the enterprise server side row model to fetch data from the server. We've implemented the IServerSideDatasource and, if the server errors, we call params.failCallback as recommended.

However, nothing happens on the grid. The loading spinner still is visible and there's no notification to the user about anything going wrong.

The 'onRowDataChanged' event fires, but it has no information about the status of the event.

Is there a recommended way to notify the user about the failure? Ideally I'd like to deal with this through ag-grid events rather than throw my own errors from the IServerSideDatasource or even the http client.

Is this possible?

like image 324
Lee Avatar asked Jun 21 '18 16:06

Lee


1 Answers

I'm using a custom eventListener to catch failCallback calls and it works pretty well

In my main class:

onGridReady = params => {
    this.gridApi = params.api;
    this.gridApi.addEventListener('failCallback', this.onServerFailCallback);
    this.gridApi.setServerSideDatasource(MyRemoteDataSource);
 };

onServerFailCallback = params => {
    console.error('onServerFailCallback', params); 
 }

In MyRemoteDatasource:

class MyRemoteDatasource{
    getRows(params) {
        fetchData(params).then(
        response => {     
            params.successCallback(response.data);
        }, 
        error => {    
           params.failCallback();
           params.parentNode.gridApi.dispatchEvent({
               type: 'failCallback',
               api: params.parentNode.gridApi,
               columnApi: params.parentNode.columnApi,
               error: error
           });
        });
    }
}

output:

onServerFailCallback, {type: "failCallback", api: GridApi, columnApi: ColumnApi, error: Error: Error inside fetchData() at stack trace…}

like image 116
SMarello Avatar answered Sep 28 '22 18:09

SMarello