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 provide a good general method for observing changes to the displayed rows. #985

Open SimplGy opened 10 years ago

SimplGy commented 10 years ago

dataView provides two events I know of that work for observing changes to the displayed rows:

onRowCountChanged

and

onRowsChanged

onRowsChanged is good because it takes a diff and only fires if actual rows have changed. The problem is it doesn't fire if the rows have been changed to 0. This is the case if you're working in a filter at the top of the column and there are no matches.

In order to observe when the dataView changes to 0 rows, you need also to watch onRowCountChanged. The combination of these two events gets the superset of all changes (I think). You can't watch only onRowCountChanged because if you change a filter in such a way that there are still 3 results, but they are 3 different results, the event will not fire.

In order to avoid double-calling whatever code you need to trigger when the data changes, you end up needing to debounce the event combo, so it might come out like this:

onDataChanged = _.debounce ->
  grid.invalidate()
, 1

# This fires whenever rows have changed, but **not** if they change to 0
dataView.onRowsChanged.subscribe onDataChanged

# Fires when the count changes, including changing to 0
dataView.onRowCountChanged.subscribe onDataChanged

This seems like such a common need. Is there a single event I'm missing that notifies when dataView changes?

6pac commented 9 years ago

This is a great point, even if it has sat here for some months. Would the best solution to all this be to modify OnRowsChanged so that it does fire when there are no new rows. I'd have to look at what's involved, but that would seem to make sense.

SimplGy commented 9 years ago

Modifying onRowsChanged would be a breaking change, but I think it would have been the better design if you're making other sweeping changes/don't mind a breaking change.

Might want to think about rolling in other events like those that change/set columns--one reaction event for anything changing in the grid would have been very useful to us. (eg onChange fires whenever columns, rows, options, or anything has changed)

6pac commented 9 years ago

True. It's possible to put a 'legacy behaviour' switch or even sub-object into the options. At least that allows for relatively simple (if not drop-in) backwards compatibility.

SimplGy commented 9 years ago

Sounds reasonable to me. I took a quick look at your repo and I think taking over the maintenance is a great idea. SlickGrid is still the best virtualized grid system I think.

Not something I'm prioritizing anymore. Knock it out of the park :)

SimplGy commented 8 years ago

Update: should probably trigger onRowsChanged when you do a dataview.sort that has different ordering. Obviously has perf implications. Otherwise though, filter and group both throw this event but sort doesn't and you have to special-case it in application code.