vue3,element ui框架中为el-table表格实现自动滚动,并实现表头汇总数据

基础用法不太明白的请参考官网文档 ;element ui Plus官网:Table 表格 | Element PlusA Vue 3 based component library for designers and developershttps://element-plus.org/zh-CN/component/table.html

1、添加一个基础表格

复制代码
<template>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="date" label="Date" width="180" />
    <el-table-column prop="name" label="Name" width="180" />
    <el-table-column prop="address" label="Address" />
  </el-table>
</template>

2、为表格添加一下基础的样式,为并设置固定的高度:

复制代码
max-height="430" 

为表格添加一个id类名 ,或者 table-layout="fixed"

复制代码
id="out-table"   table-layout="fixed"

例如这是一个完成的样式:

复制代码
<template>
 <el-table
          ref="tableRef" border id="out-table" :data="headerList" :fit="true" table-layout="fixed"
          max-height="430"
          header-align="center" style="width:100%;" :header-cell-style="{
          color: '#1e293b',textAlign: 'center',fontWeight: '600',
          background: 'linear-gradient(to bottom, #f8fafc, #f1f5f9)',borderColor: '#e2e8f0',height: '40px'}"
          :cell-style="{textAlign: 'center',color: '#334155',borderColor: '#e2e8f0',background: '#fff',height: '40px'}">
          <el-table-column prop="materialType" :label="$t('common.materialType')">
            <template #header>
              <span class="flex items-center justify-center w-full">
                {{ $t('common.materialType') }}
                <span class="text-indigo-500 ml-2 text-sm">({{ headerList.length }})</span>
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="sourceWarehouName" :label="$t('common.OutWarehouse')" >
            <template #default="scope">
              <el-button-group size="">
                <el-button type="info w-[80px]" class="">{{scope.row.sourceWarehouName}}</el-button>
                <el-button type="info w-[80px]"  class="" plain>{{scope.row.sourceWarehouCode}}</el-button>
              </el-button-group>
            </template>
          </el-table-column>
          <el-table-column prop="targetWarehouName" :label="$t('common.InWarehouse')" >
            <template #default="scope">
              <el-button-group size="">
                <el-button type="primary w-[80px]" class="">{{scope.row.targetWarehouName}}</el-button>
                <el-button type="primary w-[80px]"  class="" plain>{{scope.row.targetWarehouCode}}</el-button>
              </el-button-group>
            </template>
          </el-table-column>
          <el-table-column prop="qty" :label="$t('mes.qty')" width="120">
            <template #default="scope">
              <el-tag type="warning" size="large"  class="w-[90px]" plain>{{scope.row.qty}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="unit" :label="$t('wms.unit')" width="80">
            <template #default="scope">
              <el-tag type="info" size="large" class="w-[60px]" plain effect="">{{scope.row.unit}}</el-tag>
            </template>
          </el-table-column>
        </el-table>
</template>

3、JS部分

注意:这里省略了给表格赋值的代码,自己自行添加(里面只有自动滚动部分的代码)

  1. 表格会以每 50 毫秒 1 像素的速度自动向下滚动。

  2. 当滚动到底部时,暂停 3 秒钟,然后将滚动条重置到顶部,继续滚动。

  3. 如果用户与滚动区域交互(例如手动拖动滚动条),则暂停自动滚动,直到用户停止交互后再恢复。

  4. 标记用户正在交互:将 isUserInteracting 设置为 true,表示用户正在与滚动区域进行交互。

  5. 保存当前滚动位置:通过 scrollWrapper.scrollTop 获取当前滚动条的位置,并将其存储到 lastScrollPosition 中。

  6. 暂停自动滚动:调用 stopScroll() 方法,清除定时器,停止自动滚动。

相关推荐
依然范特东3 分钟前
强化学习笔记2--bellman equation
人工智能·笔记
乐观勇敢坚强的老彭29 分钟前
信奥C++一维数组笔记
开发语言·c++·笔记
Old Uncle Tom40 分钟前
银行用户画像 -- 金融目标与需求意图
前端·人工智能·金融
昕光xg1 小时前
Istio笔记04-基于Jaeger的分布式链路追踪
笔记·分布式·istio
IT_陈寒1 小时前
Vue的响应式让我加班到凌晨3点,原来问题出在这
前端·人工智能·后端
东方小月1 小时前
从0开发一个 Coding Agent(一):前言
前端·人工智能·typescript
恋猫de小郭1 小时前
Flutter 全新真 3D 实现,用 flutter_scene 能开发一个「我的世界」
android·前端·flutter
ji_shuke1 小时前
远程排查 Web 系统问题:如何导出 HAR 文件协助定位
前端·问题排查
学计算机的计算基1 小时前
操作系统内存管理全解:虚拟内存、页表、COW、malloc、OOM一篇搞定
java·笔记·算法