如何实现具有可滚动列的水平布局?

huangapple go评论107阅读模式
英文:

Vaadin: How to implement horizontal layout with scrollable column?

问题

我想要实现一个水平布局,其中表格内容区域位于左侧,基于手风琴的详细信息列位于右侧。内容区域应占据剩余的页面高度(基本上是100vh - 导航栏高度),并且不应超过该值。

问题出在详细信息列上,特别是手风琴上。展开的面板可能包含许多行,所以我将手风琴放在了一个滚动器内,但它不起作用。它不是获得一个可滚动的手风琴,而是扩展了根容器,我得到了一个可滚动的窗口。

简化的代码:

var grid = new Grid<>(Pojo.class, false);

var tableBox = new VerticalLayout(grid);
tableBox.setHeightFull();

var accordion = new Accordion();
accordion.setWidthFull();

var detailsBox = new Scroller(accordion);
detailsBox.setScrollDirection(Scroller.ScrollDirection.VERTICAL);
detailsBox.setWidth("450px");

var layout = new HorizontalLayout();
layout.add(tableBox);
layout.add(detailsBox);
layout.setFlexGrow(1, tableBox);
layout.setFlexGrow(0, detailsBox);
layout.setSizeFull();

我正在使用Vaadin 24。

英文:

I want to implement a HorizontalLayout with the table content area on the left side and the accordion-based details column on the right. The content area should occupy the remaining page height (basically, 100vh - navbarHeight) and it should not exceed that value.

The issue is in the details column, specifically with the accordion. Expanded panels can contain many rows, so I put the accordion inside a scroller, but it's not working. Instead of getting a scrollable accordion, it expands the root container and I get scrollable window instead.

如何实现具有可滚动列的水平布局?

Simplified code:

var grid = new Grid<>(Pojo.class, false);

var tableBox = new VerticalLayout(grid);
tableBox.setHeightFull();

var accordion = new Accordion();
accordion.setWidthFull();

var detailsBox = new Scroller(accordion);
detailsBox.setScrollDirection(Scroller.ScrollDirection.VERTICAL);
detailsBox.setWidth("450px");

var layout = new HorizontalLayout();
layout.add(tableBox);
layout.add(detailsBox);
layout.setFlexGrow(1, tableBox);
layout.setFlexGrow(0, detailsBox);
layout.setSizeFull();

I'm using Vaadin 24.

答案1

得分: 2

我认为您在布局组件上缺少明确的高度设置。尝试在layouttableBoxdetailsBox上使用setHeightFull()

英文:

I think you’re missing explicit heights on the layout components. Try setHeightFull() on layout, tableBox, and detailsBox.

答案2

得分: 0

我明白了。所有的Vaadin布局控件基本上都是弹性容器。而这个任务不能仅仅用弹性布局来解决,但可以通过自定义CSS来解决,我是按照以下代码片段进行的。

https://stackoverflow.com/a/59550839/8817161

英文:

Ok, I got it. All Vaadin layout controls are basically flex containers. And this task isn't solvable with flex alone, but it can be solved with custom CSS, which I did following this snippet.

https://stackoverflow.com/a/59550839/8817161

huangapple
  • 本文由 发表于 2023年8月10日 21:19:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76876114.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定