查看: 75|回复: 0

vxe-table 单元格超出隐藏内容提示使用自定义插槽模板

[复制链接]

2

主题

0

回帖

0

积分

积极分子

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2008-7-24
发表于 2025-9-5 18:00:00 | 显示全部楼层 |阅读模式

vxe-table 单元格超出隐藏内容提示使用自定义插槽模板
当内容溢出时显示为省略号,show-overflow 和 show-header-overflow 和 show-footer-overflow
如果需要更灵活的展示,还可以使用自定义提示插槽模板,通过 headert-tooltip、tooltip、footer-tooltip 来自定义模板

查看官网:https://vxetable.cn
gitbub:https://github.com/x-extends/vxe-table
gitee:https://gitee.com/x-extends/vxe-table

效果

代码

单元格提示模板,使用插槽 headert-tooltip、tooltip、footer-tooltip 来自定义模板

<template>
  <div>
    <vxe-grid v-bind="gridOptions">
      <template #header-tooltip="{ column }">
        <span style="color: red;">自定义表头:{{ column.title }}</span>
      </template>
      <template #tooltip="{ row, column }">
        <div>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
        </div>
      </template>
      <template #footer-tooltip="{ row, column }">
        <span style="color: chartreuse">自定义表尾:{{ row[column.field] }}</span>
      </template>
    </vxe-grid>
  </div>
</template>

<script setup>
import { reactive } from 'vue'

const gridOptions = reactive({
  showOverflow: true,
  showHeaderOverflow: true,
  showFooterOverflow: true,
  showFooter: true,
  columns: [
    { field: 'seq', type: 'seq', width: 70 },
    { field: 'name', title: '名称' },
    { field: 'role', title: '角色' },
    { field: 'date', title: '日期日期日期日期日期日期日期日期日期', width: 200 },
    { field: 'rate', title: 'Rate' },
    { field: 'address', title: '地址地址地址地址地址地址地址地址地址地址', width: 200 }
  ],
  data: [
    { name: 'Test1', role: '前端', date: '2020-02-14', rate: 5, address: 'address1' },
    { name: 'Test2', role: '后端', date: '2020-02-22', rate: 2, address: 'address1' },
    { name: 'Test3', role: '前端', date: '2020-01-01', rate: 0, address: '深圳市深圳市深圳市深圳市深圳市深圳市' },
    { name: 'Test4', role: '设计师', date: '2020-02-23', rate: 1, address: '上海市上海市上海市上海市上海市上海市' },
    { name: 'Test5', role: '前端', date: '2020-01-20', rate: 3, address: '广州市广州市广州市广州市广州市广州市广州市广州市广州市' }
  ],
  footerData: [
    { seq: '合计', date: '2020-02-23', rate: '123456789123456789123456789123456789' }
  ]
})
</script>

自定义宽高

<template>
  <div>
    <vxe-grid v-bind="gridOptions">
      <template #header-tooltip="{ column }">
        <div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
          <div style="color: red;">自定义表头:{{ column.title }}</div>
        </div>
      </template>
      <template #tooltip="{ row, column }">
        <div style="width: 800px;">
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
          <div style="color: orange;">自定义:{{ row[column.field] }}</div>
          <vxe-link status="primary" href="https://vxeui.com/" target="_blank">点击查看官网</vxe-link>
        </div>
      </template>
      <template #footer-tooltip="{ row, column }">
        <div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
          <div style="color: chartreuse">自定义表尾:{{ row[column.field] }}</div>
        </div>
      </template>
    </vxe-grid>
  </div>
</template>

<script setup>
import { reactive } from 'vue'
const gridOptions = reactive({
  height: 300,
  showOverflow: true,
  showHeaderOverflow: true,
  showFooterOverflow: true,
  showFooter: true,
  tooltipConfig: {
    enterable: true,
    maxWidth: 400,
    maxHeight: 300
  },
  columns: [
    { field: 'seq', type: 'seq', width: 70 },
    { field: 'name', title: '名称' },
    { field: 'role', title: '角色' },
    { field: 'date', title: '日期日期日期日期日期日期日期日期日期', width: 200 },
    { field: 'rate', title: 'Rate' },
    { field: 'address', title: '地址地址地址地址地址地址地址地址地址地址', width: 200 }
  ],
  data: [
    { name: 'Test1', role: '前端', date: '2020-02-14', rate: 5, address: 'address1' },
    { name: 'Test2', role: '后端', date: '2020-02-22', rate: 2, address: 'address1' },
    { name: 'Test3', role: '前端', date: '2020-01-01', rate: 0, address: '深圳市深圳市深圳市深圳市深圳市深圳市' },
    { name: 'Test4', role: '设计师', date: '2020-02-23', rate: 1, address: '上海市上海市上海市上海市上海市上海市' },
    { name: 'Test5', role: '前端', date: '2020-01-20', rate: 3, address: '广州市广州市广州市广州市广州市广州市广州市广州市广州市' }
  ],
  footerData: [
    { seq: '合计', date: '2020-02-23', rate: '123456789123456789123456789123456789' }
  ]
})
</script>

https://gitee.com/x-extends/vxe-table



来源:https://www.cnblogs.com/qaz666/p/19075909
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部