-
-
Notifications
You must be signed in to change notification settings - Fork 619
fix: fix sticky header column width with empty data #1323
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1f9b5a4
feat: add sticky header with empty data and max-content scroll support
afc163 398cc72
fix: sticky header column width test and colGroup handling
afc163 9d62c0c
fix: adjust sticky header width calculation and remove unused props
afc163 593d858
fix: remove unnecessary -1 from expanded row width calculation
afc163 4cbf636
fix: adjust column widths in FixedColumn snapshot test
afc163 434ccd6
Update docs/examples/stickyHeader.tsx
afc163 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,6 @@ function useColumnWidth(colWidths: readonly number[], columCount: number) { | |
| export interface FixedHeaderProps<RecordType> extends HeaderProps<RecordType> { | ||
| className: string; | ||
| noData: boolean; | ||
| maxContentScroll: boolean; | ||
| colWidths: readonly number[]; | ||
| columCount: number; | ||
| direction: Direction; | ||
|
|
@@ -37,6 +36,7 @@ export interface FixedHeaderProps<RecordType> extends HeaderProps<RecordType> { | |
| stickyClassName?: string; | ||
| onScroll: (info: { currentTarget: HTMLDivElement; scrollLeft?: number }) => void; | ||
| children: (info: HeaderProps<RecordType>) => React.ReactNode; | ||
| colGroup?: React.ReactNode; | ||
| } | ||
|
|
||
| const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((props, ref) => { | ||
|
|
@@ -50,6 +50,7 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro | |
| columns, | ||
| flattenColumns, | ||
| colWidths, | ||
| colGroup, | ||
| columCount, | ||
| stickyOffsets, | ||
| direction, | ||
|
|
@@ -58,7 +59,6 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro | |
| stickyBottomOffset, | ||
| stickyClassName, | ||
| onScroll, | ||
| maxContentScroll, | ||
| children, | ||
| ...restProps | ||
| } = props; | ||
|
|
@@ -98,12 +98,6 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro | |
| }; | ||
| }, []); | ||
|
|
||
| // Check if all flattenColumns has width | ||
| const allFlattenColumnsWithWidth = React.useMemo( | ||
| () => flattenColumns.every(column => column.width), | ||
| [flattenColumns], | ||
| ); | ||
|
|
||
| // Add scrollbar column | ||
| const lastColumn = flattenColumns[flattenColumns.length - 1]; | ||
| const ScrollBarColumn: ColumnType<unknown> & { scrollbar: true } = { | ||
|
|
@@ -156,7 +150,10 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro | |
| visibility: noData || mergedColumnWidth ? null : 'hidden', | ||
| }} | ||
| > | ||
| {(!noData || !maxContentScroll || allFlattenColumnsWithWidth) && ( | ||
| {/* use original ColGroup if no data, otherwise use calculated column width */} | ||
| {noData ? ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果只有 noData 会不会不够,虽然没数据列头不换行了,那还有个场景(列的数据比列头少,也会换行吧?) 我目前的解法是,取 title 的元素,在第一行里 height =0 再渲染一次,撑起宽度 |
||
| colGroup | ||
| ) : ( | ||
| <ColGroup | ||
| colWidths={mergedColumnWidth ? [...mergedColumnWidth, combinationScrollBarSize] : []} | ||
| columCount={columCount + 1} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用了
max-content,这里不应该再加 width 的,这样会忽略掉问题。