Skip to content

Commit 1afcf94

Browse files
committed
fix TData inference on tableHelper, update more examples
1 parent 581f621 commit 1afcf94

File tree

62 files changed

+1095
-814
lines changed

Some content is hidden

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

62 files changed

+1095
-814
lines changed

docs/api/features/column-filtering.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ To make a ranking/filtering/sorting system work with tables, `filterFn`s can opt
126126
Below is an example using our own `match-sorter-utils` package (a utility fork of `match-sorter`) to rank, filter, and sort the data
127127
128128
```tsx
129-
import { sortingFns } from '@tanstack/react-table'
129+
import { sortFns } from '@tanstack/react-table'
130130
import { rankItem, compareItems } from '@tanstack/match-sorter-utils'
131131

132132
const fuzzyFilter = (row, columnId, value, addMeta) => {
@@ -152,7 +152,7 @@ const fuzzySort = (rowA, rowB, columnId) => {
152152
}
153153

154154
// Provide an alphanumeric fallback for when the item ranks are equal
155-
return dir === 0 ? sortingFns.alphanumeric(rowA, rowB, columnId) : dir
155+
return dir === 0 ? sortFns.alphanumeric(rowA, rowB, columnId) : dir
156156
}
157157
```
158158

docs/api/features/global-filtering.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ To make a ranking/filtering/sorting system work with tables, `filterFn`s can opt
5252
Below is an example using our own `match-sorter-utils` package (a utility fork of `match-sorter`) to rank, filter, and sort the data
5353
5454
```tsx
55-
import { sortingFns } from '@tanstack/[adapter]-table'
55+
import { sortFns } from '@tanstack/[adapter]-table'
5656
import { rankItem, compareItems } from '@tanstack/match-sorter-utils'
5757

5858
const fuzzyFilter = (row, columnId, value, addMeta) => {
@@ -78,7 +78,7 @@ const fuzzySort = (rowA, rowB, columnId) => {
7878
}
7979

8080
// Provide an alphanumeric fallback for when the item ranks are equal
81-
return dir === 0 ? sortingFns.alphanumeric(rowA, rowB, columnId) : dir
81+
return dir === 0 ? sortFns.alphanumeric(rowA, rowB, columnId) : dir
8282
}
8383
```
8484

