reactjs - 无法设置 React 引导表的最大高度
问题描述
我想设置我的引导表的 maxHeight。
我已经尝试了以下逻辑,但对我的桌子没有任何作用。
//1st try
componentDidMount() {
let height = 100;
this.setState({tableHeight: height + "px"});
}
<BootstrapTable style={{color: this.state.colorCr }}
data={this.state.crArray}
headers={this.props.state.options.headers}
columns={crCol}
maxHeight={this.state.tableHeight}
>
</BootstrapTable>
//2nd try
<BootstrapTable style={{color: this.state.colorCr }}
data={this.state.crArray}
headers={this.props.state.options.headers}
columns={crCol}
height={100}
>
</BootstrapTable>
//3rd try
<BootstrapTable style={{color: this.state.colorCr }}
data={this.state.crArray}
headers={this.props.state.options.headers}
columns={crCol}
bodyStyle={ { maxHeight: '100px' } }
>
</BootstrapTable>
谁能告诉我我做错了什么,或者任何其他方式来设置Bootstrap
桌子的最大高度。任何帮助都会非常感激。
解决方案
React Bootstrap Table 本身为<table>
标签添加了一个包装器 div。所以不需要额外添加<div>
。请先浏览下面的链接,他们在其中提供了一个示例来添加类和 id 以自定义表格。
在你的情况下,你必须
- 首先在您的 css 文件中为 prop 添加一个 css 规则,其中
wrapperClasses
提到max-height
to 所需的值和overflow
toauto
。这将适用于包装器 div 并将帮助您拥有一个滚动条。 - 要使标题具有粘性并且只有正文可以滚动,请为
<th>
. 有一个类范围限制取决于你。我只想将它用于我项目中特定 div 下的表格。否则,只需放置table thead th
.
.<class-name-of-wrapper-div> table thead th {
position: sticky;
position: -webkit-sticky;
top: 0;
background-color: #FFFFFF;
}
希望它能解决你的问题。
推荐阅读
- scala - Scala 中的 JavaFX 为时已晚重绘
- unity3d - 在 OnGUI 中绘制具有颜色和粗细的矩形
- android - 应用程序是否可以包含用户可以控制应用程序权限的页面?
- google-chrome-extension - 如何在 Firefox/Chrome 网络扩展中动态初始化内容脚本?
- html - 在剑道 UI 搜索文本框上添加清除图标
- azure-data-factory-2 - 具有集成运行时的 Azure 数据工厂 - 复制后删除(或移动)文件
- javascript - 有没有办法在以下上下文中伪造 React JS 中的循环动画?
- javascript - React - 从另一个文件更新状态的组件
- android - 启动 Activity 时 Android 屏幕闪烁
- javascript - 为什么 Reduce 会在它完成对传入的整个数组的循环之前关闭?