Commit 8c51d57dca1b0ef77cf441cb839d12e4fa4ac619

Authored by 梁灏
1 parent d9d1dbbd

Table Column add tooltip prop

examples/routers/table.vue
1 <template> 1 <template>
2 <div> 2 <div>
3 - <Table highlight-row ref="currentRowTable" :columns="columns3" :data="data1"></Table> 3 + <Table ref="currentRowTable" :columns="columns3" :data="data1"></Table>
4 <Button @click="handleClearCurrentRow">Clear</Button> 4 <Button @click="handleClearCurrentRow">Clear</Button>
5 </div> 5 </div>
6 </template> 6 </template>
@@ -27,20 +27,21 @@ @@ -27,20 +27,21 @@
27 }, 27 },
28 { 28 {
29 title: 'Address', 29 title: 'Address',
30 - key: 'address' 30 + key: 'address',
  31 + tooltip: true
31 } 32 }
32 ], 33 ],
33 data1: [ 34 data1: [
34 { 35 {
35 name: 'John Brown', 36 name: 'John Brown',
36 age: 18, 37 age: 18,
37 - address: 'New York No. 1 Lake Park', 38 + address: '自定义渲染列,使用 Vue 的 Render 函数。传入两个参数,第一个是 h,第二个为对象,包含 row、column 和 index,分别指当前行数据,当前列数据,当前行索引,详见示例。自定义渲染列,使用 Vue 的 Render 函数。传入两个参数,第一个是 h,第二个为对象,包含 row、column 和 index,分别指当前行数据,当前列数据,当前行索引,详见示例。自定义渲染列,使用 Vue 的 Render 函数。传入两个参数,第一个是 h,第二个为对象,包含 row、column 和 index,分别指当前行数据,当前列数据,当前行索引,详见示例。',
38 date: '2016-10-03' 39 date: '2016-10-03'
39 }, 40 },
40 { 41 {
41 name: 'Jim Green', 42 name: 'Jim Green',
42 age: 24, 43 age: 24,
43 - address: 'London No. 1 Lake Park', 44 + address: 'London No. 1 Lake Park自定义渲染列,使用 Vue 的 Render 函',
44 date: '2016-10-01' 45 date: '2016-10-01'
45 }, 46 },
46 { 47 {
src/components/table/cell.vue
@@ -5,7 +5,14 @@ @@ -5,7 +5,14 @@
5 <Checkbox :value="checked" @click.native.stop="handleClick" @on-change="toggleSelect" :disabled="disabled"></Checkbox> 5 <Checkbox :value="checked" @click.native.stop="handleClick" @on-change="toggleSelect" :disabled="disabled"></Checkbox>
6 </template> 6 </template>
7 <template v-if="renderType === 'html'"><span v-html="row[column.key]"></span></template> 7 <template v-if="renderType === 'html'"><span v-html="row[column.key]"></span></template>
8 - <template v-if="renderType === 'normal'"><span>{{row[column.key]}}</span></template> 8 + <template v-if="renderType === 'normal'">
  9 + <template v-if="column.tooltip">
  10 + <Tooltip transfer :content="row[column.key]" :disabled="!showTooltip" :max-width="300" class="ivu-table-cell-tooltip">
  11 + <span ref="content" @mouseenter="handleTooltipIn" @mouseleave="handleTooltipOut" class="ivu-table-cell-tooltip-content">{{ row[column.key] }}</span>
  12 + </Tooltip>
  13 + </template>
  14 + <span v-else>{{row[column.key]}}</span>
  15 + </template>
9 <template v-if="renderType === 'expand' && !row._disableExpand"> 16 <template v-if="renderType === 'expand' && !row._disableExpand">
10 <div :class="expandCls" @click="toggleExpand"> 17 <div :class="expandCls" @click="toggleExpand">
11 <Icon type="ios-arrow-forward"></Icon> 18 <Icon type="ios-arrow-forward"></Icon>
@@ -23,10 +30,11 @@ @@ -23,10 +30,11 @@
23 import Cell from './expand'; 30 import Cell from './expand';
24 import Icon from '../icon/icon.vue'; 31 import Icon from '../icon/icon.vue';
25 import Checkbox from '../checkbox/checkbox.vue'; 32 import Checkbox from '../checkbox/checkbox.vue';
  33 + import Tooltip from '../tooltip/tooltip.vue';
26 34
27 export default { 35 export default {
28 name: 'TableCell', 36 name: 'TableCell',
29 - components: { Icon, Checkbox, Cell }, 37 + components: { Icon, Checkbox, Cell, Tooltip },
30 props: { 38 props: {
31 prefixCls: String, 39 prefixCls: String,
32 row: Object, 40 row: Object,
@@ -45,7 +53,8 @@ @@ -45,7 +53,8 @@
45 return { 53 return {
46 renderType: '', 54 renderType: '',
47 uid: -1, 55 uid: -1,
48 - context: this.$parent.$parent.$parent.currentContext 56 + context: this.$parent.$parent.$parent.currentContext,
  57 + showTooltip: false, // 鼠标滑过overflow文本时,再检查是否需要显示
49 }; 58 };
50 }, 59 },
51 computed: { 60 computed: {
@@ -78,6 +87,13 @@ @@ -78,6 +87,13 @@
78 }, 87 },
79 handleClick () { 88 handleClick () {
80 // 放置 Checkbox 冒泡 89 // 放置 Checkbox 冒泡
  90 + },
  91 + handleTooltipIn () {
  92 + const $content = this.$refs.content;
  93 + this.showTooltip = $content.scrollWidth > $content.offsetWidth;
  94 + },
  95 + handleTooltipOut () {
  96 + this.showTooltip = false;
81 } 97 }
82 }, 98 },
83 created () { 99 created () {
src/styles/components/table.less
@@ -158,6 +158,16 @@ @@ -158,6 +158,16 @@
158 text-overflow: ellipsis; 158 text-overflow: ellipsis;
159 } 159 }
160 160
  161 + &-tooltip{
  162 + width: 100%;
  163 + &-content{
  164 + display: block;
  165 + overflow: hidden;
  166 + text-overflow: ellipsis;
  167 + white-space: nowrap;
  168 + }
  169 + }
  170 +
161 &-with-expand{ 171 &-with-expand{
162 height: 47px; 172 height: 47px;
163 line-height: 47px; 173 line-height: 47px;