问题
Is it possible to programmatically scroll to a row using react-table[table library for react projects]
ANSWER EDIT: I ended up adding refs to each rows by formatting Cell. and used this function
scrollToKeyInTable(oldKey, newKey) {
if (newKey) {
const node = this._rowRefs.get(newKey);
try {
const row = node.parentElement.parentElement.parentElement;
const tableBodyNode = row.parentElement;
tableBodyNode.scrollTop = row.offsetTop - 35;
const { scrollX, scrollY } = window;
node.focus({ preventScroll: true });
window.scrollTo(scrollX, scrollY);
return this;
} catch (e) {}
} else if (oldKey) {
const node = this._rowRefs.get(oldKey);
if (node) {
node.blur();
}
}
}
来源:https://stackoverflow.com/questions/50583339/how-to-programmatically-scroll-to-a-row-using-react-table