Skip to content

Commit 330e6fe

Browse files
committed
Update index.jsx
1 parent 7556ffe commit 330e6fe

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ export default {
1919
type: Boolean,
2020
required: true,
2121
},
22-
tableContainerEl: {
23-
type: HTMLDivElement,
24-
default: null,
25-
},
2622
hooks: {
2723
type: Object,
2824
required: true,
@@ -94,6 +90,8 @@ export default {
9490
left: 0,
9591
top: 0,
9692
},
93+
// table element
94+
tableEl: null,
9795
// cell element
9896
cellEl: null,
9997
// auto resize
@@ -187,6 +185,9 @@ export default {
187185
parentRendered: {
188186
handler: function (val) {
189187
if (val) {
188+
// fixed #471
189+
this.setTableEl();
190+
190191
// add table container scroll hook
191192
this.hooks.addHook(
192193
HOOKS_NAME.TABLE_CONTAINER_SCROLL,
@@ -264,14 +265,22 @@ export default {
264265
},
265266

266267
methods: {
268+
// set table element
269+
setTableEl() {
270+
this.$nextTick(() => {
271+
const tableEl = this.$el.previousElementSibling;
272+
this.tableEl = tableEl;
273+
});
274+
},
275+
267276
// set cell element
268277
setCellEl() {
269-
const { cellSelectionData, tableContainerEl } = this;
278+
const { cellSelectionData, tableEl } = this;
270279

271280
const { rowKey, colKey } = cellSelectionData.currentCell;
272281

273-
if (tableContainerEl) {
274-
const cellEl = tableContainerEl.querySelector(
282+
if (tableEl) {
283+
const cellEl = tableEl.querySelector(
275284
`tbody.ve-table-body tr[row-key="${rowKey}"] td[col-key="${colKey}"]`,
276285
);
277286

@@ -292,16 +301,16 @@ export default {
292301
hasRightFixedColumn,
293302
currentColumn: column,
294303
cellEl,
295-
tableContainerEl,
304+
tableEl,
296305
} = this;
297306

298-
if (cellEl && tableContainerEl) {
307+
if (cellEl && tableEl) {
299308
const {
300309
left: tableLeft,
301310
top: tableTop,
302311
right: tableRight,
303312
bottom: tableBottom,
304-
} = tableContainerEl.getBoundingClientRect();
313+
} = tableEl.getBoundingClientRect();
305314

306315
const {
307316
left: cellLeft,

0 commit comments

Comments
 (0)