如何将 React Suite Grid 中的行大小调整为最高单元格的高度

发布于 2025-01-14 00:26:23 字数 1085 浏览 5 评论 0原文

我正在使用 React Suite 的网格 以日历格式显示大学课程数据。除了单元格高度不统一之外,网格效果很好:我的网格 UI 的图像示例

这是我目前的网格代码:

<Grid
    style={{
        width: "100%",
        height: "100%",
    }}
    data-testid="grid"
>
    {this.state.data.map((c) => (
        <Row>
            {c.map((e) => (
                <Col className="display-linebreak" style={this.formatCell(e)}>{e}</Col>
            ))}
        </Row>
    ))}
</Grid>

有没有什么方法可以使所有单元格的高度在各自的行中保持一致,同时仍然使网格足够灵活,可以接收可变数量的日期和时间的数据?我尝试执行此操作的一种方法是添加 {{ height: "100%" }} 作为行的内联样式,但我很快意识到这种方法或任何类似的方法都行不通,因为最终需要的是单元格高度以符合基于其他单元格的自动高度的动态行高。我考虑的另一件事是,如果 Column 是 Row 的父组件,而不是相反,那么相对于 Row 隔离单元格可能会更容易,但我认为这在 React Suite Grid 中是不可能的。

基本上,我的难题是,如果行中还有尚未渲染的单元格,单元格如何知道它必须有多高?如果发现更高的单元格,是否可以返回并更新渲染后的高度?单元格如何知道它位于哪一行?

非常感谢任何提示或见解,我很乐意澄清任何事情或回答相关问题。先感谢您!

I am working with React Suite's Grid to display university course data in a calendar format. The grid works great, other than the cell heights not being uniform: An image example of my Grid UI

Here is the code I currently have for the grid:

<Grid
    style={{
        width: "100%",
        height: "100%",
    }}
    data-testid="grid"
>
    {this.state.data.map((c) => (
        <Row>
            {c.map((e) => (
                <Col className="display-linebreak" style={this.formatCell(e)}>{e}</Col>
            ))}
        </Row>
    ))}
</Grid>

Is there any way to make the height of all cells consistent across their respective row, while still making the grid flexible enough for data intake of a variable number of dates and times? One way I tried to do this is by adding {{ height: "100%" }} as inline style for the Row, but I quickly realized that this or any similar approach will not work, as ultimately it is the cell height that needs to conform to a dynamic row height, based on the automatic heights of the other cells. Another thing I considered is that it may be easier to isolate a cell with respect to a Row if Column is the parent component to Row instead of the other way around, but I don't think this is possible in React Suite Grid.

Basically, my conundrum is, how can the cell know how tall it has to be if there are cells in the row that have not been rendered yet? Is it possible to go back and update the height post-render if a taller cell is found? How does a cell even know which row it is in?

Any tips or insight is greatly appreciated, I am happy to clarify anything or answer questions about it. Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云胡 2025-01-21 00:26:23

我通过向 rs-row 添加 flex 来做到这一点:

.rs-row{
display: flex;
flex-direction: row;
flex-wrap: wrap;
}

然后您可以将高度 100% 添加到其中的 cols 或卡片元素。

I did it with adding flex to the rs-row:

.rs-row{
display: flex;
flex-direction: row;
flex-wrap: wrap;
}

Then you can add height 100% to the cols or cards elements inside of them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文