-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Resize DataTable columns (standard & sticky header tables) #5288
Resize DataTable columns (standard & sticky header tables) #5288
Conversation
Merge from carbon-design-system
Chore: get carbon-design-system/master
merge with sds-master
…o table-resize-columns
…o table-resize-columns
…o table-resize-columns
Hi @gmoehler! 👋 If I remember correctly, were you going down the route of adding this into Cloud PAL? |
Correct that was the suggestion from the Carbon team. Will work on it in near future |
Perfect! Sounds great 😄 We're going through older PRs just to clean-up ones that may be inactive. I am going to close this one out but feel free to re-open! |
Is this available in the latest version of Carbon React? Couldn't find any documentation on this |
Can someone please answer: what version of Carbon React is this available in? |
@nagiah @akmalhakimi1991 this feature was not added to Carbon core |
Thanks for your quick response @tw15egan |
An answer please: |
@nagiah there are no plans to implement this feature |
Closes #4751
Closes #3911
This PR implements a column width resizer which works both for standard DataTable as well as for a DataTable with sticky-header.
It builds on an earlier PR (#5214), but minimizes the impact to the existing code dramatiacally, because it either uses additional components (like
TableColumnResizer
) or tools (likeDataTable/tools/columnResize.js
) or introduces copies of existing components (TableHeader
->TableHeaderResizable
,TableCell
->TableCellResizable
). The resize storywith-resizable-columns.js
uses the duplicated components and covers a few little additions for the resizing to work (see below).The resizing algorithm is enhanced as compared to the earlier PR #5214:
min-width
is defined forth/td
(as it is the case for sticky header tables)The algorithm needs access to the width of all columns, also it potentially changes the column width of all columns. For sticky header tables it is required to update the widh in the header
th
and the celltd
. Therefore, a central place is required to keep the width data. This solution uses an React ContextResizeContext
along with a store to keep that data. This keeps the impact to other code low to a maximum, while using state-of-the-art react mechanism. A reducerResizeReducer
triggers store changes. Everything is encapsulated into a custom react hookuseColumnResizing()
. The hook is used in the resizer componentTableColumnResizer
to trigger the resizing. In TableHeaderResizableand
TableCellResizablethe same hook is used to retreive the new width and set it via
style={{ width: colWidth + 'px' }}`.Changelog
New
TableHeader
->TableHeaderResizable
,TableCell
->TableCellResizable
TableColumnResizer
DataTable/tools/columnResize.js
_data-table-column-resize.scss
Changed
_data-table-column-resize.scss
Removed
nothing
Testing / Reviewing
Open the story DataTable > with resizabable columns, grab the resizer in the header of the table and resize the columns. Also switch on Sticky header (experimental) in the Knobs to verify things work for sticky header tables, too.