How to programmatically scroll to a row using react-table

雨燕双飞 提交于 2020-07-05 05:06:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!