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="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>
.content { width: 100%;height: 500px;
}
</style>

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

System Verilog学习笔记(八)——采样和数据驱动

System Verilog学习笔记&#xff08;八&#xff09;——采样和数据驱动 为了避免在RTL仿真行为中发生的信号竞争问题&#xff0c;可以通过非阻塞赋值或者特定信号延迟来解决同步的问题。 默认情况下&#xff0c;时钟对于组合电路的驱动会添加一个无限小时间&#xff08;delta-…

RLWE同态加密编码打包——系数打包

RLWE同态加密的明文域 RLWE的加密方案&#xff0c;如BGV、BFV&#xff0c;加密的对象&#xff0c;实际上是分圆多项式环上的一个整系数多项式。而我们在平时接触到的需要加密的数据&#xff0c;如图像或者工资&#xff0c;通常是一个数。所以&#xff0c;在使用RLWE同态加密时…

JVM对象创建与内存分配机制

JVM对象创建与内存分配机制 JVM对象创建与内存分配机制 JVM对象创建与内存分配机制对象的创建过程内存分配对象栈上分配对象逃逸分析标量替换 对象在Eden区分配大对象直接进入老年代长期存活的对象将进入老年代对象年龄动态判断老年代空间分配担保机制 对象头与指针压缩对象头利…

课时49:表达式_表达式进阶_集合基础

3.3.2 集合基础 学习目标 这一节&#xff0c;我们从 基础知识、简单实践、小结 三个方面来学习。 基础知识 简介 所谓的集合&#xff0c;主要是针对多个条件表达式组合后的结果&#xff0c;尤其是针对于逻辑场景的组合。初中数学的相关逻辑示意图&#xff1a;表现样式 两个…

将四个主页面配置为 tab-bar 的子路由

