UNPKG

@humanspeak/svelte-headless-table

Version:

A powerful, headless table library for Svelte that provides complete control over table UI while handling complex data operations like sorting, filtering, pagination, grouping, and row expansion. Build custom, accessible data tables with zero styling opin

29 lines (28 loc) 890 B
import { derived } from 'svelte/store'; import { DataBodyRow, getSubRows } from '../bodyRows.js'; const withSubRows = (row, getChildren) => { const subItems = getChildren(row.original); if (subItems === undefined) { return row; } const subRows = getSubRows(subItems, row); row.subRows = subRows.map((row) => withSubRows(row, getChildren)); return row; }; export const addSubRows = ({ children }) => () => { const getChildren = children instanceof Function ? children : (item) => item[children]; const deriveRows = (rows) => { return derived(rows, ($rows) => { return $rows.map((row) => { if (row.isData()) { return withSubRows(row, getChildren); } return row; }); }); }; return { pluginState: {}, deriveRows }; };