Example code for element multiple tables to achieve synchronous scrolling

Example code for element multiple tables to achieve synchronous scrolling

Element UI implements multiple tables scrolling at the same time, horizontally and vertically

insert image description here

The code is as follows:

<script src="//unpkg.com/vue/dist/vue.js"></script>
<script src="//unpkg.com/[email protected]/lib/index.js"></script>
<div id="app">
<template>
    <el-table
      ref="table1"
      border="10"
      height="150"
      :data="tableData"
      style="width: 800px">
      <el-table-column
        prop="date"
        label="Date"
        width="300">
      </el-table-column>
      <el-table-column
        prop="name"
        label="Name"
        width="300">
      </el-table-column>
      <el-table-column
        width="300px"
        prop="address"
        label="Address">
      </el-table-column>
            <el-table-column
        width="300px"
        prop="address"
        label="Address">
      </el-table-column>
    </el-table>
    <br/>
    <el-table
      ref="table2"
      border="10"
      height="150"
      :data="tableData"
      style="width: 800px">
      <el-table-column
        prop="date"
        label="Date"
        width="300">
      </el-table-column>
      <el-table-column
        prop="name"
        label="Name"
        width="300">
      </el-table-column>
      <el-table-column
        width="300px"
        prop="address"
        label="Address">
      </el-table-column>
            <el-table-column
        width="300px"
        prop="address"
        label="Address">
      </el-table-column>
    </el-table>
  </template>
</div>
var Main = {
      data() {
        return {
          tableData: [{
            date: '2016-05-02',
            name: 'Wang Xiaohu',
            address: 'Shanghai'
          }, {
            date: '2016-05-04',
            name: 'Wang Xiaohu',
            address: 'Shanghai'
          }, {
            date: '2016-05-04',
            name: 'Wang Xiaohu',
            address: 'Shanghai'
          }, {
            date: '2016-05-04',
            name: 'Wang Xiaohu',
            address: 'Shanghai'
          }],
          dom1: null,
          dom2: null
        }
      },
      mounted() {
        this.dom1 = this.$refs.table1.bodyWrapper
        this.dom2 = this.$refs.table2.bodyWrapper

        this.listenerScroll()
      },
      methods: {
        listenerScroll() {
          this.dom2.addEventListener('scroll', () => {
            // Scroll this.dom1.scrollLeft = this.dom2.scrollLeft
            // Vertical scroll this.dom1.scrollTop = this.dom2.scrollTop
          })
        }
      }
    }
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')

This is the end of this article about how to achieve synchronized scrolling of multiple element tables. For more information about synchronized scrolling of element tables, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solve the problem of hiding table columns in element-ui
  • Detailed explanation of the writing method of VUE2.0+ElementUI2.0 table el-table loop dynamic column rendering
  • The cool operations on table in Element-UI (summary)
  • Solution to Table Problem in ElementUI
  • 4 ways to modify Element's el-table style in Vue
  • Detailed explanation of table column timestamp formatting in Element UI of vue2.0
  • Using the slot-scope method of Element UI Table

<<:  Detailed explanation of the Docker deployment tutorial for Jenkins beginners

>>:  Explanation of the execution priority of mySQL keywords

Recommend

How to configure https for nginx in docker

Websites without https support will gradually be ...

Detailed explanation of the calculation method of flex-grow and flex-shrink in flex layout

Flex(彈性布局) in CSS can flexibly control the layout...

Tutorial on how to install htop on CentOS 8

If you are looking to monitor your system interac...

Linux kernel device driver memory management notes

/********************** * Linux memory management...

Tutorial on installing mongodb under linux

MongoDB is cross-platform and can be installed on...

How to delete a property of an object in JavaScript

1. delete delete is the only real way to remove a...

v-html rendering component problem

Since I have parsed HTML before, I want to use Vu...

JS realizes video barrage effect

Use ES6 modular development and observer mode to ...

Calling the search engine in the page takes Baidu as an example

Today, it suddenly occurred to me that it would be...

MySQL 8.0.17 installation and configuration graphic tutorial

This article records the graphic tutorial of MySQ...

How to use CSS custom variables in Vue

Table of contents The CSS custom variable functio...

How to configure SSL for koa2 service

I. Introduction 1: SSL Certificate My domain name...

File sharing between Ubuntu and Windows under VMware

This article records the method of sharing files ...