mirror of
https://github.com/gosticks/react-table.git
synced 2026-08-19 16:30:21 +00:00
58 lines
1.1 KiB
JavaScript
58 lines
1.1 KiB
JavaScript
export const useAbsoluteLayout = hooks => {
|
|
hooks.useInstance.push(useInstance)
|
|
}
|
|
|
|
useAbsoluteLayout.pluginName = 'useAbsoluteLayout'
|
|
|
|
const useInstance = instance => {
|
|
const {
|
|
totalColumnsWidth,
|
|
hooks: {
|
|
getRowProps,
|
|
getTableBodyProps,
|
|
getHeaderGroupProps,
|
|
getHeaderProps,
|
|
getCellProps,
|
|
},
|
|
} = instance
|
|
|
|
const rowStyles = {
|
|
style: {
|
|
position: 'relative',
|
|
width: `${totalColumnsWidth}px`,
|
|
},
|
|
}
|
|
|
|
getTableBodyProps.push(() => rowStyles)
|
|
getRowProps.push(() => rowStyles)
|
|
getHeaderGroupProps.push(() => rowStyles)
|
|
|
|
// Calculating column/cells widths
|
|
const cellStyles = {
|
|
position: 'absolute',
|
|
top: 0,
|
|
}
|
|
|
|
getHeaderProps.push(header => {
|
|
return {
|
|
style: {
|
|
...cellStyles,
|
|
left: `${header.totalLeft}px`,
|
|
width: `${header.totalWidth}px`,
|
|
},
|
|
}
|
|
})
|
|
|
|
getCellProps.push(cell => {
|
|
return {
|
|
style: {
|
|
...cellStyles,
|
|
left: `${cell.column.totalLeft}px`,
|
|
width: `${cell.column.totalWidth}px`,
|
|
},
|
|
}
|
|
})
|
|
|
|
return instance
|
|
}
|