Table Column add tooltip prop

This commit is contained in:
梁灏 2018-06-29 11:24:26 +08:00
parent d9d1dbbd5a
commit 8c51d57dca
3 changed files with 34 additions and 7 deletions

View file

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<Table highlight-row ref="currentRowTable" :columns="columns3" :data="data1"></Table> <Table ref="currentRowTable" :columns="columns3" :data="data1"></Table>
<Button @click="handleClearCurrentRow">Clear</Button> <Button @click="handleClearCurrentRow">Clear</Button>
</div> </div>
</template> </template>
@ -27,20 +27,21 @@
}, },
{ {
title: 'Address', title: 'Address',
key: 'address' key: 'address',
tooltip: true
} }
], ],
data1: [ data1: [
{ {
name: 'John Brown', name: 'John Brown',
age: 18, age: 18,
address: 'New York No. 1 Lake Park', address: '自定义渲染列,使用 Vue 的 Render 函数。传入两个参数,第一个是 h第二个为对象包含 row、column 和 index分别指当前行数据当前列数据当前行索引详见示例。自定义渲染列使用 Vue 的 Render 函数。传入两个参数,第一个是 h第二个为对象包含 row、column 和 index分别指当前行数据当前列数据当前行索引详见示例。自定义渲染列使用 Vue 的 Render 函数。传入两个参数,第一个是 h第二个为对象包含 row、column 和 index分别指当前行数据当前列数据当前行索引详见示例。',
date: '2016-10-03' date: '2016-10-03'
}, },
{ {
name: 'Jim Green', name: 'Jim Green',
age: 24, age: 24,
address: 'London No. 1 Lake Park', address: 'London No. 1 Lake Park自定义渲染列,使用 Vue 的 Render 函',
date: '2016-10-01' date: '2016-10-01'
}, },
{ {

View file

@ -5,7 +5,14 @@
<Checkbox :value="checked" @click.native.stop="handleClick" @on-change="toggleSelect" :disabled="disabled"></Checkbox> <Checkbox :value="checked" @click.native.stop="handleClick" @on-change="toggleSelect" :disabled="disabled"></Checkbox>
</template> </template>
<template v-if="renderType === 'html'"><span v-html="row[column.key]"></span></template> <template v-if="renderType === 'html'"><span v-html="row[column.key]"></span></template>
<template v-if="renderType === 'normal'"><span>{{row[column.key]}}</span></template> <template v-if="renderType === 'normal'">
<template v-if="column.tooltip">
<Tooltip transfer :content="row[column.key]" :disabled="!showTooltip" :max-width="300" class="ivu-table-cell-tooltip">
<span ref="content" @mouseenter="handleTooltipIn" @mouseleave="handleTooltipOut" class="ivu-table-cell-tooltip-content">{{ row[column.key] }}</span>
</Tooltip>
</template>
<span v-else>{{row[column.key]}}</span>
</template>
<template v-if="renderType === 'expand' && !row._disableExpand"> <template v-if="renderType === 'expand' && !row._disableExpand">
<div :class="expandCls" @click="toggleExpand"> <div :class="expandCls" @click="toggleExpand">
<Icon type="ios-arrow-forward"></Icon> <Icon type="ios-arrow-forward"></Icon>
@ -23,10 +30,11 @@
import Cell from './expand'; import Cell from './expand';
import Icon from '../icon/icon.vue'; import Icon from '../icon/icon.vue';
import Checkbox from '../checkbox/checkbox.vue'; import Checkbox from '../checkbox/checkbox.vue';
import Tooltip from '../tooltip/tooltip.vue';
export default { export default {
name: 'TableCell', name: 'TableCell',
components: { Icon, Checkbox, Cell }, components: { Icon, Checkbox, Cell, Tooltip },
props: { props: {
prefixCls: String, prefixCls: String,
row: Object, row: Object,
@ -45,7 +53,8 @@
return { return {
renderType: '', renderType: '',
uid: -1, uid: -1,
context: this.$parent.$parent.$parent.currentContext context: this.$parent.$parent.$parent.currentContext,
showTooltip: false, // overflow
}; };
}, },
computed: { computed: {
@ -78,6 +87,13 @@
}, },
handleClick () { handleClick () {
// Checkbox // Checkbox
},
handleTooltipIn () {
const $content = this.$refs.content;
this.showTooltip = $content.scrollWidth > $content.offsetWidth;
},
handleTooltipOut () {
this.showTooltip = false;
} }
}, },
created () { created () {

View file

@ -158,6 +158,16 @@
text-overflow: ellipsis; text-overflow: ellipsis;
} }
&-tooltip{
width: 100%;
&-content{
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
&-with-expand{ &-with-expand{
height: 47px; height: 47px;
line-height: 47px; line-height: 47px;