Skip to content

Commit 88f0f3a

Browse files
feat(solid): add solid createTableHook and v9 examples (#6198)
* feat: add solid createTableHook * feat(solid): createTableHook helper Add new examples: - basic app table - composble tables Update config.json to render new solid table examples * ci: apply automated fixes * chore(solid): add new table examples Add new examples: - basic-external-state - basic-external-stpore - basic-use-table - with-tanstack-query Update config.json to render new solid table examples --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent a85e333 commit 88f0f3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3721
-163
lines changed

docs/config.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,10 @@
822822
{
823823
"label": "solid",
824824
"children": [
825-
{ "to": "framework/solid/examples/basic", "label": "Basic" },
826-
{ "to": "framework/solid/examples/basic-table-helper", "label": "Basic with Helpers" },
825+
{ "to": "framework/solid/examples/basic-use-table", "label": "Basic (createTable)" },
826+
{ "to": "framework/solid/examples/basic-app-table", "label": "Basic (createAppTable)" },
827+
{ "to": "framework/solid/examples/basic-external-state", "label": "Basic (External State)" },
828+
{ "to": "framework/solid/examples/basic-external-store", "label": "Basic (External Store)" },
827829
{ "to": "framework/solid/examples/column-groups", "label": "Header Groups" }
828830
]
829831
},
@@ -999,8 +1001,9 @@
9991001
{
10001002
"label": "solid",
10011003
"children": [
1002-
{ "to": "framework/solid/examples/bootstrap", "label": "Solid Bootstrap" }
1003-
]
1004+
{ "to": "framework/solid/examples/bootstrap", "label": "Solid Bootstrap" },
1005+
{ "to": "framework/solid/examples/composable-tables", "label": "Composable Tables" },
1006+
{ "to": "framework/solid/examples/with-tanstack-query", "label": "With TanStack Query" }]
10041007
},
10051008
{
10061009
"label": "vue",
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/solid/basic/package.json renamed to examples/solid/basic-app-table/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "tanstack-table-example-solid-basic",
2+
"name": "tanstack-table-example-solid-basic-app-table",
33
"version": "0.0.0",
44
"description": "",
55
"scripts": {

examples/solid/basic-table-helper/src/App.tsx renamed to examples/solid/basic-app-table/src/App.tsx

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { createTableHelper, flexRender } from '@tanstack/solid-table'
1+
import { createTableHook } from '@tanstack/solid-table'
22
import { For, createSignal } from 'solid-js'
33

4-
// This example uses the new `createTableHelper` method to create a re-usable table helper object instead of independently using the standalone `createTable` hook and `createColumnHelper` method. You can choose to use either way.
4+
// This example uses the new `createTableHook` method to create a re-usable table hook factory instead of independently using the standalone `useTable` hook and `createColumnHelper` method. You can choose to use either way.
55

66
// 1. Define what the shape of your data will be for each row
77
type Person = {
@@ -39,20 +39,25 @@ const defaultData: Array<Person> = [
3939
status: 'Complicated',
4040
progress: 10,
4141
},
42+
{
43+
firstName: 'kevin',
44+
lastName: 'vandy',
45+
age: 28,
46+
visits: 100,
47+
status: 'Single',
48+
progress: 70,
49+
},
4250
]
4351

4452
// 3. New in V9! Tell the table which features and row models we want to use. In this case, this will be a basic table with no additional features
45-
const tableHelper = createTableHelper({
53+
const { createAppTable, createAppColumnHelper } = createTableHook({
4654
_features: {},
4755
_rowModels: {}, // client-side row models. `Core` row model is now included by default, but you can still override it here
48-
49-
TData: {} as Person,
5056
debugTable: true,
5157
})
5258

5359
// 4. Create a helper object to help define our columns
54-
// const { columnHelper } = tableHelper // if TData was set in the table helper options - otherwise use the createColumnHelper method below
55-
const columnHelper = tableHelper.createColumnHelper<Person>()
60+
const columnHelper = createAppColumnHelper<Person>()
5661

5762
// 5. Define the columns for your table with a stable reference (in this case, defined statically outside of a react component)
5863
const columns = columnHelper.columns([
@@ -89,21 +94,28 @@ const columns = columnHelper.columns([
8994
}),
9095
])
9196

92-
function App() {
97+
export function App() {
9398
// 6. Store data with a stable reference
94-
const [data, setData] = createSignal(defaultData)
95-
const rerender = () => setData(defaultData)
99+
const [data, setData] = createSignal([...defaultData])
100+
101+
// Helper to rerender with sorted data (by age ascending)
102+
function rerender() {
103+
setData((prev) =>
104+
prev.slice().sort((a: Person, b: Person) => a.age - b.age),
105+
)
106+
}
96107

97108
// 7. Create the table instance with the required columns and data.
98-
// Features and row models are already defined in the table helper object above
99-
const table = tableHelper.createTable({
109+
// Features and row models are already defined in the createTableHook call above
110+
const table = createAppTable({
100111
columns,
101112
get data() {
102113
return data()
103114
},
104-
// add additional table options here or in the table helper above
115+
// add additional table options here or in the createTableHook call above
105116
})
106117

118+
// 8. Render your table markup from the table instance APIs
107119
return (
108120
<div class="p-2">
109121
<table>
@@ -114,12 +126,7 @@ function App() {
114126
<For each={headerGroup.headers}>
115127
{(header) => (
116128
<th>
117-
{header.isPlaceholder
118-
? null
119-
: flexRender(
120-
header.column.columnDef.header,
121-
header.getContext(),
122-
)}
129+
<table.FlexRender header={header} />
123130
</th>
124131
)}
125132
</For>
@@ -134,10 +141,7 @@ function App() {
134141
<For each={row.getAllCells()}>
135142
{(cell) => (
136143
<td>
137-
{flexRender(
138-
cell.column.columnDef.cell,
139-
cell.getContext(),
140-
)}
144+
<table.FlexRender cell={cell} />
141145
</td>
142146
)}
143147
</For>
@@ -152,12 +156,7 @@ function App() {
152156
<For each={footerGroup.headers}>
153157
{(header) => (
154158
<th>
155-
{header.isPlaceholder
156-
? null
157-
: flexRender(
158-
header.column.columnDef.footer,
159-
header.getContext(),
160-
)}
159+
<table.FlexRender footer={header} />
161160
</th>
162161
)}
163162
</For>
@@ -167,11 +166,9 @@ function App() {
167166
</tfoot>
168167
</table>
169168
<div class="h-4" />
170-
<button onClick={() => rerender()} class="border p-2">
171-
Rerender
169+
<button onClick={rerender} class="border p-2">
170+
Rerender (sort by age)
172171
</button>
173172
</div>
174173
)
175174
}
176-
177-
export default App
File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { render } from 'solid-js/web'
2+
import './index.css'
3+
import { App } from './App'
4+
5+
render(() => <App />, document.getElementById('root') as HTMLElement)
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)