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() 方法,清除定时器,停止自动滚动。

相关推荐
京东云开发者19 分钟前
当AI成为导演-如何用AI创作动漫短剧
前端
李白的天不白1 小时前
使用 SmartAdmin 进行前后端开发
java·前端
乘风gg1 小时前
🤡PUA AI Coding 工具 的 10 条终极语录
前端·ai编程·claude
学Linux的语莫1 小时前
Vue 3 入门教程
前端·javascript·vue.js
怕浪猫1 小时前
第一章、Chrome DevTools Protocol (CDP) 详解
前端·javascript·chrome
kyriewen2 小时前
从本地到生产:迁移到 GitHub Actions 自动化 CI/CD,总结了这 5 个坑
前端·github·自动化运维
雨季mo浅忆2 小时前
首个Vue3项目边写边学边记
前端·vue3
IT_陈寒3 小时前
React中useEffect依赖项这个坑我居然踩了三天
前端·人工智能·后端
qq4356947013 小时前
Vue04
前端·vue.js
我是真菜4 小时前
彻底理解js中的深浅拷贝
前端·javascript