| 48 | } |
| 49 | |
| 50 | function syncColumnWidths( |
| 51 | table: HTMLTableElement, |
| 52 | fixedHeader: HTMLDivElement |
| 53 | ) { |
| 54 | const origThs = table.querySelectorAll("thead th") |
| 55 | const cloneThs = fixedHeader.querySelectorAll("th") |
| 56 | cloneThs.forEach((th, idx) => { |
| 57 | const width = window.getComputedStyle(origThs[idx]).width |
| 58 | th.style.width = width |
| 59 | }) |
| 60 | fixedHeader.querySelector("table")!.style.width = `${table.offsetWidth}px` |
| 61 | fixedHeader.style.width = `${table.parentElement?.offsetWidth}px` |
| 62 | } |
| 63 | |
| 64 | export function useStickyTable() { |
| 65 | const tableRef = useRef<HTMLTableElement>(null) |