Skip to content

Dynamic handling of grid options, and document how to avoid watchers (ng-if, ng-class, ng-show etc) #1819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
PaulL1 opened this issue Oct 14, 2014 · 8 comments
Assignees
Milestone

Comments

@PaulL1
Copy link
Contributor

PaulL1 commented Oct 14, 2014

When I started on the project I was surprised at how much hand-rolled code there was - click event handlers and the like. I generally followed the pattern, but without understanding why. I now understand that it is a deliberate strategy to avoid the performance impacts of large numbers of watches being fired on every digest cycle.

What would be great is to create some documentation for new contributors on:
a) Why we do this
b) The common patterns - so if you would have used an ng-show, you should instead do a compile or an append in the specific circumstance you need
c) Common gotchas, so if we hand roll then we need to have handlers for the common triggers - if you are simulating an ng-class, then you need to recalculate it whenever the data changes

I also wonder whether we could add some helper methods, or registration functions, or something (or perhaps we already have these and they're the column builders etc which should be getting reused). My thought here is that once we write down the patterns, we'd suddenly see that we have a bunch of items that we'd like to reevaluate whenever the data changes. Ideally we'd have a single data watch / registration thing that holds a list of registered functions that should be called when it observes a data change (or even that gets called centrally by anything that changes data, such as the edit feature).

If we got this right, we could simplify this whole process into a standard set of registrations that people use to get the equivalent of an ng-show, an ng-if etc. Basically it'd be a helper function that took a template and a condition, and some information about what events require a reevaluation of the condition. It would be like a custom angular - so it still takes the load off the developer, but the triggers for reevaluation are much more tailored than just "every digest cycle re-evaluate the whole thing".

@PaulL1 PaulL1 added this to the 3.0 milestone Oct 14, 2014
@PaulL1
Copy link
Contributor Author

PaulL1 commented Oct 14, 2014

In a sense #1792 might be an example of this - we don't want every bit of code creating it's own watch on the options, it'd be nice if we could have a pattern where we could just write an evaluation function that decides whether or not to show the footer, and register it to be dependent on the options. Whenever the options change the grid would automatically re-evaluate that function.

PaulL1 added a commit to PaulL1/ng-grid that referenced this issue Oct 15, 2014
Add a dataChangeCallback capability to grid, which is called
by the data watch function.  Make use of this for importer to
know when the data change has occurred.  Refer angular-ui#1819 for the
concept here.

Fix rowEdit so that error rows aren't duplicate entered into
rowEditRowsDirty if they error twice.

Update tutorial numbering - newer tutorials have conflicted with
older.

Change importer to require an explicit callback to be provided
by the user - change the data from userspace rather than in the
grid itself.

Fix grid menu so that it displays correctly on Chrome, it had
started only partially rendering.  Fixed by changing position from
absolute to fixed.
@PaulL1
Copy link
Contributor Author

PaulL1 commented Oct 16, 2014

I needed something along these lines to provide dynamic column header classes - a method to notice that something had changed that might impact headers. I also applied this to cell class.

The logic behind it is to create a set of dataChangeCallbacks on the grid (refer registerDataChangeCallback and associated methods on the grid). These then get notified by the data watch (when rows are added or removed), the columnDefs watch (implying columnDefs have changed), and the edit end event. There is also an ability for a user to manually notify of data changes using the api.

Interested in a review of this approach and whether people think it looks good.

This was referenced Nov 4, 2014
@PaulL1 PaulL1 mentioned this issue Nov 14, 2014
@PaulL1 PaulL1 self-assigned this Nov 21, 2014
@PaulL1 PaulL1 changed the title Document how to avoid watchers (ng-if, ng-class, ng-show etc) Dynamic handling of grid options, and document how to avoid watchers (ng-if, ng-class, ng-show etc) Dec 19, 2014
@PaulL1 PaulL1 modified the milestones: 3.1, 3.0 Mar 28, 2015
@PaulL1
Copy link
Contributor Author

PaulL1 commented Mar 28, 2015

Elements of the documentation are now there, there are just a number of places where we still don't dynamically honour options cleanly. The majority of them are dealt with, but not all them.

@YonatanKra
Copy link
Contributor

Where can I find this documented?

@PaulL1
Copy link
Contributor Author

PaulL1 commented Apr 7, 2015

The point of the open issue is kinda that it's not already documented and it'd be good if it was.

@YonatanKra
Copy link
Contributor

Been wondering about these: Elements of the documentation are now there :)

@bernardoadc
Copy link

Any advances?

@johntiger1
Copy link
Contributor

johntiger1 commented Oct 11, 2017

I think there should definitely be some documentation added to address this. Copying Paul's answer from: #2417

"Many of the grid features aren't dynamic - they are set on grid creation and not updated when you change the options. I would expect this to be another example, there is a description in #1819"

This would have saved me some time when I tried to reason why I could disable filtering later on (i.e. outside gridoptions instantiation), but could not enable filtering later on--it is just not supported in any case.

I can post the code later if anyone is interested

@stale stale bot added the stale label May 23, 2018
@angular-ui angular-ui deleted a comment from stale bot May 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants