UNPKG

@1771technologies/lytenyte-pro

Version:

Blazingly fast headless React data grid with 100s of features.

51 lines (50 loc) 2.08 kB
import { columnScrollIntoViewValue, rowScrollIntoViewValue, } from "@1771technologies/lytenyte-shared"; export const makeScrollIntoView = (grid) => { return (opts) => { const vp = grid.state.viewport.get(); if (!vp) return; let x = undefined; let y = undefined; const col = opts.column; if (col != null) { const meta = grid.state.columnMeta.get(); let colIndex; if (typeof col === "number") colIndex = col; else if (typeof col === "string") colIndex = meta.columnsVisible.findIndex((c) => c.id === col); else colIndex = meta.columnsVisible.findIndex((c) => c.id === col.id); if (colIndex !== -1) { x = columnScrollIntoViewValue({ centerCount: meta.columnsVisible.filter((c) => c.pin !== "start" && c.pin !== "end") .length, startCount: meta.columnsVisible.filter((c) => c.pin === "start").length, endCount: meta.columnsVisible.filter((c) => c.pin === "end").length, columnIndex: colIndex, columnPositions: grid.state.xPositions.get(), viewport: vp, }); } } const row = opts.row; if (row != null) { y = rowScrollIntoViewValue({ bottomCount: grid.state.rowDataStore.rowBottomCount.get(), topCount: grid.state.rowDataStore.rowTopCount.get(), rowCount: grid.state.rowDataStore.rowCount.get(), headerHeight: grid.internal.headerHeightTotal.get(), rowIndex: row, rowPositions: grid.state.yPositions.get(), viewport: vp, }); } const rtl = grid.state.rtl.get(); vp.scrollTo({ left: x != null ? x * (rtl ? -1 : 1) : undefined, top: y, behavior: opts.behavior ?? "auto", }); }; };