UNPKG

tav-ui

Version:
52 lines (47 loc) 1.4 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var vue = require('vue'); var log = require('../../../../utils/log2.js'); function useTableScrollTo(tableElRef, getDataSourceRef) { let bodyEl; async function findTargetRowToScroll(targetRowData) { const { id } = targetRowData; const targetRowEl = bodyEl?.querySelector(`[data-row-key="${id}"]`); await vue.nextTick(); bodyEl?.scrollTo({ top: targetRowEl?.offsetTop ?? 0, behavior: "smooth" }); } function scrollTo(pos) { const table = vue.unref(tableElRef); if (!table) return; const tableEl = table.$el; if (!tableEl) return; if (!bodyEl) { bodyEl = tableEl.querySelector(".ant-table-body"); if (!bodyEl) return; } const dataSource = vue.unref(getDataSourceRef); if (!dataSource) return; if (pos === "top") { findTargetRowToScroll(dataSource[0]); } else if (pos === "bottom") { findTargetRowToScroll(dataSource[dataSource.length - 1]); } else { const targetRowData = dataSource.find((data) => data.id === pos); if (targetRowData) { findTargetRowToScroll(targetRowData); } else { log.warn(`id: ${pos} doesn't exist`); } } } return { scrollTo }; } exports.useTableScrollTo = useTableScrollTo; //# sourceMappingURL=useTableScrollTo2.js.map