Replies: 4 comments 7 replies
-
I'd also like to be able to set a percentage-based width, which doesn't seem possible |
Beta Was this translation helpful? Give feedback.
-
I've come up with a const table = useReactTable<T>({
defaultColumn: {
minSize: 0,
size: 0,
},
getCoreRowModel: getCoreRowModel(),
...
}) Then, in the definition for each header and cell, I apply the style only if the calculated width != 0: // Header
<th
key={header.id}
colSpan={header.colSpan}
style={{
width: header.getSize() !== 0 ? header.getSize() : undefined,
}}
>
...
// Cell
<td
key={cell.id}
style={{
width:
cell.column.getSize() !== 0
? cell.column.getSize()
: undefined,
}}
>
... This will ensure that a style will only be applied if the column specifically defines it. Remember that this doesn't actually change the result of |
Beta Was this translation helpful? Give feedback.
-
The temporary fix suggested above didn't work for my use case so I came up with the following solution:
const cellRefs = React.useRef<HTMLDivElement[][]>([])
const handleCellRefsSet = React.useCallback(
(el: HTMLDivElement, row: number, cell: number) => {
if (!cellRefs.current[row]) cellRefs.current[row] = new Array(originalColumns.length)
cellRefs.current[row][cell] = el
},
[originalColumns.length]
)
const columns = React.useMemo(() =>
originalColumns.map((col, i) => ({
...col,
// Use `scrollWidth` to get the width of the element including its (maybe) hidden fragment.
size: Math.max(...cellRefs.current.map((refs) => refs[i].scrollWidth), col.minSize!),
}),
[originalColumns]) |
Beta Was this translation helpful? Give feedback.
-
the easiest temorary solution is
|
Beta Was this translation helpful? Give feedback.
-
I guess it is no longer possible to create auto-sizing columns based on the content of the cell?
So the column would have min width of the widest cell in the column.
I found this discussion but the "auto" value is no longer possible for sizing. We can set only numbers now.
#3192
Beta Was this translation helpful? Give feedback.
All reactions