import { FlexRender, createSortedRowModel, createTable, rowSortingFeature, sortFn_alphanumeric, sortFn_text, tableFeatures, } from '@tanstack/solid-table' import { For, Show, createSignal } from 'solid-js' import { makeData } from './makeData' import type { ColumnDef } from '@tanstack/solid-table' import type { Person } from './makeData' const features = tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns: { alphanumeric: sortFn_alphanumeric, text: sortFn_text, }, }) function App() { const [data, setData] = createSignal(makeData(1_000)) const refreshData = () => setData(makeData(1_000)) const stressTest = () => setData(makeData(1_000_000)) const columns: Array> = [ { id: 'rowNumber', header: '#', cell: ({ row }) => row.getDisplayIndex() + 1, }, { header: 'Name', footer: (props) => props.column.id, columns: [ { accessorKey: 'firstName', cell: (info) => info.getValue(), footer: (props) => props.column.id, }, { accessorFn: (row) => row.lastName, id: 'lastName', cell: (info) => info.getValue(), header: () => Last Name, footer: (props) => props.column.id, }, { accessorKey: 'email', header: 'Email', sortFn: 'alphanumeric', footer: (props) => props.column.id, }, ], }, { header: 'Info', footer: (props) => props.column.id, columns: [ { accessorKey: 'age', header: () => 'Age', footer: (props) => props.column.id, }, { header: 'More Info', columns: [ { accessorKey: 'visits', header: () => Visits, footer: (props) => props.column.id, }, { accessorKey: 'status', header: 'Status', footer: (props) => props.column.id, }, { accessorKey: 'progress', header: 'Profile Progress', footer: (props) => props.column.id, }, ], }, ], }, ] const table = createTable({ features, get data() { return data() }, columns, // initialState: { sorting: [{ id: 'firstName', desc: false }] }, // set the initial sort once // atoms: { sorting: sortingAtom }, // preferred: own sorting state with an external atom // state: { sorting }, // classic controlled state; pair with onSortingChange // onSortingChange: setSorting, // enableSorting: false, // disable sorting for every column; default true // sortDescFirst: true, // start every sort cycle with descending order; inferred by column data by default // enableSortingRemoval: false, // keep a sorted column sorted when toggling; default true // enableMultiSort: false, // disable Shift-click multi-sorting; default true // enableMultiRemove: false, // prevent a multi-sort toggle from removing a sorted column; default true // isMultiSortEvent: () => true, // make every sort interaction a multi-sort; default requires Shift // maxMultiSortColCount: 3, // limit multi-sorting to three columns; default Infinity // manualSorting: true, // pass data that is already sorted, for example from a server // autoResetPageIndex: false, // with pagination, keep the current page when sorting changes; default true debugTable: true, }) return (
{(headerGroup) => ( {(header) => ( )} )} {(row) => ( {(cell) => ( )} )}
{{ asc: ' 🔼', desc: ' 🔽', }[header.column.getIsSorted() as string] ?? null}
{table.getRowModel().rows.length.toLocaleString()} Rows
        {JSON.stringify(table.store.get(), null, 2)}
      
) } export default App