ElementUI 表格横向滚动条时滚动到指定位置

ElementUI 表格横向滚动条时滚动到指定位置

复制代码
  getColumnOffset(columnProp) {
      this.$nextTick(() => {
        const table = this.$refs.tableRef.$refs.multipleTable;
        const columns = table.columns;
        const column = columns.find((col) => col.property === columnProp);
        if (column) {
          // const cell = table.$el.querySelector(`th[data-property=${columnProp}]`);
          const cell = table.$el.querySelector(`.${column.id}`);

          if (cell) {
            const rect = cell.getBoundingClientRect();
            const offset = rect.left - table.$el.getBoundingClientRect().left;
            console.log(`${columnProp}列距离左侧的位置是: ${offset}px`);
            this.$refs.tableRef.$refs.multipleTable.bodyWrapper.scrollLeft = `${offset}`; //Number(this.$refs.tableRef.$refs.multipleTable.bodyWidth.replace('px',''));
          }
        }
      });
    },

this.getColumnOffset("operName");

会将滚动条滚动到设置的列,方便编辑;

相关推荐
\xin2 小时前
pikachu自编exp,xss反射性get,post,存储型xss,dom,dom-x
前端·javascript·xss
是烟花哈6 小时前
【前端】React框架学习
前端·学习·react.js
qq4356947017 小时前
JavaWeb08
前端
2401_878454538 小时前
html和css的复习(1)
前端·css·html
@PHARAOH8 小时前
WHAT - git worktree 概念
前端·git
IT_陈寒9 小时前
我竟然被JavaScript的隐式类型转换坑了三天!
前端·人工智能·后端
我亚索贼六丶9 小时前
二十六. AI基础概念之如何更好的使用AI
前端
小码哥_常9 小时前
安卓启动页Logo适配秘籍:告别“奇形怪状”的展示
前端
我亚索贼六丶9 小时前
二十五.Electron 初体验与进阶
前端
当时只道寻常9 小时前
像使用 Redis 一样操作 LocalStorage
前端·前端工程化