Skip to content
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

Destroy shouldn't delete DOM #216

Closed
mistahenry opened this issue Aug 21, 2015 · 6 comments
Closed

Destroy shouldn't delete DOM #216

mistahenry opened this issue Aug 21, 2015 · 6 comments

Comments

@mistahenry
Copy link

Hey, great plugin. My major issue with it is that the destroy method actually deletes the DOM. I was hoping it would merely uninit the dashboard. I am using Ember.js and here's my use case. When adding a widget, I simply added it to an array which causes a rerender which adds another widget into the dashboard (thanks to two-way binding). The problem is that this new widget isn't considered a part of the dashboard even though it has all of the correct data attributes. So I thought I'll do what I do with other plugins. Call destroy, the init again. Only, I lost all of my DOM :(

See, your add_widget method is not conducive to Ember because it requires that I pass html to the helper method itself, which isn't at all what I want to do from an Ember perspective. It'd be nice to either not destroy the DOM or provide a way to add a widget to the dashboard that already exists in the DOM to the dashboard container. As in, don't programmatically create a new widget for me. Let me specify that this widget doesn't currently exist in the dashboard but it should, so add it.

@edborden
Copy link

edborden commented Oct 5, 2015

I use Gridstack with Ember and use add_widget in setup like this:
didInsertElement: -> scheduleOnce 'afterRender', @, 'setupGridstackWidget'

I haven't been able to grock what the "right way" to integrate plugins that directly manipulate the DOM with Ember, though. What am I missing?

@gmsa
Copy link

gmsa commented Dec 10, 2015

+1

@kdietrich
Copy link
Contributor

You can use remove_widget with detach_node=false to remove a widget without changing the DOM. The counterpart make_widget allows you to convert an existing node into a widget without gridstack creating another DOM node.

@jhpedemonte
Copy link

remove_widget isn't enough. Calling destroy on the Gridstack object does cleanup for the whole grid, not just an individual widget. Looking at the code, it removes a "resize" handler and style rules (as well as removing the container from the DOM, which is what we want to avoid in this issue).

@radiolips
Copy link
Member

We can add a parameter for destroy to determine whether or not to remove from the DOM.

@radiolips radiolips added this to the v0.2.5 milestone Feb 18, 2016
radiolips added a commit to radiolips/gridstack.js that referenced this issue Feb 22, 2016
@radiolips
Copy link
Member

This feature has been merged in. destroy now takes an optional detachGrid method. Pass false and I believe your problem will be solved. Let me know if you have any further problems.

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

6 participants