eltable 合计行添加tooltip

eltable 合计行添加tooltip

  • 问题描述:
    eltable 合计行单元格内容过长会换行,需求要求合计行数据超长显示 … ,鼠标 hover 时显示提示信息。
    在这里插入图片描述

  • 解决方案:eltable合计行没有对外的修改接口,想法是 自己实现一个tooltip, 为合计行单元添加鼠标移入移出事件,移入显示tooltip,移出隐藏tooltip,tooltip的定位和内容通过移入时拿到单元格位置和内容。

  • 实现代码 (最后有优化代码)

<template><div class="content"><el-table show-summary :data="data"><el-table-columnv-for="item in header"v-bind="item":show-overflow-tooltip="true"></el-table-column></el-table><!-- 自定义tooltip --><Transition name="el-fade-in"><div v-show="toolTipVisble" id="customTooltip" ref="customTooltip">{{ tipMsg }}<div class="popper__arrow"></div></div></Transition></div>
</template>
<script>
export default {components: {},data() {return {//合计行提示toolTipVisble: false,tipMsg: "",header: [{ label: "列1", prop: "col1", width: "70px" },{ label: "列2", prop: "col2", width: "70px" },{ label: "列3", prop: "col3", width: "70px" },{ label: "列4", prop: "col4", minWidth: "70px" },],data: [{col1: "23333333333333",col2: "2345679",col3: "66666666666666",col4: "4",},{ col1: "2", col2: "2", col3: "3", col4: "4" },{ col1: "2", col2: "2", col3: "3", col4: "4" },{ col1: "2", col2: "2", col3: "3", col4: "4" },{ col1: "2", col2: "2", col3: "3", col4: "4" },],};},mounted() {this.setSummaryListener();},methods: {setSummaryListener() {let that = this;let table = document.querySelector(".el-table__footer-wrapper>table");this.$nextTick(() => {for (let rowIndex = 0; rowIndex < table.rows.length; rowIndex++) {let row = table.rows[rowIndex].cells;for (let colIndex = 0; colIndex < row.length; colIndex++) {let col = row[colIndex];let cells = col.getElementsByClassName("cell");if (cells && cells.length > 0) {let cell = cells[0];if (cell.scrollWidth > cell.offsetWidth) {cell.onmouseenter = function () {that.setTooltip(true, rowIndex, colIndex, cell);};cell.onmouseleave = function () {that.setTooltip(false, rowIndex, colIndex, cell);};}}}}});},setTooltip(isShow, rowIndex, columnIndex, colEl) {this.toolTipVisble = isShow;if (isShow) {this.tipMsg = colEl.innerText || colEl.textContent;let toolTip = this.$refs.customTooltip;let rect = colEl.getBoundingClientRect();//向上偏移量const offsetTop = 50;toolTip.style.top = rect.top - offsetTop + "px";this.$nextTick(() => {const cellBorderWidth = 1;toolTip.style.left =rect.left -(toolTip.offsetWidth / 2 -(colEl.offsetWidth + cellBorderWidth * 2) / 2) +"px";});}},},
};
</script>
<style>
/* 合计行单元格样式 */
.el-table__footer-wrapper .el-table__footer .el-table__cell .cell {overflow: hidden;text-overflow: ellipsis;word-break: break-all;white-space: nowrap;
}
</style><style lang="scss" scoped>
#customTooltip {position: absolute;transform-origin: center bottom;background: #303133;color: #fff;border-radius: 4px;padding: 10px;font-size: 12px;line-height: 1.2;word-wrap: break-word;.popper__arrow {position: absolute;display: block;width: 0px;height: 0px;bottom: -12px;left: 42%;border-left: 6px solid transparent;border-right: 6px solid transparent;border-bottom: 6px solid transparent;border-top: 6px solid #303133;}
}
.content {display: flex;flex-direction: column;width: 100%;height: 500px;
}
</style>
  • 实现效果
    在这里插入图片描述
  • 瞅瞅源码
    eltable 数据行单元格提示信息show-overflow-tooltip源码实现思路跟上面差不多。
    单元格的提示信息也是绑定鼠标移入移出事件,提示信息用的el-tooltip。
    el-tooltip:这里el-tooltip标签里面没有内容,之后通过鼠标移入事件绑定。
    在这里插入图片描述
    单元格绑定鼠标事件
    在这里插入图片描述
    referenceElm 绑定目标对象(提示信息定位对象)。
    在这里插入图片描述
  • 优化一下我自己写的tooltip,用el-tooltip实现。
<template><div class="all-overview-content"><el-table show-summary :data="data"><el-table-columnv-for="item in header"v-bind="item":show-overflow-tooltip="true"></el-table-column></el-table><!-- 自定义tooltip --><!-- <Transition name="el-fade-in"><div v-show="toolTipVisble" id="customTooltip" ref="customTooltip">{{ tipMsg }}<div class="popper__arrow"></div></div></Transition> --><el-tooltipplacement="top"ref="tooltip":content="tooltipContent"></el-tooltip></div>
</template><script>
export default {components: {},data() {return {tooltipContent: "",header: [{ label: "列1", prop: "col1", width: "70px" },{ label: "列2", prop: "col2", width: "70px" },{ label: "列3", prop: "col3", width: "70px" },{ label: "列4", prop: "col4", minWidth: "500px" },],data: [{col1: "23333333333333",col2: "2345679",col3: "66666666666666",col4: "4",},{ col1: "2", col2: "2", col3: "3", col4: "4" },{ col1: "2", col2: "2", col3: "3", col4: "4" },{ col1: "2", col2: "2", col3: "3", col4: "4" },{ col1: "2", col2: "2", col3: "3", col4: "4" },],};},mounted() {this.setSummaryListener();},methods: {setSummaryListener() {let that = this;let table = document.querySelector(".el-table__footer-wrapper>table");this.$nextTick(() => {for (let rowIndex = 0; rowIndex < table.rows.length; rowIndex++) {let row = table.rows[rowIndex].cells;for (let colIndex = 0; colIndex < row.length; colIndex++) {let col = row[colIndex];let cells = col.getElementsByClassName("cell");if (cells && cells.length > 0) {let cell = cells[0];if (cell.scrollWidth > cell.offsetWidth) {cell.onmouseenter = function () {that.setTooltip(true, rowIndex, colIndex, cell);};cell.onmouseleave = function () {that.setTooltip(false, rowIndex, colIndex, cell);};}}}}});},setTooltip(isShow, rowIndex, columnIndex, colEl) {const tooltip = this.$refs.tooltip;if (isShow) {this.tooltipContent = colEl.innerText || colEl.textContent;tooltip.referenceElm = colEl;tooltip.$refs.popper && (tooltip.$refs.popper.style.display = "none");tooltip.doDestroy();tooltip.setExpectedState(true);tooltip.handleShowPopper();} else {tooltip.setExpectedState(false);tooltip.handleClosePopper();}},},
};
</script><style>
/* 合计行单元格样式 */
.el-table__footer-wrapper .el-table__footer .el-table__cell .cell {overflow: hidden;text-overflow: ellipsis;word-break: break-all;white-space: nowrap;
}
</style><style lang="scss" scoped>
.all-overview-content {display: flex;flex-direction: column;width: 100%;height: 500px;
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/2815791.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

【GB28181】wvp-GB28181-pro快速修改登录页面名称(前端)

引言 作为一个非前端开发人员,自己摸索起来比较费劲,也浪费了很多时间 本文快速帮助开发者修改为自己名称的一个国标平台 文章目录 一、 预期效果展示二、 源码修改-前端三、 验证修改效果一、 预期效果展示 二、 源码修改-前端 需要修改的文件位置: 项目工程下web_src目录…

高并发数据采集:Ebay商家信息多进程爬虫的进阶实践

背景 Ebay作为全球最大的电子商务平台之一&#xff0c;其商家信息包含丰富的市场洞察。然而&#xff0c;要高效获取这些信息&#xff0c;就需要利用先进的技术手段。本文将深入探讨如何通过并发加速技术&#xff0c;实现Ebay商家信息多进程爬虫的最佳实践方法&#xff0c;并附…

Find My运动相机|苹果Find My技术与相机结合,智能防丢,全球定位

运动相机设计用于在各种运动和极限环境中使用&#xff0c;如徒步、登山、攀岩、骑行、滑翔、滑雪、游泳和潜水等&#xff0c;它们通常具有防抖防震、深度防水和高清画质的特点&#xff0c;能够适应颠簸剧烈的环境&#xff0c;甚至可以承受一定程度的摔落&#xff0c;一些运动相…

skywalking展示http请求和响应

1.效果图 可以在请求中看到自定义请求信息input和返回值output&#xff0c;方便快速定位问题 2.添加依赖 <dependency><groupId>org.apache.skywalking</groupId><artifactId>apm-toolkit-trace</artifactId><version>9.1.0</version&…

MySQL的Redo Log、Undo Log、Binlog与Replay Log日志

前言 MySQL数据库作为业界最流行的开源关系型数据库之一&#xff0c;其底层实现涉及多种重要的日志机制&#xff0c;其中包括Redo Log、Undo Log、Binlog和Replay Log。这些日志组件共同确保MySQL数据库系统在面对事务处理、数据恢复和主从复制等方面表现出色。本文主要介绍一下…

pytorch 图像的卷积操作

目录 1.卷积核基本参数说明 2.卷积相关操作说明 3.卷积操作示例 1.卷积核基本参数说明 pytorch进行图像卷积操作之前&#xff0c;需要把图像素格式进行分离&#xff0c;比如一个图像为rgb格式&#xff0c;把R&#xff0c;G,B取出来作为一个ndarray&#xff0c;前文讲过&#…

ARM系列 -- 虚拟化(三)

为了实现虚拟化&#xff0c;虚拟机需要控制系统资源。但是实际的系统资源是在hypervisor直接控制之下&#xff0c;为了实现隔离和安全等方面的考虑&#xff0c;不可能让虚拟机直接控制这些系统资源。 比如&#xff0c;虚拟机想根据具体情况去做电源管理。一个解决办法就是利用…

.net 在ubuntu下动态写入 中文字乱码 解决:ubuntu下添加中文字库

.net 在ubuntu下动态写入图片水印 中文字乱码 解决&#xff1a;ubuntu下添加中文字库 1.安装字体命令 sudo apt install -y fontconfig2.查看已安装的字体 &#xff08;1&#xff09;查看linux已安装字体 fc-list&#xff08;2&#xff09;查看linux已安装中文字体 fc-li…

字节面试问题

实现三列布局的方法 第一种&#xff1a;可以使用浮动margin 第二种&#xff1a;浮动BFC <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, in…

力扣 第 386 场周赛 解题报告 | 反悔贪心

力扣 第 386 场周赛 解题报告 | 反悔贪心 前言 整体评价 前两天发烧&#xff0c;今天才补完题&#xff08;非常惭愧&#xff09;第三题的二分不容易想到&#xff0c;第四题的 “反悔堆” 这种思想值得学习。 T1 分割数组 思路&#xff1a;通过哈希表保证不存在出现两次以上…

常见的主流媒体有哪些?主流媒体报道的优势

传媒如春雨&#xff0c;润物细无声&#xff0c;大家好&#xff0c;我是51媒体胡老师。 主流媒体通常指的是具有广泛影响力和权威性的媒体机构&#xff0c;它们在新闻报道、舆论引导等方面扮演着重要角色。 常见的主流媒体包括但不限于&#xff1a; 电视媒体&#xff1a;如总台…

PHP+vue+mysql高校学生健康管理系统fe93x

。高校学生健康管理平台采用系统设计遵循界面层、业务逻辑层和数据访问层的Web开发三层架构。采用B/S结构,使得系统更加容易维护。高校学生健康 管理平台主要实现角色有管理员和学生,医护人员,辅导员,管理员在后台管理诊断结果模块、医护咨询模块、医护人员模块、医护回复模块、…

国际黄金价格是什么?和黄金价格有何区别?

黄金是世界上最珍贵的贵金属之一&#xff0c;其价值被无数人所垂涎。而国际黄金价格作为市场上的参考指标&#xff0c;直接影响着黄金交易的买卖。那么国际黄金价格到底是什么&#xff0c;与黄金价格又有何区别呢&#xff1f;本文将为您详细解答。 国际黄金价格是指以美元计量的…

多源视频融合平台VMS/smarteye,免费的GB28181 server, 免费的RTMP推流server,RTSP server

海康、大华、宇视等网络摄像机IPcamera及DVR/NVR等多路设备走国标28181接入视频混合融合平台smarteye 第三方国标摄像头走GB28181接入视频融合平台VMS/smarteye&#xff0c; 平台已为设备预分配了SIP帐号&#xff0c;这样免去了找平台人员索要接入SIP帐号的麻烦&#xff0c;可…

深入理解c指针(五)

目录 八、指针与数组 1、数组名的理解 2、使用指针访问数组 3、一维数组传参的本质 4、冒泡排序 5、二级指针 6、指针数组 7、指针数组模拟二维数组 八、指针与数组 int arr[10] {1,2,3,4,5,6,7,8,9,10}; int *p &arr[0]; 1、数组名的理解 某一数组名就是该数组…

深度学习PyTorch 之 RNN-中文多分类

关于RNN的理论部分我们已经在前面介绍过&#xff0c;所以这里直接上代码 1、 数据部分 1.1 读取数据 # 加载数据 data_path ./data/news.csv data pd.read_csv(data_path)# 预览数据的前几行 data.head()数据是csv格式&#xff0c;只有两列&#xff0c;第一列是标签&#…

Django数据库配置+迁移

目录 配置settings.py 在项目下新建bookstore应用 将新建应用添加到项目中 创建模型 执行数据库信息迁移 新增或修改数据库的信息 配置settings.py 找到项目同名文件夹下的settings.py文件&#xff0c;将原有的django默认配置修改为下图 引擎只需要将最后一部分改为对应…

网络:IPv6

1、由于IPv4地址资源枯竭&#xff0c;所以产生了IPV6。 版本长度地址数量IPv432 bit4 294 967 296IPv6128 bit340 282 366 920 938 463 374 607 431 768 211 456 2、IPv6的基本报头在IPv4报头基础上&#xff0c;增加了流标签域&#xff0c;去除了一些冗余字段&#xff0c;使报…

Mint_21.3 drawing-area和goocanvas的FB笔记(一)

一、关于freebasic和goocanvas Linux下的FreeBasic是C的一种实现&#xff0c;有指针、类、线程&#xff0c;正则表达式&#xff0c;可内嵌asm和其它语言c等&#xff0c;c的h库几乎都能改写后使用(不能直接用&#xff0c;它的.bi可从h近乎自动转换)&#xff0c;老的Quick Basic…

搭建服务器及跨域处理

使用内置的模块搭建服务器 自己电脑: 域名:localhost ip:127.0.0.1 http模块搭建服务器 const http = require(http)// 创建一个http对应的服务器,每次改完服务器的代码后都需要重新启动下服务器 /*方式一: const server = http.createServer((request,response)=>{…