Skip to content

Widget width reported incorrectly by save() after dragging from wider nested grid #2394

@akosfekete

Description

@akosfekete

Subject of the issue

Widget width is incorrect in JSON produced by the save() method, if the given widget has been dragged from a nested grid that has more columns than the outer grid. The grid and widgets behave correctly, the problem is only with data generated by save(). Loading back this data into the grid will cause an incorrect state (since the JSON contains an impossible layout)

The save() method in gridstack-engine.ts takes the width value from this._layouts if present. The resized node's actual width seems correct, the incorrect value seems to come from this._layouts
https://github.com/gridstack/gridstack.js/blob/89ae9d6fd163137c5fde895ae14d1c5d2bb7a495/src/gridstack-engine.ts#L746C7-L746C7
image

Your environment

  • version of gridstack.js - 8.2.3
  • which browser/OS - Firefox 116 / Chrome 114, Windows

Steps to reproduce

  1. Drag a widget from a grid with 2 columns into a nested grid with 3 columns
  2. Resize the widget to be as wide as possible
  3. Drag the widget back into the main grid from the nested grid
  4. Resize the widget
    The widget will have its width reported incorrectly in the JSON data generated by save()

https://jsfiddle.net/akosfekete/Lpv2au4w/11/
firefox_RNua2gRDXP

Expected behavior

The width should be the same as it appears in the layout.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions