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

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

相关推荐
Csvn1 小时前
WASM
前端
修己xj2 小时前
我用 AI 给自己写了一个 Markdown 编辑器,然后把它开源了
前端
FRing032 小时前
vue2干货总结2(v-bind、v-for、v-model、指令修饰符、v-bind操作class和style)
开发语言·前端·vue.js·vue2
幸运小猿3 小时前
模拟慢上传-处理超时重试image 丢失线上问题
前端·javascript·html
moshuying4 小时前
网购能买Token了!
前端
h_65432104 小时前
echarts实现柱状图加一条横线
前端·echarts
风骏时光牛马5 小时前
生成一个后端标题,只需要一个标题,不需要其他的任何文本。
前端
子非鱼@Itfuture5 小时前
关于前后端联调中登录状态/登录信息失效?
java·前端
郭小李5 小时前
openFeign入门
java·开发语言·前端
馒头不想说话5 小时前
AI当运营,帮你省人力
前端