查了Ai 给的方法是tableRef.current.scrollToRow(0);
但是实际上用地antd3 压根没有这个方法。
分享一下我自己想的一个简答的办法。
1、需要定位的行要有唯一的标识 例如id。
let data = [
{
id: 1
},
{
id: 2
},
{
id: 3
},
]
这个id是为了方便找到所在行的位置。
2、在写Table 的Columns的时候 给这一行的某个字段(如果是id这字段更好)加上类名
className,例如:
{
title: 'Id',
dataIndex: 'id',
align: 'left',
width: 200,
className: `th-center`,
onCell: (record) => {
return {
className: `table-title d-${record.id}`,
}
},
render: (text, record) => {
return text
}
}
最主要的就是onCell 这里,这个可以拿到这一行的信息 return 的className中 加上id类名,如果id是纯数字这种的建议前面加上一个字母,方便下面获取类名。
3、在需要滚动到某一行的地方使用下面代码: