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");

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

相关推荐
mCell4 小时前
【短文】不是最强,是最适合
前端·aigc·deepseek
余瑜鱼鱼鱼5 小时前
HTML常用标签总结
前端·html
Jave21085 小时前
Vue 中 mixins 混合开发的主要使用场景有哪些?
前端·vue.js
徐同保5 小时前
openclaw安装
前端
JEECG低代码平台5 小时前
JeecgBoot低代码平台 Ant Design Vue 4.x 升级避坑指南
前端·vue.js·低代码
yashuk5 小时前
Go-Gin Web 框架完整教程
前端·golang·gin
唐叔在学习5 小时前
e.preventDefault()到底怎么用?
前端·javascript
北寻北爱6 小时前
面试题-vue篇
前端·vue.js
XPoet6 小时前
AI 编程工程化:Skill——给你的 AI 员工装上技能包
前端·后端·ai编程
JEECG低代码平台6 小时前
JeecgBoot低代码平台 Qiankun 微前端集成指南:主应用配置全流程
前端·低代码