1、找到指定的行,并高亮
<div id={'tableList'}>
<Table bordered
dataSource={data}
pagination={false}
rowClassName={this.setClassName}
columns={this.columns}
scroll={{ y: 440 }}/>
</div>
//设置行样式
setClassName = (record, index) => {
if(record.id == this.state.currId){
return `row${index} ${styles.highlight}`; //highlight样式需要自己定义
}
return `row${index}`;
}
2、滚动条滚动到高亮行位置
//调用getRowHeightAndSetTop方法获取高亮行的index值后,通过setScrollTopValue设置滚动条位置
//data:table的datasource数据
//value:当前需要高亮的值
getRowHeightAndSetTop(data, value){
data && data.forEach((item, index) => {
if(item.id == value){
this.setTableScrollTop(index);
}
})
}
//设置滚动条位置的方法
setTableScrollTop(index){
if (index != 0 || index != -1){
//40是一行的高度,index*40就是滚动条要移动的位置
let currPosition = index * 40;
$(`#list .ant-table-body`).scrollTop(currPosition);
}
}