Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add header table #1074

Merged
merged 7 commits into from
Feb 2, 2024
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
8 changes: 8 additions & 0 deletions docs/demo/components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: components
nav:
title: Demo
path: /demo
---

<code src="../examples/components.tsx"></code>
40 changes: 40 additions & 0 deletions docs/examples/components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';
import Table from 'rc-table';

const data = [];
for (let i = 0; i < 100; i += 1) {
data.push({
key: i,
a: `a${i}`,
b: `b${i}`,
c: `c${i}`,
});
}

const table = (props: any) => {
return (
<>
<div style={{ background: '#fff' }}>header table</div>
<table className={props.className}>{props.children}</table>
</>
);
};

const Demo = () => {
return (
<div>
<Table
components={{ header: { table } }}
sticky
columns={[
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100 },
{ title: 'title2', dataIndex: 'b', key: 'b', width: 100 },
{ title: 'title3', dataIndex: 'c', key: 'c', width: 200 },
]}
data={data}
/>
</div>
);
};

export default Demo;
8 changes: 5 additions & 3 deletions src/FixedHolder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<unknown>>(
...restProps
} = props;

const { prefixCls, scrollbarSize, isSticky } = useContext(TableContext, [
const { prefixCls, scrollbarSize, isSticky, getComponent } = useContext(TableContext, [
'prefixCls',
'scrollbarSize',
'isSticky',
'getComponent',
]);
const TableComponent = getComponent(['header', 'table'], 'table');

const combinationScrollBarSize = isSticky && !fixHeader ? 0 : scrollbarSize;

Expand Down Expand Up @@ -146,7 +148,7 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<unknown>>(
[stickyClassName]: !!stickyClassName,
})}
>
<table
<TableComponent
style={{
tableLayout: 'fixed',
visibility: noData || mergedColumnWidth ? null : 'hidden',
Expand All @@ -165,7 +167,7 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<unknown>>(
columns: columnsWithScrollbar,
flattenColumns: flattenColumnsWithScrollbar,
})}
</table>
</TableComponent>
</div>
);
});
Expand Down
1 change: 1 addition & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export type CustomizeScrollBody<RecordType> = (
export interface TableComponents<RecordType> {
table?: CustomizeComponent;
header?: {
table?: CustomizeComponent;
wrapper?: CustomizeComponent;
row?: CustomizeComponent;
cell?: CustomizeComponent;
Expand Down
14 changes: 14 additions & 0 deletions tests/FixedColumn.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,18 @@ describe('Table.FixedColumn', () => {
});
});
});
describe('components.table by sticky', () => {
it('render', async () => {
const table = props => {
return (
<>
<div className="healer-table">header table</div>
<table className={props.className}>{props.children}</table>
</>
);
};
const { container } = render(<Table sticky components={{ header: { table } }} />);
expect(container.querySelector('.healer-table')).toBeTruthy();
});
});
});
Loading