fix: table customRow events not work #1881

pull/1886/head 1.5.0-rc.4
tangjinzhou 5 years ago
parent eac21b49fc
commit 43c961c971

@ -145,12 +145,16 @@ const BaseTable = {
render() { render() {
const { sComponents: components, prefixCls, scroll, data, getBodyWrapper } = this.table; const { sComponents: components, prefixCls, scroll, data, getBodyWrapper } = this.table;
const { expander, tableClassName, hasHead, hasBody, fixed } = this.$props; const { expander, tableClassName, hasHead, hasBody, fixed, isAnyColumnsFixed } = this.$props;
const tableStyle = {}; const tableStyle = {};
if (!fixed && scroll.x) { if (!fixed && scroll.x) {
tableStyle.width = scroll.x === true ? 'max-content' : scroll.x; // width auto body table
// https://github.com/ant-design/ant-design/issues/22160
const tableWidthScrollX = isAnyColumnsFixed ? 'max-content' : 'auto';
// not set width, then use content fixed width
tableStyle.width = scroll.x === true ? tableWidthScrollX : scroll.x;
tableStyle.width = tableStyle.width =
typeof tableStyle.width === 'number' ? `${tableStyle.width}px` : tableStyle.width; typeof tableStyle.width === 'number' ? `${tableStyle.width}px` : tableStyle.width;
} }

@ -83,31 +83,36 @@ const TableRow = {
} }
}, },
methods: { methods: {
onRowClick(event) { onRowClick(event, rowPropFunc = noop) {
const { record, index } = this; const { record, index } = this;
this.__emit('rowClick', record, index, event); this.__emit('rowClick', record, index, event);
rowPropFunc(event);
}, },
onRowDoubleClick(event) { onRowDoubleClick(event, rowPropFunc = noop) {
const { record, index } = this; const { record, index } = this;
this.__emit('rowDoubleClick', record, index, event); this.__emit('rowDoubleClick', record, index, event);
rowPropFunc(event);
}, },
onContextMenu(event) { onContextMenu(event, rowPropFunc = noop) {
const { record, index } = this; const { record, index } = this;
this.__emit('rowContextmenu', record, index, event); this.__emit('rowContextmenu', record, index, event);
rowPropFunc(event);
}, },
onMouseEnter(event) { onMouseEnter(event, rowPropFunc = noop) {
const { record, index, rowKey } = this; const { record, index, rowKey } = this;
this.__emit('hover', true, rowKey); this.__emit('hover', true, rowKey);
this.__emit('rowMouseenter', record, index, event); this.__emit('rowMouseenter', record, index, event);
rowPropFunc(event);
}, },
onMouseLeave(event) { onMouseLeave(event, rowPropFunc = noop) {
const { record, index, rowKey } = this; const { record, index, rowKey } = this;
this.__emit('hover', false, rowKey); this.__emit('hover', false, rowKey);
this.__emit('rowMouseleave', record, index, event); this.__emit('rowMouseleave', record, index, event);
rowPropFunc(event);
}, },
setExpandedRowHeight() { setExpandedRowHeight() {
@ -241,15 +246,26 @@ const TableRow = {
customClassName, customClassName,
customClass, customClass,
); );
const rowPropEvents = rowProps.on || {};
const bodyRowProps = mergeProps( const bodyRowProps = mergeProps(
{ ...rowProps, style }, { ...rowProps, style },
{ {
on: { on: {
click: this.onRowClick, click: e => {
dblclick: this.onRowDoubleClick, this.onRowClick(e, rowPropEvents.click);
mouseenter: this.onMouseEnter, },
mouseleave: this.onMouseLeave, dblclick: e => {
contextmenu: this.onContextMenu, this.onRowDoubleClick(e, rowPropEvents.dblclick);
},
mouseenter: e => {
this.onMouseEnter(e, rowPropEvents.mouseenter);
},
mouseleave: e => {
this.onMouseLeave(e, rowPropEvents.mouseleave);
},
contextmenu: e => {
this.onContextMenu(e, rowPropEvents.contextmenu);
},
}, },
class: rowClassName, class: rowClassName,
}, },

Loading…
Cancel
Save