使用vant组件库 路由 {path: /, name: layout,component: () > import(/views/layout),children: [{path: , // 默认子路由name: home,component: () > import(/views/home)},{path: qa,name: qa,component: () > import(/views/qa)},{path: video,name: video,compo…

对比CentOS与Ubuntu:选择最适合你的Linux发行版

目录 对比CentOS与Ubuntu&#xff1a;选择最适合你的Linux发行版CentOS vs Ubuntu&#xff1a;概述CentOS vs Ubuntu&#xff1a;安装和配置CentOS vs Ubuntu&#xff1a;性能和稳定性示例代码和解决方案CentOS示例&#xff1a;Ubuntu示例&#xff1a; CentOS vs Ubuntu&#x…

Tips杂记

&#x1f972; &#x1f978; &#x1f90c; &#x1fac0; &#x1fac1; &#x1f977; &#x1f43b;‍❄️&#x1f9a4; &#x1fab6; &#x1f9ad; &#x1fab2; &#x1fab3; &#x1fab0; &#x1fab1; &#x1fab4; &#x1fad0; &#x1fad2; &#x1fad1…

UE5 C++ TPS开发 学习记录(七)

这节课是P16,主要是创建了生命周期的五个回调和委托还有句柄 MultiPlayerSessionSubsystem.h // Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "Subsystems/GameInstanceSu…

阿里云2核4G服务器租用价格85元一年,30元3个月

阿里云2核4G服务器多少钱一年&#xff1f;2核4G服务器1个月费用多少&#xff1f;2核4G服务器30元3个月、85元一年&#xff0c;轻量应用服务器2核4G4M带宽165元一年&#xff0c;本文阿里云服务器网整理的2核4G参加活动的主机是ECS经济型e实例和u1云服务器&#xff0c;阿里云服务…

三分钟数据持久化:Spring Boot, JPA 与 SQLite 的完美融合

三分钟&#xff0c;迎接一个更加高效和简便的开发体验。 在快节奏的软件开发领域&#xff0c;每一个简化工作流程的机会都不容错过。想要一个无需繁琐配置、能够迅速启动的数据持久化方案吗&#xff1f;这篇文章将是你的首选攻略。在这里&#xff0c;我们将向你展示如何将 Spri…

自然语言处理 | 语言模型(LM) 浅析

自然语言处理&#xff08;NLP&#xff09;中的语言模型&#xff08;Language Model, LM&#xff09;是一种统计模型&#xff0c;它的目标是计算一个给定文本序列的概率分布&#xff0c;即对于任意给定的一段文本序列&#xff08;单词序列&#xff09;&#xff0c;语言模型能够估…

关于vue-seamless-scroll插件中使用echarts图表后有些模块中图表不渲染的问题的解决方案

参考网址&#xff1a;https://chenxuan0000.github.io/vue-seamless-scroll/guide/09-echart.html 拿vue2为例来说明 1、引入 执行npm install vue-seamless-scroll // main.js import scroll from vue-seamless-scroll Vue.use(scroll)2、使用 <template><vue-se…

图搜索基础-深度优先搜索

图搜索基础-深度优先搜索 参考原理引入流程解析手推例子 代码实现运行结果结果分析 参考 理论参考&#xff1a;深蓝学院 实现参考&#xff1a;github项目 原理 引入 对于这样一个图&#xff0c;我们试图找到S到G的通路&#xff1a; 计算机程序不会像人眼一样&#xff0c;一…

kafka学习问题

查看topic列表报超时 报错如下&#xff1a; Error while executing topic command : Timed out waiting for a node assignment. Call: listTopics [2024-02-28 14:36:57,024] ERROR org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignm…

如何做代币分析:以 USDT 币为例

作者&#xff1a;lesleyfootprint.network 编译&#xff1a;cicifootprint.network 数据源&#xff1a;USDT Token Dashboard &#xff08;仅包括以太坊数据&#xff09; 在加密货币和数字资产领域&#xff0c;代币分析起着至关重要的作用。代币分析指的是深入研究与代币相关…

DolphinScheduler——工作流实例的生命周期

目录 一、DolphinScheduler架构原理 1.1 系统架构图 1.2 DolphinScheduler核心概念 1.2 创建工作流 1.2.1 如何触发一个工作流实例 1.2.2 任务调度链路监控 1.2.3 Workflow-DAG解析 DAG解析 Dispatch分发流程 Master和Worker的交互过程 1.3 任务运行状态 该篇文章主…

Python·算法·每日一题(2月29日)正则表达式匹配

题目 给你一个字符串 s 和一个字符规律 p&#xff0c;请你来实现一个支持 ‘.’ 和 ‘*’ 的正则表达式匹配。 ‘.’ 匹配任意单个字符‘*’ 匹配零个或多个前面的那一个元素 所谓匹配&#xff0c;是要涵盖 整个 字符串 s的&#xff0c;而不是部分字符串。 示例 示例一 输入…

总是 -bash: gomobile: 命令未找到

总是 -bash: gomobile: 命令未找到 问题描述 我的项目是/Users/$user/go/src/abc.com/project 当我尝试在 /Users/GaryChan/go/src/abc.com/project/sdk 并运行: export ANDROID_HOME/Users/$user/Library/Android/sdk/ndk-bundle/gomobile bind -targetandroid abc.com/p…

【Web】Java反序列化之CC6--HashMap版

前文&#xff1a; 【Web】Java反序列化之再看CC1--LazyMap 上面这篇文章提到&#xff0c;只要调用的LazyMap的get方法&#xff0c;就可以最终完成transform的调用。 在高版本下&#xff0c;CC1不再能打通&#xff0c;CC6依然通用&#xff0c;其反序列化入口不再是Annotation…

Leetcode : 215. 数组中的第 K 个最大元素

给定整数数组 nums 和整数 k&#xff0c;请返回数组中第 k 个最大的元素。 请注意&#xff0c;你需要找的是数组排序后的第 k 个最大的元素&#xff0c;而不是第 k 个不同的元素。 你必须设计并实现时间复杂度为 O(n) 的算法解决此问题。 思路&#xff1a;最开始排序算法&…