vaadin / vaadin-grid

vaadin-grid is a free, high quality data grid / data table Web Component. Part of the Vaadin components.
https://vaadin.com/components
Apache License 2.0
401 stars 155 forks source link

Add Dom Observers for Templates #890

Closed hotforfeature closed 7 years ago

hotforfeature commented 7 years ago

Discussed with @Saulis. The grid won't work with Angular 2 and other libraries where elements are created and attached programatically.

Specifically, the column templates in Angular 2 are first created, then attached to <vaadin-grid-column> before child elements are attached to the <template>.

Adding some observers for when templates or their content changes will resolve any issues with programmatically creating and attaching a grid and its children. Alternatively, we could expose an API to inform the grid that its templates or columns have changed so that it knows to re-stamp them.

Relates to https://github.com/hotforfeature/origami/issues/18 for Angular 4/Polymer 2 support.

Analect commented 7 years ago

@Saulis ... we're keen to prototype vaadin-grid (v3 supporting polymer 2) in an angular4 context. Is this suggested fix alot of work to get in? Thanks.

Saulis commented 7 years ago

@hotforfeature @Analect I've made a POC branch here column-template-observer which should work at least on a concept level. Could you guys try it out if you get any results when running on Angular?

hotforfeature commented 7 years ago

I'll test out that branch and see how it works in Angular 4.

hotforfeature commented 7 years ago

I tested and so far it looks like it's working! There's one change that needs to be made though:

https://github.com/vaadin/vaadin-grid/blob/master/vaadin-grid-column.html#L97

_prepareTemplatizer() can get called multiple times, and the template already has a templatizer. We should change this to

if (template && !template.templatizer) {

to ensure the templatizer doesn't get replaced.

Analect commented 7 years ago

@Saulis ... posting @hotforfeature preliminary demo here (hope that's OK) based on those changes you had implemented on the column-template-observer branch.

Seems I forgot to add. Sorry. https://github.com/hotforfeature/origami/tree/vaadin/demo

Analect commented 7 years ago

@Saulis ... do you think you might be able to roll in your changes in the column-template-observer branch with the small fix above? As per @hotforfeature comment here, that appears all that's needed to get vaadin-grid compatible with origami. Thanks.

Saulis commented 7 years ago

@hotforfeature @Analect I've added the !template.templatizer check along with some tests to the column-template-observer branch (force pushed, so remember to run bower cache clean) – could you guys verify this version works better for you and I'll push a pull request for it. Thanks!

hotforfeature commented 7 years ago

@Saulis works perfectly!

Analect commented 7 years ago

@Saulis ... do you think your fix on column-template-observer could get included in your next release? Thanks.

Saulis commented 7 years ago

@Analect need to do some additional fixes to make it releasable, but I'll try to get a PR up asap.

manolo commented 7 years ago

Master build is not green, so moving this to the backlog until we spend some time to fix master.

Analect commented 7 years ago

@manolo @Saulis ... is https://github.com/vaadin/vaadin-grid/pull/918 any close to being merged? Thanks.