Error in AG Grid when using valueGetter when defining ColumnDefs

Viewed 1205

First time writing here so apologies if I'm not doing it correctly. I am trying change the value type of a string into an integer when importing values into my AG Grid in React. In order to do this, I created this column header :

 {
    headerName: "calc inline clicks",
    field: "adsetstats_inline_link_clicks",
    aggFunc: "sum",
    valueGetter: params => {
        return parseInt(params.data.adsetstats_inline_link_clicks_0days_ago);
    }
  }

I then run:

this.setState({ rowData })

However, when I run this, React gives me the following error:

Error: ag-Grid: cannot get grid to draw rows when it is in the middle of drawing rows. Your code probably called a grid API method while the grid was in the render stage. To overcome this, put the API call into a timeout, eg instead of api.refreshView(), call setTimeout(function(){api.refreshView(),0}). To see what part of your code that caused the refresh check this stacktrace.

Any idea how to fix this? Nothing I have done seems to work.

Thanks, Gabriel

2 Answers

I had this issue too. The real problem is that the valueGetter is throwing an error, but for some reason that error is swallowed and ag-grid displays this error instead. In your case, you may want to check that params.data is defined before accessing its property.

Use SetTimeout() around the this.setState and put timeout for 100ms. It works

Related