@kitr/table 0.0.0-stage → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +14 -2
- package/dist/index.d.ts +97 -0
- package/dist/index.js +135 -0
- package/dist/kitr.d.ts +17 -0
- package/dist/kitr.js +19 -0
- package/docs/api.md +68 -0
- package/docs/index.md +864 -0
- package/docs/overview.md +90 -0
- package/package.json +65 -3
package/docs/overview.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Overview
|
|
3
|
+
description: Show rows of data with sorting, paging and filters that stay in the URL.
|
|
4
|
+
order: 0
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Tables
|
|
8
|
+
|
|
9
|
+
## What it is
|
|
10
|
+
|
|
11
|
+
`@kitr/table` is TanStack Table plus URL state. `useUrlTableState()` keeps sorting, paging and filters in the route's search params; `parseTableSearch()` validates them, so `?page=abc` becomes page 1. Rows come from the server through [query](/packages/query).
|
|
12
|
+
|
|
13
|
+
Runs in the browser. Made for [router](/packages/router)'s `validateSearch` and `navigate`.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
kitr add table
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Adds `@kitr/table` and TanStack Table. No provider, no config file. [Every change](/packages/table/guide#install).
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
Three pieces: columns, a route that accepts table params, and the table. The columns:
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
// app/features/orders/columns.tsx
|
|
29
|
+
import type { ColumnDef, DataTableFeatures } from '@kitr/table'
|
|
30
|
+
|
|
31
|
+
export interface Order {
|
|
32
|
+
id: string
|
|
33
|
+
customer: string
|
|
34
|
+
total: number
|
|
35
|
+
status: 'open' | 'paid' | 'refunded'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const columns: ColumnDef<DataTableFeatures, Order>[] = [
|
|
39
|
+
{ accessorKey: 'customer', header: 'Customer' },
|
|
40
|
+
{ accessorKey: 'total', header: 'Total', cell: ({ row }) => `€${row.original.total.toFixed(2)}` },
|
|
41
|
+
{ accessorKey: 'status', header: 'Status', enableSorting: false },
|
|
42
|
+
]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`validateSearch: parseTableSearch` on the route makes `page`, `size`, `sort` and `filter` typed search params. The page turns them into table state and hands them to the registry's `<DataTable>`:
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
// app/pages/orders/index.tsx
|
|
49
|
+
import { useSuspenseQuery } from '@kitr/query'
|
|
50
|
+
import { getRouteApi } from '@kitr/router'
|
|
51
|
+
import { useUrlTableState } from '@kitr/table'
|
|
52
|
+
import { DataTable } from '#components/ui/data-table'
|
|
53
|
+
import { columns } from '#app/features/orders/columns'
|
|
54
|
+
import { ordersPageQuery } from '#app/features/orders/queries'
|
|
55
|
+
|
|
56
|
+
const route = getRouteApi('/orders')
|
|
57
|
+
|
|
58
|
+
export default function OrdersPage() {
|
|
59
|
+
const search = route.useSearch()
|
|
60
|
+
const navigate = route.useNavigate()
|
|
61
|
+
const { data } = useSuspenseQuery(ordersPageQuery.options(search))
|
|
62
|
+
const urlState = useUrlTableState({
|
|
63
|
+
search,
|
|
64
|
+
setSearch: (patch) => navigate({ search: (prev) => ({ ...prev, ...patch }) }),
|
|
65
|
+
})
|
|
66
|
+
return <DataTable columns={columns} data={data.rows} rowCount={data.total} {...urlState} />
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Click the Total header. The URL becomes `/orders?sort=-total`, the loader fetches that page, and the table shows the largest orders first. Reload and it stays sorted. Next in the guide: [Show your first sortable table](/packages/table/guide#show-your-first-sortable-table).
|
|
71
|
+
|
|
72
|
+
## Built on
|
|
73
|
+
|
|
74
|
+
kitr adds the URL state hook, the search param parser and the feature set for the data table component.
|
|
75
|
+
|
|
76
|
+
## Problems it solves
|
|
77
|
+
|
|
78
|
+
- **Table state lost on reload.** [Keep sorting, paging and filters in the URL](/packages/table/guide#keep-sorting-paging-and-filters-in-the-url).
|
|
79
|
+
- **Crashes from hand-edited URLs.** [Validate the URL](/packages/table/guide#validate-the-url).
|
|
80
|
+
- **Thousands of rows in the browser.** [Fetch one page from the server](/packages/table/guide#fetch-one-page-from-the-server).
|
|
81
|
+
- **Filters per column.** [Filter by a column](/packages/table/guide#filter-by-a-column).
|
|
82
|
+
- **Small datasets that need no API paging.** [Sort and page in the browser](/packages/table/guide#sort-and-page-in-the-browser).
|
|
83
|
+
- **Styling someone else's table markup.** [Render your own markup](/packages/table/guide#render-your-own-markup).
|
|
84
|
+
|
|
85
|
+
## Further reading
|
|
86
|
+
|
|
87
|
+
- [Guide](/packages/table/guide).
|
|
88
|
+
- [API reference](/packages/table/api).
|
|
89
|
+
- [TanStack Table docs](https://tanstack.com/table/latest).
|
|
90
|
+
- [Router](/packages/router) and [Query](/packages/query).
|
package/package.json
CHANGED
|
@@ -1,6 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitr/table",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "@kitr/table: TanStack Table re-exported, plus URL-bound table state.",
|
|
5
|
+
"kitr": {
|
|
6
|
+
"name": "table",
|
|
7
|
+
"title": "Tables",
|
|
8
|
+
"summary": "Show rows of data with sorting, paging and filters that stay in the URL.",
|
|
9
|
+
"category": "interface",
|
|
10
|
+
"runsOn": "client",
|
|
11
|
+
"builtOn": [
|
|
12
|
+
"@tanstack/react-table"
|
|
13
|
+
],
|
|
14
|
+
"client": true,
|
|
15
|
+
"docs": "docs",
|
|
16
|
+
"setup": "./kitr"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/kitrjs/kitr.git",
|
|
23
|
+
"directory": "packages/table"
|
|
24
|
+
},
|
|
25
|
+
"homepage": "https://kitr.dev/packages/table",
|
|
26
|
+
"bugs": "https://github.com/kitrjs/kitr/issues",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./kitr": {
|
|
37
|
+
"types": "./dist/kitr.d.ts",
|
|
38
|
+
"default": "./dist/kitr.js"
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist",
|
|
44
|
+
"docs"
|
|
45
|
+
],
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@kitr/core": "0.3.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"react": ">=18.0.0",
|
|
51
|
+
"@tanstack/react-table": "^9.3.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"tsdown": "^0.23.7",
|
|
55
|
+
"typescript": "^5.9.3",
|
|
56
|
+
"react": "^19.3.1",
|
|
57
|
+
"@types/react": "^19.3.0",
|
|
58
|
+
"@tanstack/react-table": "^9.3.1"
|
|
59
|
+
},
|
|
60
|
+
"keywords": [
|
|
61
|
+
"kitr",
|
|
62
|
+
"kitr-package"
|
|
63
|
+
],
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsdown",
|
|
66
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
67
|
+
}
|
|
6
68
|
}
|