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

Cross-domain issues in front-end and back-end separation of Vue+SpringBoot

In the front-end and back-end separation developm...

Dynamic starry sky background implemented with CSS3

Result:Implementation Code html <link href=...

How to install Docker using scripts under Linux Centos

What is the main function of Docker? At present, ...

Detailed explanation of Javascript event capture and bubbling methods

Table of contents 1. Event Processing Model 1. Ev...

Summary of methods for inserting videos into HTML pages

Now if you want to use the video tag in a page, y...

MySQL character types are case sensitive

By default, MySQL character types are not case-se...

Overview and differences between html inline elements and html block-level elements

Block-level element features : •Always occupies a ...

Some problems you may encounter when installing MySQL

Question 1: When entering net start mysql during ...

How to use Docker container to access host network

Recently, a system was deployed, using nginx as a...

Ajax jquery realizes the refresh effect of a div on the page

The original code is this: <div class='con...

Pitfalls based on MySQL default sorting rules

The default varchar type in MySQL is case insensi...

Detailed explanation of HTML document types

Mine is: <!DOCTYPE html> Blog Garden: <!...

Vue implementation example using Google Recaptcha verification

In our recent project, we need to use Google robo...