Skip to content

Commit 43c961c

Browse files
committed
fix: table customRow events not work #1881
1 parent eac21b4 commit 43c961c

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

components/vc-table/src/BaseTable.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,16 @@ const BaseTable = {
145145

146146
render() {
147147
const { sComponents: components, prefixCls, scroll, data, getBodyWrapper } = this.table;
148-
const { expander, tableClassName, hasHead, hasBody, fixed } = this.$props;
148+
const { expander, tableClassName, hasHead, hasBody, fixed, isAnyColumnsFixed } = this.$props;
149149

150150
const tableStyle = {};
151151

152152
if (!fixed && scroll.x) {
153-
tableStyle.width = scroll.x === true ? 'max-content' : scroll.x;
153+
// 当有固定列时,width auto 会导致 body table 的宽度撑不开,从而固定列无法对齐
154+
// 详情见:https://github.com/ant-design/ant-design/issues/22160
155+
const tableWidthScrollX = isAnyColumnsFixed ? 'max-content' : 'auto';
156+
// not set width, then use content fixed width
157+
tableStyle.width = scroll.x === true ? tableWidthScrollX : scroll.x;
154158
tableStyle.width =
155159
typeof tableStyle.width === 'number' ? `${tableStyle.width}px` : tableStyle.width;
156160
}

components/vc-table/src/TableRow.jsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,36 @@ const TableRow = {
8383
}
8484
},
8585
methods: {
86-
onRowClick(event) {
86+
onRowClick(event, rowPropFunc = noop) {
8787
const { record, index } = this;
8888
this.__emit('rowClick', record, index, event);
89+
rowPropFunc(event);
8990
},
9091

91-
onRowDoubleClick(event) {
92+
onRowDoubleClick(event, rowPropFunc = noop) {
9293
const { record, index } = this;
9394
this.__emit('rowDoubleClick', record, index, event);
95+
rowPropFunc(event);
9496
},
9597

96-
onContextMenu(event) {
98+
onContextMenu(event, rowPropFunc = noop) {
9799
const { record, index } = this;
98100
this.__emit('rowContextmenu', record, index, event);
101+
rowPropFunc(event);
99102
},
100103

101-
onMouseEnter(event) {
104+
onMouseEnter(event, rowPropFunc = noop) {
102105
const { record, index, rowKey } = this;
103106
this.__emit('hover', true, rowKey);
104107
this.__emit('rowMouseenter', record, index, event);
108+
rowPropFunc(event);
105109
},
106110

107-
onMouseLeave(event) {
111+
onMouseLeave(event, rowPropFunc = noop) {
108112
const { record, index, rowKey } = this;
109113
this.__emit('hover', false, rowKey);
110114
this.__emit('rowMouseleave', record, index, event);
115+
rowPropFunc(event);
111116
},
112117

113118
setExpandedRowHeight() {
@@ -241,15 +246,26 @@ const TableRow = {
241246
customClassName,
242247
customClass,
243248
);
249+
const rowPropEvents = rowProps.on || {};
244250
const bodyRowProps = mergeProps(
245251
{ ...rowProps, style },
246252
{
247253
on: {
248-
click: this.onRowClick,
249-
dblclick: this.onRowDoubleClick,
250-
mouseenter: this.onMouseEnter,
251-
mouseleave: this.onMouseLeave,
252-
contextmenu: this.onContextMenu,
254+
click: e => {
255+
this.onRowClick(e, rowPropEvents.click);
256+
},
257+
dblclick: e => {
258+
this.onRowDoubleClick(e, rowPropEvents.dblclick);
259+
},
260+
mouseenter: e => {
261+
this.onMouseEnter(e, rowPropEvents.mouseenter);
262+
},
263+
mouseleave: e => {
264+
this.onMouseLeave(e, rowPropEvents.mouseleave);
265+
},
266+
contextmenu: e => {
267+
this.onContextMenu(e, rowPropEvents.contextmenu);
268+
},
253269
},
254270
class: rowClassName,
255271
},

0 commit comments

Comments
 (0)