Skip to content

Commit

Permalink
Scroll to previous pos on expansion (#4102)
Browse files Browse the repository at this point in the history
  • Loading branch information
djbarnwal authored Feb 20, 2024
1 parent 68c5289 commit 67676e2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions web-common/src/features/dashboards/pivot/PivotTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
getCoreRowModel,
getExpandedRowModel,
} from "@tanstack/svelte-table";
import type { Readable } from "svelte/motion";
import { derived } from "svelte/store";
import type { PivotDataRow, PivotDataStore } from "./types";
import {
createVirtualizer,
defaultRangeExtractor,
} from "@tanstack/svelte-virtual";
import type { Readable } from "svelte/motion";
import { derived } from "svelte/store";
import type { PivotDataRow, PivotDataStore } from "./types";
export let pivotDataStore: PivotDataStore;
Expand Down Expand Up @@ -68,6 +68,7 @@
getScrollElement: () => containerRefElement,
estimateSize: () => ROW_HEIGHT,
overscan: OVERSCAN,
initialOffset: rowScrollOffset,
rangeExtractor: (range) => {
const next = new Set([...stickyRows, ...defaultRangeExtractor(range)]);
Expand All @@ -78,6 +79,9 @@
$: virtualRows = $virtualizer.getVirtualItems();
$: totalRowSize = $virtualizer.getTotalSize();
let rowScrollOffset = 0;
$: rowScrollOffset = $virtualizer?.scrollOffset || 0;
// In this virtualization model, we create buffer rows before and after our real data
// This maintains the "correct" scroll position when the user scrolls
$: [before, after] = virtualRows.length
Expand Down

1 comment on commit 67676e2

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.