#1086·SlickGrid

dataView does not handle removeCellCssStyles

Author: nexushoratioCreated Sep 13, 2015Updated Sep 28, 2021

I am fairly sure this issue is the same as discussed at http://stackoverflow.com/questions/12860036/slickgrid-remove-css-when-filter-is-applied , though I think the analysis there is wrong.

A typical code flow might go like this:

  grid.addCellCssStyles(someName, hash);
  dataView.syncGridCellCssStyles(grid, someName);

so the css stays in sync with the actual data (verses the cell the data is displayed in at the time). dataView does that by registering a handler with grid.onCellCssStylesChanged().

Later on, this may get called:

grid.removeCellCssStyles(someName);

At this point, things go awry.

onCellCssStylesChanged trigger calls dataView's handler with (someName, null). The handler does nothing in this case:

        if (args.hash) {
          storeCellCssStyles(args.hash);
        }

What I think should happen is, if args.hash === null (vs say undefined), then all of the existing handlers should be unsubscribed.

My local hack looks like this:

        if (args.hash) {
          storeCellCssStyles(args.hash);
        } else {
          grid.onCellCssStylesChanged.unsubscribe(styleChanged);
          self.onRowsChanged.unsubscribe(update);
          self.onRowCountChanged.unsubscribe(update);          
        }

(Obviously, I set a variable called self to this to get the right scope, not sure how javascripty that name is.)

Anyway, this works well for me.