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

相关推荐
IT_陈寒5 分钟前
Python项目实战经验分享:为什么你的多进程日志会丢失?
前端·人工智能·后端
柳杉13 分钟前
让 AI 学会审美、建模和剪片:我收藏夹里的 14 个仓库
前端·ai编程·three.js
前端架构师-老李18 分钟前
HTML与CSS基础第七课—HTML 中的a标签(跳转链接)
前端·css·html
Zhao-Jichao25 分钟前
AI Prompting for Everyone 课程笔记 - P08 上下文 Context
人工智能·笔记
鬼手点金29 分钟前
Skills:领域能力的可组合单元
java·人工智能·笔记·自动化·1024程序员节
陈随易1 小时前
一个网吧网管,做了个网页,卖了 5000 万
前端·后端·程序员
jktantan9 小时前
Vue keep-alive 切标签后滚动位置回顶?因为 onDeactivated 里读到的 scrollTop 是 0
前端·javascript·vue.js
夕除10 小时前
Redis 过期策略
redis·笔记·面试
2601_9628857210 小时前
quotes 字段全解:涨跌幅、振幅、换手率的口径与单位
java·前端·spring
excel11 小时前
encodeURI 和 encodeURIComponent 有什么区别?
前端