From f50428300225521256103eb00ed95ece74948bdb Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Mon, 25 Jul 2022 20:48:33 +0200 Subject: [PATCH] use position:sticky for table header --- .../src/perspectives/PerspectiveTable.svelte | 72 +++++++------------ 1 file changed, 24 insertions(+), 48 deletions(-) diff --git a/packages/web/src/perspectives/PerspectiveTable.svelte b/packages/web/src/perspectives/PerspectiveTable.svelte index 2ec952f7..f115d221 100644 --- a/packages/web/src/perspectives/PerspectiveTable.svelte +++ b/packages/web/src/perspectives/PerspectiveTable.svelte @@ -22,9 +22,6 @@ export let loadedCounts; let dataRows; let domWrapper; - let domTableHead; - let domHeaderWrap; - let theadClone; async function loadLevelData(node: PerspectiveTreeNode, parentRows: any[], counts) { dbg('load level data', counts); @@ -104,38 +101,11 @@ // } } - async function createHeaderClone() { - if (!domTableHead || !domHeaderWrap) return; - await tick(); - - if (theadClone) { - theadClone.remove(); - theadClone = null; - } - theadClone = domTableHead.cloneNode(true); - const sourceCells = domTableHead.querySelectorAll('th'); - const targetCells = theadClone.querySelectorAll('th'); - domHeaderWrap.appendChild(theadClone); - for (const pair of _.zip(sourceCells, targetCells)) { - const [src, dst]: [any, any] = pair; - dst.style.width = `${src.getBoundingClientRect().width - 1}px`; - dst.style.minWidth = `${src.getBoundingClientRect().width - 1}px`; - dst.style.maxWidth = `${src.getBoundingClientRect().width - 1}px`; - } - } - onMount(() => {}); $: loadData(root, $loadedCounts); $: display = root && dataRows ? new PerspectiveDisplay(root, dataRows) : null; - $: { - display; - domTableHead; - domHeaderWrap; - createHeaderClone(); - } - function buildMenu() { return [ { @@ -145,20 +115,15 @@ } -
- - -
{#if display}
- + {#each _.range(display.columnLevelCount) as columnLevel} {#each display.columns as column} @@ -219,15 +184,6 @@ flex: 1; } - .headerWrap { - position: absolute; - left: 0; - top: 0; - right: 14px; - overflow: hidden; - z-index: 100; - } - table { /* position: absolute; left: 0; @@ -235,27 +191,47 @@ bottom: 0; right: 0; */ overflow: scroll; - border-collapse: collapse; + /* border-collapse: collapse; */ outline: none; + + border-collapse: separate; /* Don't collapse */ + border-spacing: 0; } + + table thead { + position: sticky; + top: 0; + z-index: 100; + } + th { - border: 1px solid var(--theme-border); + /* border: 1px solid var(--theme-border); */ text-align: left; padding: 2px; margin: 0; background-color: var(--theme-bg-1); overflow: hidden; vertical-align: center; + z-index: 100; + + border-bottom: 1px solid var(--theme-border); + border-right: 1px solid var(--theme-border); + } + + thead tr:first-child th { + border-top: 1px solid var(--theme-border); } td { font-weight: normal; - border: 1px solid var(--theme-border); + /* border: 1px solid var(--theme-border); */ background-color: var(--theme-bg-0); padding: 2px; position: relative; overflow: hidden; vertical-align: top; + border-bottom: 1px solid var(--theme-border); + border-right: 1px solid var(--theme-border); } /*