Table滚动到指定行方法
<Tableborderedcolumns={columns}dataSource={data}pagination={false}rowClassName={setClassName}scroll={{ y: 440 }}/>// 设置行样式function setClassName(record, index) {if(record.id == state.currentId){return `row${index} ${styles.highlight}`; // 自定义 highlight样式}return `row${index}`;}// 滚动条滚动到高亮行位置// value:当前需要高亮的值getRowHeightAndSetTop(dataSource, value){for(const [item, index] in dataSource.entries()) {if(item.id !== value) break;// 40是一行的高度,index*40就是滚动条要移动的位置let offset = index * 40;$(`.ant-table-body`).scrollTop(offset);}}
Table分页滚动到顶部
问题点: Table 在当前页,向下滑动后,再翻页后滚动条还是在原处
需求: 翻页的时候,把当前的滚动条定位到表格的顶部
<Table ref={tableRef} />const $table = tableRef.current.querySelector('.ant-table-body');// 翻页的时候让滚动条到顶部$table.scrollTop = 0;
