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”);
会将滚动条滚动到设置的列,方便编辑;