Skip to content

sizeToContent is not triggered when initializing from HTML #2552

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

Closed
vmihailenco opened this issue Nov 28, 2023 · 5 comments · Fixed by #2561 · May be fixed by Samg217/glpi#8
Closed

sizeToContent is not triggered when initializing from HTML #2552

vmihailenco opened this issue Nov 28, 2023 · 5 comments · Fixed by #2561 · May be fixed by Samg217/glpi#8
Labels

Comments

@vmihailenco
Copy link
Contributor

Subject of the issue

When initializing GridStack from HTML, the items are not automatically resized to content. As a workaround, you can still manually resize the item or add grid.cellHeight(50); to trigger an update.

For example:

      let grid = GridStack.init({
        handle: ".card-header",
        sizeToContent: true,
        cellHeight: 49,
      });
      // Uncomment the following line.
      //grid.cellHeight(50);

Your environment

Can be reproduced on Chrome with GridStack 9 and 10.

Steps to reproduce

  1. Run https://jsfiddle.net/owzvb79t/
  2. Uncomment grid.cellHeight(50) to get the desired behavior.

Expected behavior

The item should be automatically sized to content after initialization.

adumesny added a commit to adumesny/gridstack.js that referenced this issue Dec 9, 2023
* fix gridstack#2552 where dom init wasn't calling sizeToContent

Also:
* fixed drag&drop not calling size either
* prevent animation when loading (from empty) and when replacing placeholder with actual content (helps in sizeToContent)
* resizeToContent() no longer use dic sizing (only node.h) so we rarely have to delay for animation (only when column widget changes)
* bunch of renames (internal) to make cleaner.

*** POSSIBLE BREAK (unlikely)
* ResizeToContentFcn doesn't take optional useAttr arg anymore
@adumesny
Copy link
Member

adumesny commented Dec 9, 2023

fixed in next release. don't forget to donate if you find this lib useful!

@vmihailenco
Copy link
Contributor Author

@adumesny thanks, but nothing really changed... Here is the updated fiddle for v10.0.1: https://jsfiddle.net/19mj7r5o/

@thadguidry
Copy link

thadguidry commented Dec 11, 2023

You need to use the correct URL in the JSFiddle Resources? If you hover over it, you will see it's pointing to 10.0.0
https://cdn.jsdelivr.net/npm/gridstack@10.0.0/dist/gridstack-all.js
and should be
https://cdn.jsdelivr.net/npm/gridstack@10.0.1/dist/gridstack-all.js
After clicking + to save the resource change, then click RUN button again.

@vmihailenco
Copy link
Contributor Author

@thadguidry I did just that, but somehow messed it up. All seems to be good now: https://jsfiddle.net/927om8he/2/

@adumesny
Copy link
Member

I used the official demo to fix html init (second grid of https://gridstackjs.com/demo/sizeToContent.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants