Skip to content

Grid stack not updating after widget is removed with removeWidget() #2234

@olivergreendev

Description

@olivergreendev

Subject of the issue

I have followed the tutorial found at https://www.binarcode.com/blog/build-interactive-dashboards-with-vuejs-and-tailwind which has its own codesandbox setup (which also has the same bug), but essentially when I click on the icon to delete a widget, it gets spliced from the widgets array (good), and also removed from the grid successfully (good), however the grid-stack in the DOM doesn't update its gs-curent-row, and thus its max-height inline style that gets calculated based off the current row. The widget node is 100% being removed from the DOM, just the grid-stack isn't updating itself, and thus when I go to add a new widget, there is always some blank space in the grid that affects the position of the new widget. When I use the removeAll function, it works great as it removes all the widgets from the DOM and array, as well as updates the grid-stack so new widgets get added from x: 0, y: 0 correctly.

Your environment

gridstack.js version: ^7.2.3
browser: chrome - Version 111.0.5563.65 (Official Build) (64-bit)

Steps to reproduce

Using the attached codesandbox, click the 'Start Editing' button, hover over each widget and click the trash can icon to delete all of the widgets. Click the 'Add Widget' button, and you'll see a new 'Widget 1' card gets added a few rows down, since the grid-stack is still detecting all the blank space from the previous widgets above it. What should happen, is the grid-stack should now be cleared, such that the new Widget 1 card gets added to position x: 0, y: 0 - but that is not the case.

You can find the codesandbox that was setup in the tutorial here https://codesandbox.io/p/sandbox/editable-dashboard-prototype-with-vue-gridstack-and-tailwind-css-65hxp5?file=%2Fsrc%2Fcomponents%2FEditableDashboard.vue&selection=%5B%7B%22endColumn%22%3A13%2C%22endLineNumber%22%3A116%2C%22startColumn%22%3A13%2C%22startLineNumber%22%3A116%7D%5D

All I have done is follow this tutorial, and produced the same bug as found in the tutorial codesandbox.

Expected behavior

If I remove a widget, the grid-stack should update it's data, so that there is no blank space that affects the auto-calculated positioning of new widgets.

image

image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions