ag-grid: Cell class & refreshing data causes an internal error

[x] bug report => see 'Providing a Reproducible Scenario'
[] feature request => do not use Github for feature requests, see 'Customers of AG Grid'
[] support request => see 'Requesting Community Support'

When using cell class (I think) or maybe cell style, upon refreshing the data an exception is seen:

ERROR TypeError: Cannot read properties of undefined (reading 'length')
    at CellCustomStyleFeature.applyClassesFromColDef (ag-grid-community.cjs.js:20788)
    at CellCtrl.refreshCell (ag-grid-community.cjs.js:22001)
    at ag-grid-community.cjs.js:22920
    at Array.forEach (<anonymous>)
    at RowCtrl.onRowNodeDataChanged (ag-grid-community.cjs.js:22919)
    at ag-grid-community.cjs.js:1350
    at Set.forEach (<anonymous>)
    at processEventListeners (ag-grid-community.cjs.js:1345)
    at EventService.dispatchToListeners (ag-grid-community.cjs.js:1355)
    at EventService.dispatchEvent (ag-grid-community.cjs.js:1334)

This appears at this code point which was introduced after version 25.3.0:

    if (this.staticClasses.length) {
        this.staticClasses.forEach(function (className) { return _this.cellComp.addOrRemoveCssClass(className, false); });
    }

This should be (this.staticClasses && this staticClasses.length)

My cell definition ends as follows:

cellClass: this.processEditableClass,

I am happy to send through a plunkr, please provide a link if available. This has to be 26.2.0 however of ag-grid.

Current behaviour. When the data is got the second time (upon paging or filtering) using a datasource the error is seen. If I regress to 25.3.0 the error is no longer present. The version in error is 26.2.0

Expected behaviour.

There should be no error and use the trap above to ensure staticClasses aren’t checked.

Environment Angular, NG12 Windows or Linux

  • AG Grid version:*

26.2.0

  • Browser: All browsers show this.

  • Language:

Typescript 4.4.5

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 17 (2 by maintainers)

Most upvoted comments

@VyacheslavAS Appears different to me, as in its different code, but similar train crash antipattern. If you think its a. Issue create a stackblitz with a simple example and link it to a new issue.

Hello!

Thank you for reporting this - much appreciated!

Based on your description we’ve now reproduced this issue as a regression from v26.1

Until this is fixed please use the following workaround - add a return statement with an empty string to cover other potential paths of the cellStyle function, as shown in the following example: https://plnkr.co/edit/QwSn5XrLufuJw1Xx

We have added this bug to our backlog and we are tracking it with the following reference and description: AG-6235 [Regression] When setting cellClass for a column but not returning any value for some cells, an exception is thrown and cells without a style set aren’t rendered

We try to fix bugs from one release to the next, so this should be fixed in the next release or the one after if it was raised too close to the next release date.

You can see the next release date on the product pipeline page: https://www.ag-grid.com/ag-grid-pipeline/

Now that this issue is recorded in our backlog, we will soon close the GitHub issue because we will not update it when this bug is fixed in a future version of AG Grid. The best way to get an update on this item is to sign up for AG Grid new release notifications. Once a new AG Grid version is released, look for the item reference above (AG-XXXX) on the changelog page to see if it’s resolved in that version: https://www.ag-grid.com/ag-grid-changelog/

Thanks again for bringing this up with us - we appreciate your time!

If cellclass is a function, it must have a return value

This seemed to fix it for us, just ensuring that all paths return a value. Still annoying that this suddenly changed.

I am also facing same issue using ag-grid in vue 2. image