Skip to content

Commit 49ba441

Browse files
committed
Update index.jsx
1 parent c9694ac commit 49ba441

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

packages/ve-table/src/index.jsx

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,6 @@ export default {
277277
hooks: {},
278278
// is parent rendered
279279
parentRendered: false,
280-
// table container wrapper width
281-
tableContainerWrapperWidth: 0,
282280
// table viewport width except scroll bar width
283281
tableViewportWidth: 0,
284282
/*
@@ -528,6 +526,12 @@ export default {
528526
}
529527
return result;
530528
},
529+
// table container wrapper style
530+
tableContainerWrapperStyle() {
531+
return {
532+
width: "100%",
533+
};
534+
},
531535
// table container style
532536
tableContainerStyle() {
533537
let maxHeight = getValByUnit(this.maxHeight);
@@ -781,6 +785,8 @@ export default {
781785
handler(newVal, oldVal) {
782786
this.initColumns();
783787
this.initGroupColumns();
788+
console.log("???");
789+
this.initColumnWidthByColumnResize();
784790

785791
// 排除首次
786792
if (newVal != oldVal && oldVal) {
@@ -915,49 +921,55 @@ export default {
915921
// body cell width change
916922
bodyCellWidthChange(colWidths) {
917923
this.colgroups = this.colgroups.map((item) => {
918-
// map
919924
item._realTimeWidth = colWidths.get(item.key);
920925
return item;
921926
});
927+
922928
this.hooks.triggerHook(HOOKS_NAME.TABLE_CELL_WIDTH_CHANGE);
923929
},
924930

925-
// set column width
931+
// set column width for column resize
926932
setColumnWidth({ colKey, width }) {
927933
this.colgroups = this.colgroups.map((item) => {
928934
if (item.key === colKey) {
929-
item._realTimeWidth = width;
935+
item._columnResizeWidth = width;
930936
}
931937
return item;
932938
});
939+
this.$nextTick(() => {
940+
this.setScrollBarStatus();
941+
});
933942
this.hooks.triggerHook(HOOKS_NAME.TABLE_CELL_WIDTH_CHANGE);
934943
},
935944

936-
// set table width
937-
setTableWidth(nextTableWidth) {
938-
let tableContainerWrapperEl =
939-
this.$refs[this.tableContainerWrapperRef];
940-
if (tableContainerWrapperEl) {
941-
this.tableContainerWrapperWidth = nextTableWidth;
942-
// 解决列宽拖动有滚动条->无滚动条 表格高度不更新问题
943-
this.$nextTick(() => {
944-
this.setScrollBarStatus();
945-
});
946-
}
947-
},
948-
949945
// update colgroups by sort change
950946
updateColgroupsBySortChange(sortColumns) {
951947
this.colgroups = this.colgroups.map((item) => {
952948
// update colgroups by sort columns
953949
if (Object.keys(sortColumns).indexOf(item.field) > -1) {
954950
item.sortBy = sortColumns[item.field];
955951
}
956-
957952
return item;
958953
});
959954
},
960955

956+
// init column width by column resize
957+
initColumnWidthByColumnResize() {
958+
const { enableColumnResize } = this;
959+
960+
const columnDefaultWidth = 50;
961+
if (enableColumnResize) {
962+
this.colgroups = this.colgroups.map((item) => {
963+
let columnWidth = columnDefaultWidth;
964+
if (isNumber(item.width)) {
965+
columnWidth = item.width;
966+
}
967+
item._columnResizeWidth = columnWidth;
968+
return item;
969+
});
970+
}
971+
},
972+
961973
// init columns
962974
initColumns() {
963975
const { columnHiddenOption } = this;
@@ -3765,7 +3777,6 @@ export default {
37653777
},
37663778
render() {
37673779
const {
3768-
tableContainerWrapperWidth,
37693780
showHeader,
37703781
tableViewportWidth,
37713782
tableContainerStyle,
@@ -3901,11 +3912,7 @@ export default {
39013912
// table container wrapper props
39023913
const tableContainerWrapperProps = {
39033914
ref: this.tableContainerWrapperRef,
3904-
style: {
3905-
width: tableContainerWrapperWidth
3906-
? tableContainerWrapperWidth + "px"
3907-
: "100%",
3908-
},
3915+
style: this.tableContainerWrapperStyle,
39093916
class: {
39103917
"ve-table": true,
39113918
[clsName("border-around")]: this.borderAround,
@@ -4093,9 +4100,6 @@ export default {
40934100
const columnResizerProps = {
40944101
props: {
40954102
parentRendered: this.parentRendered,
4096-
tableRootEl: this.$refs[this.tableRootRef],
4097-
tableContainerWrapperInstance:
4098-
this.$refs[this.tableContainerWrapperRef],
40994103
tableContainerEl: this.$refs[this.tableContainerRef],
41004104
hooks: this.hooks,
41014105
colgroups,
@@ -4104,7 +4108,6 @@ export default {
41044108
setIsColumnResizerHover: this.setIsColumnResizerHover,
41054109
setIsColumnResizing: this.setIsColumnResizing,
41064110
setColumnWidth: this.setColumnWidth,
4107-
setTableWidth: this.setTableWidth,
41084111
columnWidthResizeOption: this.columnWidthResizeOption,
41094112
},
41104113
};

0 commit comments

Comments
 (0)