-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
make widget auto-size height to fit content (no vertical scrollbar) #404
Comments
The same issue here, HELP NEEDED! have been pulling my hair for the last 2 days, any reply would be highly appreciated! |
I believe that what you're asking about can be done with CSS and DOM manipulation. If either of you could provide a jsFiddle, I'd be happy to help achieve the desired outcome. |
Hi Radiolips here have more info please see this url there have 2 div (drag me element ) in this div have image, when i will drag and drop in gridstak element then it's show image inside gridstack container, but in gridstack container have scroll bar and have fixed height there i need full height same as image height without scrolling. |
and there i want height as per image height without spacing and scroll bar |
Hi & thanks for your reply @radiolips, Please note the section called MIDDLE and sidebars which have scrollbars, That would be really nice if I could have that on initialization.
|
I tried to fix this issue temporarily but something is not right with the cellHeight then this happened: the columns are now extremely long! even some of them do not have any contents. |
Help still needed! I am still pulling my hair! has been a week. Let me know if this can not be done with grid stack. Just saying that "It can be done with CSS and DOM manipulation" will not solve our issue! |
i also want answer for this question. |
I believe this is one of the most important features that should be included! I have the same issue working around is not as easy as @radiolips says! |
Is there a solution to this yet? @radiolips @webdesignmzm |
Also looking for a solution to this, any updates? |
I am looking for solution as well. |
Apologies for the delay. Firstly, @webdesignmzm and @somchaisomsi, I'd like to point out that this library, and the support everyone receives, is entirely free of charge. Please be more considerate to the contributors who are spending their own time to provide a better dashboard experience for all users. I am closing this ticket. Before closing it, I will say (note that I am now now, nor have I anywhere on this ticket, said the word "easy") that this can be done using Javascript and CSS. This Stack Overflow article (http://stackoverflow.com/questions/2522579/how-do-i-get-the-real-height-of-a-overflow-hidden-or-overflow-scroll-div) explains how to grab the height of a div with a scrollbar. If you put this code into a
This code simply calls |
FYI for people coming in later, I've found that it works a little better if you use round instead of ceil.
|
@SimonOrdo Could you explain why using |
@SimonOrdo Would you please send us the updated js fiddle link? |
@SimonOrdo @radiolips at first I thought Math.round indeed works better. With Math.ceil the item always becomes a bit larger than expected when doing a manual resize. At first I couldn't find any situation where the item is not large enough when using round. However, after some more testing I ran into some issues when using round instead of ceil where the height wouldn't be large enough, thus resulting in a vertical scrollbar, which I would like to prevent. Using ceil fixes this problem, but causes some other issues:
Any help with the other problems would be greatly appreciated! |
I am trying to check that gridstack panel takes height based on its inner container height. I was using the code of responsive.html file which I downloaded from gridstack.
But the div is not at all expanding. I did not understand how I will use the solution provided by @radiolips . Where shall I change the code. |
The following is an alternate solution to dynamically size a grid cell based on its content using the grid's let contentElement = widgetInstance.el.querySelector(".grid-stack-item-content").children[0].children[0]; let contentHeight = Math.ceil((contentElement .parentElement.clientHeight * 1.05) / grid.opts.cellHeight); // Get height in rows. Multiply by 1.05 for some buffer contentElement.parentElement.parentElement.style.overflow = "hidden"; // Hide scrollbars if desired grid.update(widgetInstance.el, {h: contentHeight}); |
I think it's time to re-open this and do it the right way if someone is willing to donate or contribute a review. some sort of contentHeight option on the grid/gridItems.... @jasondalycan Also your element is specific to your use case of course. widgetInstance.el.querySelector(".grid-stack-item-content") should be enought if you don't overflow:hidden. but you are right my new |
Not sure if this is helpful, but figured I'd share. In retrospect while typing this up, I'd probably put this in the "conceptual" category of things.. @jasondalycan has a cleaner solution, that is.
|
this is very application specific as how tall a widget needs to be is highly depends on your specific content layout/DOM heirarchy. Here is code I just added in my Angular app for reference if it helps someone (comment to map to GS classes). I call this whenever content changes, or grid resizes. I don't think I can move this into the generic lib I'm afraid, as it assumes content takes available space, while first and only child is sized for content and would clip in my case. /** Call to make the gridItem match the content height of the finished loaded widget */
public resizeToContent() {
const el = this.el; // .grid-stack-item
if (!el) return;
let height = el.getBoundingClientRect().height;
const card = el.querySelector('.card-block'); // .grid-stack-item-content that fills remaining space between header+footer
if (!card) return;
const cardH = card.getBoundingClientRect().height;
const contentH = (card.firstChild as Element)?.getBoundingClientRect().height || cardH; // actual widget inside that may clip out or have extra space
height += contentH - cardH;
const grid = this.grid.grid; // GridStack
const cell = grid?.getCellHeight();
if (!cell) return;
let h = Math.ceil(height / cell);
const opt = this.options; // GridStackWidget
if (opt.maxH && h > opt.maxH) h = opt.maxH;
if (h !== opt.h) grid.update(el, {h});
} Note: this bypass the needs to know the padding/margin as it just figure out how big it is vs how much bigger to fit the content unclipped and size the outside accordingly. |
* fix gridstack#404 * added `GridStackOptions.fitToContent` and `GridStackWidget.fitToContent` to make gridItems size themselves to their content (no scroll bar), calling `GridStack.resizeToContent(el)` whenever the grid or item is resized * added demo showing behavior * fixed sizing event to use much more accurate ResizeObserver on grid rather than generic window.addEventListener('resize')
* fix gridstack#404 * make sure to use batch mode to improve re-layout
fixed in the next release v9! even though items have height=1 to start with they are sized to content and reflow as needed... long overdue feature - don't forget to donate to help support this lib! 20230807_093423.mp4 |
@adumesny is this feature already available to use in production? i just updated to 8.4.0 right now but still cant see the |
as I mentioned it will be in v9 - still need to consume it in my app and test it some more... |
* changing column size and manually resizing a widget will now call resizeToContent() * added resizeToContentCB for app to override how to resize. * Added `resizeToContentParent` to make generic code more robust. * fixed some 1 column loading Nan issues
* `sizeToContent` now supports being `boolean|number` to limit the height but user can resize past that, unlike maxH. * more gridstack#404 fixes
* more fix gridstack#404 * resizeToContentParent is now GridStackWidget var as well (local override) for widgets that needs to resize differently.
* fix resizeToContent() to handle node.h (using when cellHeight changes or we resize) vs DOM sizing (rest of the time) more gridstack#404
works for nested grid too! 20230910_120205.1.mp4 |
I want height as per inner container, i do not want any scroll bar and i want to put image inside grid-stack-item-content and i want grid-stack-item height same as image Height,
i have tried but i do not get result, can please let me know it;s possible
The text was updated successfully, but these errors were encountered: