From a3273188e7ffaeac2ae508603231c8f3e153d31f Mon Sep 17 00:00:00 2001 From: "cinwell.li" Date: Wed, 29 Mar 2017 11:59:12 +0800 Subject: [PATCH] Table: improve performance for rendering tooltip, fixed #3478 (#3836) * Table: improve performance for rendering tooltip, fixed #3478 * Table: add tooltip-effect property --- examples/docs/en-US/table.md | 3 ++- examples/docs/zh-CN/table.md | 3 +++ packages/table/src/table-body.js | 19 +++++++++++++++++-- packages/table/src/table-column.js | 8 +------- packages/table/src/table.vue | 4 +++- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/examples/docs/en-US/table.md b/examples/docs/en-US/table.md index dec042af..084203eb 100644 --- a/examples/docs/en-US/table.md +++ b/examples/docs/en-US/table.md @@ -1440,7 +1440,7 @@ When the row content is too long and you do not want to display the horizontal s |---------- |-------------- |---------- |-------------------------------- |-------- | | data | table data | array | — | — | | height | Table's height. By default it has an `auto` height. If its value is a number, the height is measured in pixels; if its value is a string, the height is affected by external styles | string/number | — | — | -| maxHeight | Table's max-height. The height of the table starts from `auto` until it reaches the maxHeight limit. The `maxHeight` is measured in pixels, same as `height` | string/number | — | — | +| max-height | Table's max-height. The height of the table starts from `auto` until it reaches the maxHeight limit. The `maxHeight` is measured in pixels, same as `height` | string/number | — | — | | stripe | whether table is striped | boolean | — | false | | border | whether table has vertical border | boolean | — | false | | fit | whether width of column automatically fits its container | boolean | — | true | @@ -1454,6 +1454,7 @@ When the row content is too long and you do not want to display the horizontal s | default-expand-all | whether expand all rows by default, only works when the table has a column type="expand" | Boolean | — | false | | expand-row-keys | set expanded rows by this prop, prop's value is the keys of expand rows, you should set row-key before using this prop | Array | — | | | default-sort | set the default sort column and order. property `prop` is used to set default sort column, property `order` is used to set default sort order | Object | `order`: ascending, descending | if `prop` is set, and `order` is not set, then `order` is default to ascending | +| tooltip-effect | tooltip `effect` property | String | dark/light | | dark | ### Table Events | Event Name | Description | Parameters | diff --git a/examples/docs/zh-CN/table.md b/examples/docs/zh-CN/table.md index 48b73b1c..d0d0ea69 100644 --- a/examples/docs/zh-CN/table.md +++ b/examples/docs/zh-CN/table.md @@ -1109,6 +1109,7 @@ ) : '' ] + ).concat( + ) } @@ -142,10 +145,14 @@ export default { data() { return { - tooltipDisabled: true + tooltipContent: '' }; }, + created() { + this.activateTooltip = debounce(50, tooltip => tooltip.handleShowPopper()); + }, + methods: { getKeyOfRow(row, index) { const rowKey = this.table.rowKey; @@ -199,10 +206,18 @@ export default { // 判断是否text-overflow, 如果是就显示tooltip const cellChild = event.target.querySelector('.cell'); - this.tooltipDisabled = cellChild.scrollWidth <= cellChild.offsetWidth; + if (cellChild.scrollWidth > cellChild.offsetWidth) { + const tooltip = this.$refs.tooltip; + + this.tooltipContent = cell.innerText; + tooltip.referenceElm = cell; + tooltip.doDestroy(); + this.activateTooltip(tooltip); + } }, handleCellMouseLeave(event) { + this.$refs.tooltip.handleClosePopper(); const cell = getCell(event); if (!cell) return; diff --git a/packages/table/src/table-column.js b/packages/table/src/table-column.js index ec582705..6260fb6e 100644 --- a/packages/table/src/table-column.js +++ b/packages/table/src/table-column.js @@ -288,13 +288,7 @@ export default { } return _self.showOverflowTooltip || _self.showTooltipWhenOverflow - ? -
{ renderCell(h, data) }
- { renderCell(h, data) } -
+ ?
{ renderCell(h, data) }
:
{ renderCell(h, data) }
; }; }, diff --git a/packages/table/src/table.vue b/packages/table/src/table.vue index 07f49400..173d4ae3 100644 --- a/packages/table/src/table.vue +++ b/packages/table/src/table.vue @@ -169,7 +169,9 @@ defaultExpandAll: Boolean, - defaultSort: Object + defaultSort: Object, + + tooltipEffect: String }, components: {