Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

padding: @cell-padding;
white-space: normal;
word-break: break-word;
border: @border;
border-top: 0;
border-left: 0;
Expand Down
3 changes: 3 additions & 0 deletions docs/examples/scrollY.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const Test = () => {
rowKey={record => record.key}
onRow={(record, index) => ({ style: { backgroundColor: 'red' } })}
/>
<h3>Column align issue</h3>
<p>https://github.com/ant-design/ant-design/issues/54889</p>
<Table columns={columns} data={data} sticky scroll={{ y: 300, x: 2000 }} />
</div>
);
};
Expand Down
50 changes: 46 additions & 4 deletions docs/examples/stickyHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,34 @@ const data = [
{ a: '1333', c: 'eee', d: 2, key: '20' },
];

const columns3: ColumnType<RecordType>[] = [
{ title: '', dataIndex: 'name', key: '0' },
{ title: 'First column', dataIndex: 'name', key: '1' },
{ title: 'Second column', dataIndex: 'address', key: '2' },
{ title: 'Third column', dataIndex: 'age', key: '3' },
{ title: 'Another column', dataIndex: 'address', key: '4' },
{ title: 'Extra column', dataIndex: 'name', key: '5' },
{ title: 'And yet another column', dataIndex: 'address', key: '6' },
{
title: 'Column 7 with extraaaaaaaaa long word',
dataIndex: 'age',
key: '7',
},
{ title: 'Column 8', dataIndex: 'address', key: '8' },
{ title: 'Column 9', dataIndex: 'name', key: '9' },
{ title: 'Column 10', dataIndex: 'address', key: '10' },
{ title: 'Column 11', dataIndex: 'address', key: '11' },
{ title: 'Column 12', dataIndex: 'age', key: '12' },
{ title: 'Column 13', dataIndex: 'address', key: '13' },
{ title: 'Column 14', dataIndex: 'name', key: '14' },
{ title: 'Column 15', dataIndex: 'address', key: '15' },
{ title: 'Column 16', dataIndex: 'address', key: '16' },
{ title: 'Column 17', dataIndex: 'name', key: '17' },
{ title: 'Column 18', dataIndex: 'address', key: '18' },
{ title: 'Column 19', dataIndex: 'address', key: '19' },
{ title: 'Column 20', dataIndex: 'age', key: '20' },
];

