Repository navigation
Replies: 1 comment
|
The cause is that the example only writes CSS variables for The fix is to re-run the writer when visibility changes as well as when sizing changes. v9 (current example, atoms): React.useLayoutEffect(() => {
const writeColumnSizeVars = () => {
const tableEl = tableRef.current
if (!tableEl) return
for (const header of table.getFlatHeaders()) {
tableEl.style.setProperty(`--header-${header.id}-size`, String(header.getSize()))
tableEl.style.setProperty(`--col-${header.column.id}-size`, String(header.column.getSize()))
}
tableEl.style.width = `${table.getTotalSize()}px`
}
writeColumnSizeVars()
const subs = [
table.atoms.columnSizing.subscribe(writeColumnSizeVars),
table.atoms.columnVisibility.subscribe(writeColumnSizeVars), // <- add this
]
return () => subs.forEach((s) => s.unsubscribe())
}, [])This doesn't cost you anything during a resize. Visibility doesn't change while you're dragging, so the extra subscription only fires when a column is actually shown or hidden. It also keeps I tested this with
v8 ( const columnSizeVars = React.useMemo(() => {
// ...same loop over table.getFlatHeaders()
}, [
table.getState().columnSizingInfo,
table.getState().columnSizing,
table.getState().columnVisibility, // <- add this
])You could also loop over |
Uh oh!
There was an error while loading. Please reload this page.
I have implemented performant column sizing as shown in this example in a table which also uses column visibility.
However, because the table no longer updates on
state.columnSizing, the size config of a column which started hidden is ignored when it is first shown.How can I get the performance benefits while also having columns un-hide at the correct size?
All reactions