docs/api/features/sorting.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ export type SortingFn<TData extends AnyData> = {
6060
Sorting functions can be used/referenced/defined by passing the following to `columnDefinition.sortingFn`:
6161
6262
- A `string` that references a built-in sorting function
63-
- A `string` that references a custom sorting functions provided via the `tableOptions.sortingFns` option
63+
- A `string` that references a custom sorting functions provided via the `tableOptions.sortFns` option
6464
- A function directly provided to the `columnDefinition.sortingFn` option
6565
6666
The final list of sorting functions available for the `columnDef.sortingFn` use the following type:
6767
6868
```tsx
6969
export type SortingFnOption<TData extends AnyData> =
7070
| 'auto'
71-
| SortingFns
72-
| BuiltInSortingFns
71+
| SortFns
72+
| BuiltInSortFns
7373
| SortingFn<TFeatures, TData>
7474
```
7575
@@ -78,7 +78,7 @@ export type SortingFnOption<TData extends AnyData> =
7878
### `sortingFn`
7979
8080
```tsx
81-
sortingFn?: SortingFn | keyof SortingFns | keyof BuiltInSortingFns
81+
sortingFn?: SortingFn | keyof SortFns | keyof BuiltInSortFns
8282
```
8383
8484
The sorting function to use with this column.
@@ -239,18 +239,18 @@ Returns a function that can be used to toggle this column's sorting state. This
239239
240240
## Table Options
241241
242-
### `sortingFns`
242+
### `sortFns`
243243
244244
```tsx
245-
sortingFns?: Record<string, SortingFn>
245+
sortFns?: Record<string, SortingFn>
246246
```
247247
248248
This option allows you to define custom sorting functions that can be referenced in a column's `sortingFn` option by their key.
249249
Example:
250250
251251
```tsx
252252
declare module '@tanstack/table-core' {
253-
interface SortingFns {
253+
interface SortFns {
254254
myCustomSorting: SortingFn<unknown>
255255
}
256256
}
@@ -261,7 +261,7 @@ const column = columnHelper.data('key', {
261261

262262
const table = useTable({
263263
columns: [column],
264-
sortingFns: {
264+
sortFns: {
265265
myCustomSorting: (rowA: any, rowB: any, columnId: any): number =>
266266
rowA.getValue(columnId).value < rowB.getValue(columnId).value ? 1 : -1,
267267
},

docs/guide/fuzzy-filtering.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ When using fuzzy filtering with column filtering, you might also want to sort th
9090

9191
```typescript
9292
import { compareItems } from '@tanstack/match-sorter-utils'
93-
import { sortingFns } from '@tanstack/table'
93+
import { sortFns } from '@tanstack/table'
9494

9595
const fuzzySort: SortingFn<any> = (rowA, rowB, columnId) => {
9696
let dir = 0
@@ -104,7 +104,7 @@ const fuzzySort: SortingFn<any> = (rowA, rowB, columnId) => {
104104
}
105105

106106
// Provide an alphanumeric fallback for when the item ranks are equal
107-
return dir === 0 ? sortingFns.alphanumeric(rowA, rowB, columnId) : dir
107+
return dir === 0 ? sortFns.alphanumeric(rowA, rowB, columnId) : dir
108108
}
109109
```
110110

docs/guide/sorting.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ By default, there are 6 built-in sorting functions to choose from:
145145
- `datetime` - Sorts by time, use this if your values are `Date` objects.
146146
- `basic` - Sorts using a basic/standard `a > b ? 1 : a < b ? -1 : 0` comparison. This is the fastest sorting function, but may not be the most accurate.
147147

148-
You can also define your own custom sorting functions either as the `sortingFn` column option, or as a global sorting function using the `sortingFns` table option.
148+
You can also define your own custom sorting functions either as the `sortingFn` column option, or as a global sorting function using the `sortFns` table option.
149149

150150
#### Custom Sorting Functions
151151

152-
When defining a custom sorting function in either the `sortingFns` table option or as a `sortingFn` column option, it should have the following signature:
152+
When defining a custom sorting function in either the `sortFns` table option or as a `sortingFn` column option, it should have the following signature:
153153

154154
```tsx
155155
//optionally use the SortingFn to infer the parameter types
@@ -200,7 +200,7 @@ const table = useTable({
200200
data,
201201
getCoreRowModel: createCoreRowModel(),
202202
getSortedRowModel: createSortedRowModel(),
203-
sortingFns: { //add a custom sorting function
203+
sortFns: { //add a custom sorting function
204204
myCustomSortingFn: (rowA, rowB, columnId) => {
205205
return rowA.original[columnId] > rowB.original[columnId] ? 1 : rowA.original[columnId] < rowB.original[columnId] ? -1 : 0
206206
},

examples/qwik/filters/src/main.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
createPaginatedRowModel,
1212
createSortedRowModel,
1313
flexRender,
14-
sortingFns,
14+
sortFns,
1515
useTable,
1616
} from '@tanstack/qwik-table'
1717
import { compareItems, rankItem } from '@tanstack/match-sorter-utils'
@@ -58,7 +58,7 @@ const fuzzySort: SortingFn<any> = (rowA, rowB, columnId) => {
5858
}
5959

6060
// Provide an alphanumeric fallback for when the item ranks are equal
61-
return dir === 0 ? sortingFns.alphanumeric(rowA, rowB, columnId) : dir
61+
return dir === 0 ? sortFns.alphanumeric(rowA, rowB, columnId) : dir
6262
}
6363

6464
type Person = {
@@ -220,12 +220,12 @@ const App = component$(() => {
220220
{header.isPlaceholder ? null : (
221221
<>
222222
<div
223-
{...{
224-
class: header.column.getCanSort()
223+
class={
224+
header.column.getCanSort()
225225
? 'cursor-pointer select-none'
226-
: '',
227-
onClick: header.column.getToggleSortingHandler(),
228-
}}
226+
: ''
227+
}
228+
onClick={header.column.getToggleSortingHandler()}
229229
>
230230
{flexRender(
231231
header.column.columnDef.header,

examples/qwik/row-selection/src/main.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,32 +61,28 @@ const columns: Array<ColumnDef<any, Person>> = [
6161
id: 'select',
6262
header: ({ table }) => (
6363
<IndeterminateCheckbox
64-
{...{
65-
checked: table.getIsAllRowsSelected(),
66-
indeterminate: table.getIsSomeRowsSelected(),
67-
onChange$: $(() => {
68-
console.log('toggleAllRowsSelected')
69-
table.toggleAllRowsSelected()
70-
}),
71-
}}
64+
checked={table.getIsAllRowsSelected()}
65+
indeterminate={table.getIsSomeRowsSelected()}
66+
onChange$={$(() => {
67+
console.log('toggleAllRowsSelected')
68+
table.toggleAllRowsSelected()
69+
})}
7270
/>
7371
),
7472
cell: ({ row, table }) => {
7573
const { id } = row
7674
return (
7775
<div class="px-1">
7876
<IndeterminateCheckbox
79-
{...{
80-
checked: row.getIsSelected(),
81-
disabled: !row.getCanSelect(),
82-
indeterminate: row.getIsSomeSelected(),
83-
// onChange: row.getToggleSelectedHandler(),
84-
onChange$: $(() => {
85-
// TODO: getting row instance from table works, but how can we call getToggleSelectedHandler() withour getting qwik qrl error?
86-
const row = table.getRow(id)
87-
row.toggleSelected()
88-
}),
89-
}}
77+
checked={row.getIsSelected()}
78+
disabled={!row.getCanSelect()}
79+
indeterminate={row.getIsSomeSelected()}
80+
// onChange: row.getToggleSelectedHandler(),
81+
onChange$={$(() => {
82+
// TODO: getting row instance from table works, but how can we call getToggleSelectedHandler() without getting qwik qrl error?
83+
const row = table.getRow(id)
84+
row.toggleSelected()
85+
})}
9086
/>
9187
</div>
9288
)

examples/react/basic-table-helper/src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const defaultData: Array<Person> = [
5353

5454
// 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
5555
const tableHelper = createTableHelper({
56-
_features: { columnSizingFeature: {} },
56+
_features: {},
5757
_rowModels: {}, // client-side row models. `Core` row model is now included by default, but you can still override it here
5858
_processingFns: {}, // client-side processing functions used by the row models (sorting, filtering, etc.). Not needed in this basic example
5959
debugTable: true,

examples/react/column-ordering/src/main.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,9 @@ function App() {
112112
<div className="px-1 border-b border-black">
113113
<label>
114114
<input
115-
{...{
116-
type: 'checkbox',
117-
checked: table.getIsAllColumnsVisible(),
118-
onChange: table.getToggleAllColumnsVisibilityHandler(),
119-
}}
115+
type="checkbox"
116+
checked={table.getIsAllColumnsVisible()}
117+
onChange={table.getToggleAllColumnsVisibilityHandler()}
120118
/>{' '}
121119
Toggle All
122120
</label>
@@ -126,11 +124,9 @@ function App() {
126124
<div key={column.id} className="px-1">
127125
<label>
128126
<input
129-
{...{
130-
type: 'checkbox',
131-
checked: column.getIsVisible(),
132-
onChange: column.getToggleVisibilityHandler(),
133-
}}
127+
type="checkbox"
128+
checked={column.getIsVisible()}
129+
onChange={column.getToggleVisibilityHandler()}
134130
/>{' '}
135131
{column.id}
136132
</label>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
dist-ssr
5+
*.local

0 commit comments

Comments
 (0)