reactjs - how to get a specific data from antd table
问题描述
im trying to get a specific data from an antd
table, lets say im trying to get a name of a person from an antd
table, here is how i create the onClick
function to be called when i click everywhere in the specified row inside the table
<Table
columns={this.props.columns}
dataSource={this.state.dataSource}
onRow={(r) => ({
onClick: this.showDetailUser
})}
loading={this.state.loading}
footer={this.props.footer}
/>
i want to print the name of a person from the clicked cell inside the row (not the clicked name), so i can click everywhere inside the cell and still got the name of the person, this method does work, i can click everywhere and the function get called successfully, but i cant find the method to get the data
any help will be appriciated, thanks before
解决方案
我猜你必须渲染你自己的表格行/列。Table 上的Antd 官方文档展示了一些示例。您必须在行/单元格上添加一个 onClick 侦听器。
(从文档中提取)
<Table dataSource={data}>
<ColumnGroup title="Name">
<Column title="First Name" dataIndex="firstName" key="firstName" />
<Column title="Last Name" dataIndex="lastName" key="lastName" />
</ColumnGroup>
<Column title="Age" dataIndex="age" key="age" />
<Column title="Address" dataIndex="address" key="address" />
<Column
title="Tags"
dataIndex="tags"
key="tags"
render={tags => (
<>
{/*Here you should add your click handler*/}
{tags.map(tag => (
<Tag onClick={} color="blue" key={tag}>
{tag}
</Tag>
))}
</>
)}
/>
<Column
title="Action"
key="action"
render={(text, record) => (
{/*Here you should add your click handler*/}
<Space onClick={} size="middle">
<a>Invite {record.lastName}</a>
<a>Delete</a>
</Space>
)}
/>
</Table>
(代码未测试)
推荐阅读
- c# - 有没有办法在纯 C# 中从 Chrome 浏览器中获取元素,没有 Selenium
- c# - Why is my DataGrid showing up in the wrong Grid column?
- javascript - ES2015 函数名推断在哪里定义?
- javascript - 超过最大执行时间谷歌表格脚本解决方法
- asp.net-core - RestSharp 响应错误:“每个套接字地址(协议/网络地址/端口)通常只允许使用一次”
- javascript - 单击按钮时如何使一堆输入消失
- javascript - Javascript 枚举数组
- python - 将作者姓名链接到 Python-Django 中的作者个人资料页面
- c# - 将字段作为参数传递与将方法调用作为参数传递有何不同?
- docker - 将 env 变量作为变量传递,该变量应在容器的上下文中解析