How to programmatically scroll to a row using reac

2020-06-27 01:59发布

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();
   }
 }
}

0条回答
登录 后发表回答