const Demo = () => {
const container = useRef();
return (
Expand Down Expand Up @@ -274,7 +302,7 @@ const Demo = () => {
<br />
<Table
columns={fixedColumns}
data={[{}]}
data={[{ key: '1' }]}
scroll={{
x: 'max-content',
}}
Expand All @@ -283,7 +311,7 @@ const Demo = () => {
<br />
<Table
columns={columnsWithWidth}
data={[{}]}
data={[{ key: '1' }]}
scroll={{
x: 1200,
}}
Expand All @@ -301,7 +329,7 @@ const Demo = () => {
<br />
<Table
columns={fixedColumns.map(column => ({ ...column, width: undefined }))}
data={[{}]}
data={[{ key: '1' }]}
scroll={{
x: 'max-content',
}}
Expand All @@ -310,12 +338,26 @@ const Demo = () => {
<br />
<Table
columns={columnsGrouped}
data={[{}, {}]}
data={[{ key: '1' }, { key: '2' }]}
scroll={{
x: 'max-content',
}}
sticky
/>
<br />
<h3>scroll.x is true</h3>
<p>https://github.com/ant-design/ant-design/issues/54894</p>
<Table
columns={columns3}
data={
[
{ key: '1', name: 'Test', age: 1, address: '2' },
{ key: '2', name: '0', age: 1, address: '2' },
] as any
}
sticky
scroll={{ x: true }}
/>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/ColGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function ColGroup<RecordType>({ colWidths, columns, columCount }: ColGroupProps<
}
}

return <colgroup>{cols}</colgroup>;
return cols.length > 0 ? <colgroup>{cols}</colgroup> : null;
}

export default ColGroup;
8 changes: 5 additions & 3 deletions src/FixedHolder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface FixedHeaderProps<RecordType> extends HeaderProps<RecordType> {
stickyTopOffset?: number;
stickyBottomOffset?: number;
stickyClassName?: string;
scrollTableStyle?: React.CSSProperties;
scrollX?: number | string | true;
tableLayout?: TableLayout;
onScroll: (info: { currentTarget: HTMLDivElement; scrollLeft?: number }) => void;
children: (info: HeaderProps<RecordType>) => React.ReactNode;
Expand All @@ -60,7 +60,7 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
stickyTopOffset,
stickyBottomOffset,
stickyClassName,
scrollTableStyle,
scrollX,
tableLayout = 'fixed',
onScroll,
children,
Expand Down Expand Up @@ -179,7 +179,9 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
style={{
tableLayout,
visibility: noData || mergedColumnWidth ? null : 'hidden',
...scrollTableStyle,
minWidth: '100%',
// https://github.com/ant-design/ant-design/issues/54894
width: scrollX,
}}
>
{colGroupNode}
Expand Down
2 changes: 1 addition & 1 deletion src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ function Table<RecordType extends DefaultRecordType>(
...columnContext,
direction,
stickyClassName,
scrollTableStyle,
scrollX: mergedScrollX,
tableLayout: mergedTableLayout,
onScroll: onInternalScroll,
};
Expand Down
4 changes: 0 additions & 4 deletions tests/__snapshots__/ExpandRow.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -519,7 +518,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -861,7 +859,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -996,7 +993,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down
11 changes: 5 additions & 6 deletions tests/__snapshots__/FixedColumn.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1941,7 +1941,7 @@ LoadedCheerio {
style="overflow: hidden;"
>
<table
style="table-layout: fixed; width: 1200px; min-width: 100%;"
style="table-layout: fixed; min-width: 100%; width: 1200px;"
>
<colgroup>
<col
Expand Down Expand Up @@ -2814,7 +2814,7 @@ LoadedCheerio {
style="overflow: hidden;"
>
<table
style="table-layout: fixed; width: 1200px; min-width: 100%;"
style="table-layout: fixed; min-width: 100%; width: 1200px;"
>
<colgroup>
<col
Expand Down Expand Up @@ -3136,7 +3136,7 @@ exports[`Table.FixedColumn > shadow should be shown when there are columns where
style="overflow: hidden;"
>
<table
style="table-layout: fixed; width: 1500px; min-width: 100%;"
style="table-layout: fixed; min-width: 100%; width: 1500px;"
>
<colgroup>
<col
Expand Down Expand Up @@ -3200,7 +3200,6 @@ exports[`Table.FixedColumn > shadow should be shown when there are columns where
<table
style="width: 1500px; min-width: 100%; table-layout: fixed;"
>
<colgroup />
<tbody
class="rc-table-tbody"
>
Expand Down Expand Up @@ -5567,7 +5566,7 @@ exports[`Table.FixedColumn > shadow should display correctly 1`] = `
style="overflow: hidden;"
>
<table
style="table-layout: fixed; width: 1500px; min-width: 100%;"
style="table-layout: fixed; min-width: 100%; width: 1500px;"
>
<colgroup>
<col
Expand Down Expand Up @@ -11653,7 +11652,7 @@ exports[`Table.FixedColumn > shadow should display correctly 2`] = `
style="overflow: hidden;"
>
<table
style="table-layout: fixed; width: 1500px; min-width: 100%;"
style="table-layout: fixed; min-width: 100%; width: 1500px;"
>
<colgroup>
<col
Expand Down
19 changes: 3 additions & 16 deletions tests/__snapshots__/Table.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -120,7 +119,6 @@ LoadedCheerio {
name="my-table"
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
name="my-header-wrapper"
Expand Down Expand Up @@ -214,9 +212,8 @@ LoadedCheerio {
style="overflow: hidden;"
>
<table
style="table-layout: fixed; width: 100px; min-width: 100%;"
style="table-layout: fixed; min-width: 100%; width: 100px;"
>
<colgroup />
<thead
class="rc-table-thead"
name="my-header-wrapper"
Expand Down Expand Up @@ -264,7 +261,6 @@ LoadedCheerio {
name="my-table"
style="width: 100px; min-width: 100%; table-layout: fixed;"
>
<colgroup />
<tbody
class="rc-table-tbody"
name="my-body-wrapper"
Expand Down Expand Up @@ -377,7 +373,7 @@ LoadedCheerio {
style="overflow: hidden;"
>
<table
style="table-layout: fixed; width: 100px; min-width: 100%;"
style="table-layout: fixed; min-width: 100%; width: 100px;"
>
<colgroup>
<col
Expand Down Expand Up @@ -457,7 +453,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -567,7 +562,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -660,7 +654,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="test-prefix-thead"
>
Expand Down Expand Up @@ -746,7 +739,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="test-prefix-thead"
>
Expand Down Expand Up @@ -832,7 +824,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -930,7 +921,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -1016,7 +1006,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -1095,7 +1084,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down Expand Up @@ -1192,7 +1180,7 @@ LoadedCheerio {
style="overflow: hidden;"
>
<table
style="table-layout: fixed;"
style="table-layout: fixed; min-width: 100%;"
>
<colgroup>
<col
Expand Down Expand Up @@ -1266,7 +1254,6 @@ LoadedCheerio {
<table
style="table-layout: auto;"
>
<colgroup />
<thead
class="rc-table-thead"
>
Expand Down