element-ui中table表格页面汇总固定在第一行

本文介绍了如何在使用Element-UI框架的table组件时,实现表格的表头固定以及添加表尾合计行的功能。通过设置'show-summary'字段,并可自定义合计行显示文字。
摘要由CSDN通过智能技术生成

如图
在这里插入图片描述

首先需要以下样式--注意加入/deep/
  /deep/ .el-table {
   
    display: flex;
    flex-direction: column;
  }
  /
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Element-UItable 组件,可以通过设置 `height` 和 `max-height` 来实现表格固定高度。同时,通过设置 `fixed` 属性可以实现表头固定。要同时实现第一行固定,可以使用 `append` slot,将第一行作为 table 的子组件插入到 table ,并设置其样式为固定位置。 具体实现可以参考以下代码: ```html <template> <el-table :data="tableData" :height="tableHeight" max-height="500px" :header-cell-style="{ 'background-color': '#f5f7fa', 'color': '#333', 'font-weight': 'bold' }" :row-class-name="tableRowClassName" fixed > <template slot="append"> <el-table-column v-for="(item, index) in tableData[0]" :key="index" :label="index === 0 ? '' : item" :width="index === 0 ? '50px' : '100px'" :fixed="index === 0" class-name="first-column" > <template slot-scope="{ row }"> <div v-if="index === 0">{{ row[0] }}</div> <div v-else>{{ row[index] }}</div> </template> </el-table-column> </template> <el-table-column v-for="(item, index) in tableData[0]" :key="index" :prop="index === 0 ? 'id' : item" :label="index === 0 ? 'ID' : item" :width="index === 0 ? '50px' : '100px'" :fixed="index === 0" ></el-table-column> </el-table> </template> <script> export default { data() { return { tableData: [ ['ID', 'Name', 'Age', 'Gender', 'Address'], ['1', 'John', '20', 'Male', 'New York'], ['2', 'Mary', '25', 'Female', 'Los Angeles'], ['3', 'Tom', '30', 'Male', 'Chicago'], ['4', 'Lucy', '35', 'Female', 'Houston'], ['5', 'David', '40', 'Male', 'Philadelphia'] ] } }, computed: { tableHeight() { const headerHeight = document.querySelector('.el-table__header-wrapper').offsetHeight const appendHeight = document.querySelector('.el-table__append-wrapper').offsetHeight return `calc(100vh - ${headerHeight + appendHeight}px)` } }, methods: { tableRowClassName({ rowIndex }) { if (rowIndex === 0) { return 'first-row' } } } } </script> <style scoped> .el-table__header-wrapper { position: sticky; top: 0; z-index: 1; } .el-table__append-wrapper { position: sticky; top: 40px; z-index: 1; } .first-row { position: sticky; top: 40px; z-index: 1; } .first-column { text-align: center; } </style> ``` 在上面的代码,我们通过 `append` slot 将第一行作为子组件插入到 table ,并设置其样式为 `position: sticky; top: 40px;` 实现第一行固定。同时,设置了表头和第一列的 `fixed` 属性,实现表头和第一列固定。为了使表格高度能够自适应页面高度,我们通过计算表头和第一行的高度,来动态设置表格的高度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值