reactjs - 根据状态值更改 Ant Design 表的标题
问题描述
我需要一点帮助,在 Ant Design 表中,我需要表的标题应该根据状态值而改变。在给定的沙盒示例中,列标题surname
应更改为Second Name
打开开关的位置,否则应surname
仅显示。
参考:https ://codesandbox.io/s/purple-sun-1rtz1?file=/index.js
谢谢你。
解决方案
您可以根据以下内容更改标题surNameShow
render() {
const { dataSource, surNameShow } = this.state;
const columns = this.columns;
// check and set title here
// If you want to change the second column you can use index 1, if you want it to be dynamic just loop through columns array update column you desire
if (surNameShow) {
columns[1].title = "Second Name";
} else {
columns[1].title = "Surname";
}
return (
<div>
<p className="mr-3"> Change Surname to Second Name</p>
<Switch onChange={() => this.handleChnage()} />
<Table
bordered
dataSource={dataSource}
columns={columns}
pagination={false}
/>
</div>
);
}
推荐阅读
- ruby - 通过 << 附加元素时出现意外的 FrozenError
- spring-boot - 在 Spring Boot 应用程序中创建 TCP 客户端以发送和接收
- c++ - 如何使用 boost.log 的记录器?
- javascript - 机器重启后 pm2 托管进程处于错误状态
- java - 如何在 micronaut 中获取当前主机和端口?
- android - 为远程配置设置本地化默认值
- python - 如何将熊猫数据框更改为二进制矩阵?
- sql - Oracle SQL 选择最早时间的日期时间
- html - 组内具有拖放功能的多个列表
- angularjs - WebStorm:显示未使用的 AngularJS 依赖项