parent
08c3c9cc3b
commit
0cd3db0bb0
|
@ -132,16 +132,13 @@ const BaseTable = {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { sComponents: components, prefixCls, scroll, data } = this.table;
|
const { sComponents: components, prefixCls, scroll, data } = this.table;
|
||||||
const { expander, tableClassName, hasHead, hasBody, fixed, isAnyColumnsFixed } = this.$props;
|
const { expander, tableClassName, hasHead, hasBody, fixed } = this.$props;
|
||||||
const columns = this.getColumns();
|
const columns = this.getColumns();
|
||||||
const tableStyle = {};
|
const tableStyle = {};
|
||||||
|
|
||||||
if (!fixed && scroll.x) {
|
if (!fixed && 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
|
// not set width, then use content fixed width
|
||||||
tableStyle.width = scroll.x === true ? tableWidthScrollX : scroll.x;
|
tableStyle.width = scroll.x === true ? 'auto' : scroll.x;
|
||||||
tableStyle.width =
|
tableStyle.width =
|
||||||
typeof tableStyle.width === 'number' ? `${tableStyle.width}px` : tableStyle.width;
|
typeof tableStyle.width === 'number' ? `${tableStyle.width}px` : tableStyle.width;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
import { inject } from 'vue';
|
import { inject } from 'vue';
|
||||||
import PropTypes, { withUndefined } from '../../_util/vue-types';
|
import PropTypes from '../../_util/vue-types';
|
||||||
import { measureScrollbar } from './utils';
|
|
||||||
import BaseTable from './BaseTable';
|
import BaseTable from './BaseTable';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'BodyTable',
|
name: 'BodyTable',
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
props: {
|
props: {
|
||||||
fixed: withUndefined(PropTypes.oneOfType([PropTypes.string, PropTypes.looseBool])),
|
|
||||||
columns: PropTypes.array.isRequired,
|
columns: PropTypes.array.isRequired,
|
||||||
tableClassName: PropTypes.string.isRequired,
|
tableClassName: PropTypes.string.isRequired,
|
||||||
handleBodyScroll: PropTypes.func.isRequired,
|
handleBodyScroll: PropTypes.func.isRequired,
|
||||||
|
@ -25,7 +23,6 @@ export default {
|
||||||
const { prefixCls, scroll } = this.table;
|
const { prefixCls, scroll } = this.table;
|
||||||
const {
|
const {
|
||||||
columns,
|
columns,
|
||||||
fixed,
|
|
||||||
tableClassName,
|
tableClassName,
|
||||||
getRowKey,
|
getRowKey,
|
||||||
handleBodyScroll,
|
handleBodyScroll,
|
||||||
|
@ -35,34 +32,26 @@ export default {
|
||||||
} = this;
|
} = this;
|
||||||
let { useFixedHeader, saveRef } = this.table;
|
let { useFixedHeader, saveRef } = this.table;
|
||||||
const bodyStyle = { ...this.table.bodyStyle };
|
const bodyStyle = { ...this.table.bodyStyle };
|
||||||
const innerBodyStyle = {};
|
|
||||||
|
|
||||||
if (scroll.x || fixed) {
|
|
||||||
bodyStyle.overflowX = bodyStyle.overflowX || 'scroll';
|
|
||||||
// Fix weired webkit render bug
|
|
||||||
// https://github.com/ant-design/ant-design/issues/7783
|
|
||||||
bodyStyle.WebkitTransform = 'translate3d (0, 0, 0)';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scroll.y) {
|
if (scroll.y) {
|
||||||
// maxHeight will make fixed-Table scrolling not working
|
// maxHeight will make fixed-Table scrolling not working
|
||||||
// so we only set maxHeight to body-Table here
|
// so we only set maxHeight to body-Table here
|
||||||
let maxHeight = bodyStyle.maxHeight || scroll.y;
|
let maxHeight = bodyStyle.maxHeight || scroll.y;
|
||||||
maxHeight = typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight;
|
maxHeight = typeof maxHeight === 'number' ? `${maxHeight}px` : maxHeight;
|
||||||
if (fixed) {
|
|
||||||
innerBodyStyle.maxHeight = maxHeight;
|
|
||||||
innerBodyStyle.overflowY = bodyStyle.overflowY || 'scroll';
|
|
||||||
} else {
|
|
||||||
bodyStyle.maxHeight = maxHeight;
|
bodyStyle.maxHeight = maxHeight;
|
||||||
}
|
|
||||||
bodyStyle.overflowY = bodyStyle.overflowY || 'scroll';
|
bodyStyle.overflowY = bodyStyle.overflowY || 'scroll';
|
||||||
useFixedHeader = true;
|
useFixedHeader = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Add negative margin bottom for scroll bar overflow bug
|
if (scroll.x) {
|
||||||
const scrollbarWidth = measureScrollbar({ direction: 'vertical' });
|
bodyStyle.overflowX = bodyStyle.overflowX || 'auto';
|
||||||
if (scrollbarWidth > 0 && fixed) {
|
// Fix weired webkit render bug
|
||||||
bodyStyle.marginBottom = `-${scrollbarWidth}px`;
|
// https://github.com/ant-design/ant-design/issues/7783
|
||||||
bodyStyle.paddingBottom = '0px';
|
bodyStyle.WebkitTransform = 'translate3d (0, 0, 0)';
|
||||||
|
|
||||||
|
if (!scroll.y) {
|
||||||
|
bodyStyle.overflowY = 'hidden';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +60,6 @@ export default {
|
||||||
tableClassName={tableClassName}
|
tableClassName={tableClassName}
|
||||||
hasHead={!useFixedHeader}
|
hasHead={!useFixedHeader}
|
||||||
hasBody
|
hasBody
|
||||||
fixed={fixed}
|
|
||||||
columns={columns}
|
columns={columns}
|
||||||
expander={expander}
|
expander={expander}
|
||||||
getRowKey={getRowKey}
|
getRowKey={getRowKey}
|
||||||
|
@ -79,29 +67,6 @@ export default {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
if (fixed && columns.length) {
|
|
||||||
let refName;
|
|
||||||
if (columns[0].fixed === 'left' || columns[0].fixed === true) {
|
|
||||||
refName = 'fixedColumnsBodyLeft';
|
|
||||||
} else if (columns[0].fixed === 'right') {
|
|
||||||
refName = 'fixedColumnsBodyRight';
|
|
||||||
}
|
|
||||||
delete bodyStyle.overflowX;
|
|
||||||
delete bodyStyle.overflowY;
|
|
||||||
return (
|
|
||||||
<div key="bodyTable" class={`${prefixCls}-body-outer`} style={{ ...bodyStyle }}>
|
|
||||||
<div
|
|
||||||
class={`${prefixCls}-body-inner`}
|
|
||||||
style={innerBodyStyle}
|
|
||||||
ref={saveRef(refName)}
|
|
||||||
onWheel={handleWheel}
|
|
||||||
onScroll={handleBodyScroll}
|
|
||||||
>
|
|
||||||
{baseTable}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Should provides `tabindex` if use scroll to enable keyboard scroll
|
// Should provides `tabindex` if use scroll to enable keyboard scroll
|
||||||
const useTabIndex = scroll && (scroll.x || scroll.y);
|
const useTabIndex = scroll && (scroll.x || scroll.y);
|
||||||
|
|
||||||
|
|
|
@ -501,41 +501,15 @@ export default defineComponent({
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
renderLeftFixedTable() {
|
|
||||||
const { prefixCls } = this;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div key="left" class={`${prefixCls}-fixed-left`}>
|
|
||||||
{this.renderTable({
|
|
||||||
columns: this.columnManager.leftColumns.value,
|
|
||||||
fixed: 'left',
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
renderRightFixedTable() {
|
|
||||||
const { prefixCls } = this;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div class={`${prefixCls}-fixed-right`}>
|
|
||||||
{this.renderTable({
|
|
||||||
columns: this.columnManager.rightColumns.value,
|
|
||||||
fixed: 'right',
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
renderTable(options) {
|
renderTable(options) {
|
||||||
const { columns, fixed, isAnyColumnsFixed } = options;
|
const { columns, isAnyColumnsFixed } = options;
|
||||||
const { prefixCls, scroll = {} } = this;
|
const { prefixCls, scroll = {} } = this;
|
||||||
const tableClassName = scroll.x || fixed ? `${prefixCls}-fixed` : '';
|
const tableClassName = scroll.x ? `${prefixCls}-fixed` : '';
|
||||||
|
|
||||||
const headTable = (
|
const headTable = (
|
||||||
<HeadTable
|
<HeadTable
|
||||||
key="head"
|
key="head"
|
||||||
columns={columns}
|
columns={columns}
|
||||||
fixed={fixed}
|
|
||||||
tableClassName={tableClassName}
|
tableClassName={tableClassName}
|
||||||
handleBodyScrollLeft={this.handleBodyScrollLeft}
|
handleBodyScrollLeft={this.handleBodyScrollLeft}
|
||||||
expander={this.expander}
|
expander={this.expander}
|
||||||
|
@ -546,7 +520,6 @@ export default defineComponent({
|
||||||
<BodyTable
|
<BodyTable
|
||||||
key="body"
|
key="body"
|
||||||
columns={columns}
|
columns={columns}
|
||||||
fixed={fixed}
|
|
||||||
tableClassName={tableClassName}
|
tableClassName={tableClassName}
|
||||||
getRowKey={this.getRowKey}
|
getRowKey={this.getRowKey}
|
||||||
handleWheel={this.handleWheel}
|
handleWheel={this.handleWheel}
|
||||||
|
|
Loading…
Reference in New Issue