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

41 lines (40 loc) 1.53 kB
import { type Writable } from 'svelte/store'; import type { NewTablePropSet, TablePlugin } from '../types/TablePlugin.js'; /** * Configuration options for the addColumnOrder plugin. */ export interface ColumnOrderConfig { /** Initial order of column IDs. Columns are ordered in this sequence. */ initialColumnIdOrder?: string[]; /** If true, columns not in the order list are hidden. Defaults to false. */ hideUnspecifiedColumns?: boolean; } /** * State exposed by the addColumnOrder plugin. */ export interface ColumnOrderState { /** Writable store containing the ordered list of column IDs. */ columnIdOrder: Writable<string[]>; } /** * Creates a column order plugin that enables reordering table columns. * Columns are displayed in the order specified by columnIdOrder. * * @template Item - The type of data items in the table. * @param config - Configuration options. * @returns A TablePlugin that provides column ordering functionality. * @example * ```typescript * const table = createTable(data, { * order: addColumnOrder({ * initialColumnIdOrder: ['name', 'age', 'email'], * hideUnspecifiedColumns: false * }) * }) * * // Reorder columns dynamically * const { columnIdOrder } = table.pluginStates.order * columnIdOrder.set(['email', 'name', 'age']) * ``` */ export declare const addColumnOrder: <Item>({ initialColumnIdOrder, hideUnspecifiedColumns }?: ColumnOrderConfig) => TablePlugin<Item, ColumnOrderState, Record<string, never>, NewTablePropSet<never>>;