mleibman / SlickGrid

A lightning fast JavaScript grid/spreadsheet
http://wiki.github.com/mleibman/SlickGrid
MIT License
6.81k stars 1.98k forks source link

dataView does not handle removeCellCssStyles #1086

Open nexushoratio opened 9 years ago

nexushoratio commented 9 years ago

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.

bmcd77 commented 7 years ago

Hi, I was having problems with removeCellCssStyles(...) I could remove the styles ok from the Grid but then when filtering using the DataView it seemed at times to 'forget' that the Style had already been removed and still show the Css Style I was attempting to remove.

I applied your 'hack' above and it's working perfectly now iether way (Grid - > DataView or DataView -> Grid).

I was trying to use syncGridCellCssStyles(..) but of course in this instance its no use since the Key for the Style has already been removed so the sync doesn't know what to sync with!

Thanks for posting.

6pac commented 7 years ago

I'm taking this as a bug. Fixed in https://github.com/6pac/SlickGrid

asad-shaikh-ivp commented 3 years ago

I have a similar issue where I am looping through all the columns where I want to grid.addCellCssStyles(someName, hash);

This works fine when I run it in the chrome console but when the code is executed, the css style doesn't apply. When I use dataView.syncGridCellCssStyles(grid, someName); after adding the css, it throws error because for some reason the hash value doesn't pass all the way through to the library files.

When grid.getCellCssStyles(key) gets called it returns the variables I used in the foreach to loop through all the columns instead of actual column names. I am pretty new to Slickgrid so any help will be appreciated.

6pac commented 3 years ago

@asad-shaikh-ivp - note that this repo is dead - use the 6pac link above for the latest