feat: apply full width automatically for DataTable #18357
Draft
+96
−21
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.
What does this PR do?
This PR improves DataTable to fill the full width.
Details
The way we calculate the default width of columns in DataTable:
size
values as a part of ColumnDef. Example:cal.com/packages/features/users/components/UserTable/UserListTable.tsx
Line 203 in d71b9e2
getSize()
function and its default value (https://tanstack.com/table/latest/docs/api/features/column-sizing#getsize)When browser's width is too large or there is not enough columns, the DataTable doesn't fill the full width. It used to do so, but not anymore since we've applied
flex
to<TableRow />
for the following reasons:This PR fixes the logic to calculate the column widths by increasing them a bit more if the calculated total widths doesn't fill the container's clientWidth. They are also re-calculated as browser resizes.
Screenshot.2024-12-23.at.17.17.08.mp4
(The recalculation of column sizes on window resize is debounced for better performance.)
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
If you already have resized columns, it may affect the result. So it's better to delete data from localStorage before testing. Delete all the keys starting with
data-table-column-sizing-
.DataTable should look good in the following pages:
Checklist