-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🧐 问题 proTable在自定义valueType的render中拿不到当前行的数据 #2521
Comments
+1 |
@jiyingzhi 目前可以通过valueTypeMap的item.render覆盖columns的item.render进行render自定义,这样可以拿到当前行的数据 |
感谢反馈! 确实,在 以下是一个示例代码: import ProTable, { ProColumns } from '@ant-design/pro-table';
interface DataType {
name: string;
age: number;
address: string;
}
const data: DataType[] = [
{
name: 'John Brown',
age: 32,
address: 'New York No. 1 Lake Park',
},
{
name: 'Joe Black',
age: 42,
address: 'London No. 1 Lake Park',
},
];
const columns: ProColumns<DataType>[] = [
{
title: 'Name',
dataIndex: 'name',
valueType: 'text',
},
{
title: 'Age',
dataIndex: 'age',
valueType: 'custom',
// 定义一个自定义的 render,可以在其中获取当前行的数据
valueEnum: {
male: { text: 'Male', status: 'Success' },
female: { text: 'Female', status: 'Error' },
},
render: (text, record) => {
const { age } = record;
const gender = age % 2 === 0 ? 'female' : 'male';
return (columns[1].valueEnum || {})[gender]?.text ?? text;
},
},
{
title: 'Address',
dataIndex: 'address',
valueType: 'text',
},
];
export default () => (
<ProTable<DataType>
columns={columns}
dataSource={data}
/>
); 在上面的示例代码中,我们在 希望这可以解决你的问题! |
@chenshuai2144 怎么能获取当前render中是哪个字段?我的场景是在ProTable中点击某个字段(Switch组件),能够提交请求{id:record.id,[currentKey]:record[currentKey]},但是在render中好像无法知道当前操作的是哪一列? |
🧐 问题: proTable在自定义valueType的render中拿不到当前行的数据
默认提供的类型无法得到满足, 我想自定义valueType,但发现在valueTypeMap中定义的render和在cloumns中配置的render,参数不同, 无法拿到当前行的数据record?我想更多场景下是需要这个数据的�
The text was updated successfully, but these errors were encountered: