import { For } from 'solid-js' import { useTableDevtoolsContext } from '../TableContextProvider' import { useTableStore } from '../useTableStore' import { useStyles } from '../styles/use-styles' import type { Column, RowData, TableFeatures } from '@tanstack/table-core' type AnyColumn = Column function getColumnDefSummary(column: AnyColumn): string { const def = column.columnDef as Record const header = def.header const accessorKey = def.accessorKey const accessorFn = def.accessorFn const parts: Array = [] if (typeof accessorKey === 'string') parts.push(`key: ${accessorKey}`) if (typeof accessorFn === 'function') parts.push('accessorFn') if (header !== undefined) { const headerStr = typeof header === 'string' ? header : typeof header === 'function' ? '[fn]' : String(header) parts.push(`header: ${headerStr}`) } return parts.length > 0 ? parts.join(', ') : '-' } export function ColumnsPanel() { const styles = useStyles() const { table } = useTableDevtoolsContext() const tableInstance = table() const tableState = useTableStore( tableInstance ? tableInstance.store : undefined, (state) => state, ) const getColumns = (): Array => { tableState?.() if (!tableInstance) return [] const tableWithColumnFns = tableInstance as unknown as { getAllFlatColumns?: () => Array getAllLeafColumns?: () => Array } return ( tableWithColumnFns.getAllFlatColumns?.() ?? tableWithColumnFns.getAllLeafColumns?.() ?? [] ) } const columns = getColumns() if (!tableInstance) { return (
Columns
No table instance is connected. Pass a table instance to TableDevtoolsPanel.
) } return (
Columns ({columns.length})
{(column, index) => ( )}
# id depth accessor columnDef
{index() + 1} {column.id} {column.depth} {column.accessorFn ? '✓' : '○'} {getColumnDefSummary(column)}
) }