reactjs - 蚂蚁设计获取列索引
问题描述
我正在使用Ant Design构建一个组件,该组件的使用方式如下:
<Table
style={{cursor: 'pointer'}}
components={components}
rowClassName={() => 'editable-row'}
bordered
dataSource={dataSource}
columns={columns}
pagination={{ hideOnSinglePage: true }}
onSelect={(column) => { console.log(column) }}
onRow={(record, rowIndex) => {
return {
onClick: event => {
var updated = { ...this.state }
updated.modals.days.isVisible = true;
updated.selectedRowIndex = rowIndex;
this.setState(updated)
},
};
}}
renderCell={() => {
}}
/>
当您单击一个单元格时,它应该启动一个模式(基于我单击的列)。单击时如何获取列索引(或名称)?或其他方式来实现这一点。
解决方案
您可以通过将ColumnType对象数组传递给<Table>
.
ColumnType
有一个属性render
,您可以在其中放置您的逻辑(使用 html),您将在此列中获得记录的值。正如文档中所说:返回值应该是 ReactNode,或者 colSpan/rowSpan 配置的对象。
您可以在可编辑单元格的文档中调整删除弹出确认中的部分
const columns: ColumnsType<YourRecord> = [
{
key: 'name',
title: 'Name',
dataIndex: 'name',
},
{
key: 'age',
title: 'Age',
dataIndex: 'age',
},
{
key: 'modal',
title: 'Modal',
dataIndex: 'modal',
render: (_: any, record: YourRecord) => {
return <>html with onClick to open modal</>
}
}
];
<Table
style={{cursor: 'pointer'}}
components={components}
rowClassName={() => 'editable-row'}
bordered
dataSource={dataSource}
columns={columns}
pagination={{ hideOnSinglePage: true }}
onSelect={(column) => { console.log(column) }}
onRow={(record, rowIndex) => {
return {
onClick: event => {
var updated = { ...this.state }
updated.modals.days.isVisible = true;
updated.selectedRowIndex = rowIndex;
this.setState(updated)
},
};
}}
renderCell={() => {
}}
/>
推荐阅读
- python - 如何拆分测试和训练大小
- javascript - jQuery拖放图像上传器预览PDF图像如果选择pdf格式
- c# - 如何使用 VB.NET 或 C# 将元文件(矢量图像)写入剪贴板
- reactjs - React array mapping, toggles all drop-downs on click, I want to open the dropdown for the clicked card only
- flutter - 添加 Navigator.push Flutter 时不显示 InkWell 飞溅颜色效果
- javascript - 在响应准备好之前,如何使用 xmlhttprequest 发出请求?
- php - Laravel 错误:试图获取非对象的属性“id”
- amazon-web-services - 如果数组值存在于 jq 中,则仅包含它们
- sql - 定义一个子表,然后使用 SQL 从该表中查询
- c - 如何在一般 C 程序中使用相对路径?