Skip to content

Commit 0262af8

Browse files
author
huangshuwei
committed
Fix sticky layout failure when switching fixed columns
1 parent 4b29076 commit 0262af8

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

packages/ve-table/src/body/index.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import BodyTr from "./body-tr";
22
import ExpandTr from "./expand-tr";
33
import VueDomResizeObserver from "../../../src/comps/resize-observer";
4-
import { clsName } from "../util";
4+
import { clsName, getDomResizeObserverCompKey } from "../util";
55
import { getValByUnit } from "../../../src/utils/index.js";
66
import emitter from "../../../src/mixins/emitter";
77
import {
@@ -19,6 +19,10 @@ export default {
1919
name: COMPS_NAME.VE_TABLE_BODY,
2020
mixins: [emitter],
2121
props: {
22+
columnsOptionResetTime: {
23+
type: Number,
24+
default: 0
25+
},
2226
colgroups: {
2327
type: Array,
2428
required: true
@@ -796,7 +800,10 @@ export default {
796800
<tr style="height:0;">
797801
{colgroups.map(column => {
798802
const measureTdProps = {
799-
key: column.key,
803+
key: getDomResizeObserverCompKey(
804+
column.key,
805+
this.columnsOptionResetTime
806+
),
800807
props: {
801808
tagName: "td",
802809
id: column.key

packages/ve-table/src/header/header-tr.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import HeaderTh from "./header-th";
2-
import { clsName } from "../util";
2+
import { clsName, getDomResizeObserverCompKey } from "../util";
33
import { COMPS_NAME, EMIT_EVENTS } from "../util/constant";
44
import VueDomResizeObserver from "../../../src/comps/resize-observer";
55
import emitter from "../../../src/mixins/emitter";
66
export default {
77
name: COMPS_NAME.VE_TABLE_THADER_TR,
88
mixins: [emitter],
99
props: {
10+
columnsOptionResetTime: {
11+
type: Number,
12+
default: 0
13+
},
1014
// group columns item
1115
groupColumn: {
1216
type: Array,
@@ -148,6 +152,10 @@ export default {
148152
};
149153

150154
const trProps = {
155+
key: getDomResizeObserverCompKey(
156+
rowIndex,
157+
this.columnsOptionResetTime
158+
),
151159
class: clsName("header-tr"),
152160
props: {
153161
tagName: "tr"

packages/ve-table/src/header/index.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { COMPS_NAME, EMIT_EVENTS } from "../util/constant";
55
export default {
66
name: COMPS_NAME.VE_TABLE_THADER,
77
props: {
8+
columnsOptionResetTime: {
9+
type: Number,
10+
default: 0
11+
},
812
groupColumns: {
913
type: Array,
1014
required: true
@@ -137,6 +141,8 @@ export default {
137141
const trProps = {
138142
key: rowIndex,
139143
props: {
144+
columnsOptionResetTime: this
145+
.columnsOptionResetTime,
140146
groupColumn,
141147
headerRows,
142148
colgroups,

packages/ve-table/src/index.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ export default {
163163
},
164164
data() {
165165
return {
166+
/*
167+
列配置变化次数
168+
依赖columns 配置渲染,都需要重新计算:粘性布局时,重新触发 on-dom-resize-change 事件
169+
*/
170+
columnsOptionResetTime: 0,
166171
tableContainerRef: "tableContainerRef",
167172
tableContentRef: "tableContentRef",
168173
virtualPhantomRef: "virtualPhantomRef",
@@ -409,7 +414,10 @@ export default {
409414
immediate: true
410415
},
411416
columns: {
412-
handler() {
417+
handler(newVal, oldVal) {
418+
if (newVal != oldVal) {
419+
this.columnsOptionResetTime++;
420+
}
413421
this.initColumns();
414422
this.initGroupColumns();
415423
},
@@ -988,6 +996,7 @@ export default {
988996
const headerProps = {
989997
class: clsName("header"),
990998
props: {
999+
columnsOptionResetTime: this.columnsOptionResetTime,
9911000
groupColumns,
9921001
colgroups,
9931002
fixedHeader,
@@ -1003,6 +1012,7 @@ export default {
10031012
const bodyProps = {
10041013
class: [clsName("body"), this.tableBodyClass],
10051014
props: {
1015+
columnsOptionResetTime: this.columnsOptionResetTime,
10061016
colgroups,
10071017
expandOption,
10081018
checkboxOptipon,

0 commit comments

Comments
 (0)