1
1
<script lang =" ts" >
2
- import ' ./index.css' ;
3
- import { writable } from ' svelte/store' ;
2
+ import ' ./index.css'
3
+ import { writable } from ' svelte/store'
4
4
5
- import ' ./index.css' ;
5
+ import ' ./index.css'
6
6
7
7
import {
8
8
createSvelteTable ,
9
9
flexRender ,
10
10
getCoreRowModel ,
11
- getFilteredRowModel ,
12
- getPaginationRowModel ,
13
- type FilterFn
14
- } from ' @tanstack/svelte-table' ;
11
+ getFilteredRowModel ,
12
+ getPaginationRowModel ,
13
+ } from ' @tanstack/svelte-table'
15
14
16
- import { type RankingInfo , rankItem } from ' @tanstack/match-sorter-utils' ;
15
+ import type {
16
+ ColumnDef ,
17
+ TableOptions ,
18
+ FilterFn ,
19
+ } from ' @tanstack/svelte-table'
17
20
18
- import { makeData , type Person } from ' ./makeData ' ;
21
+ import { rankItem } from ' @tanstack/match-sorter-utils '
19
22
20
- declare module ' @tanstack/table-core' {
21
- interface FilterFns {
22
- fuzzy: FilterFn <unknown >;
23
- }
24
- interface FilterMeta {
25
- itemRank: RankingInfo ;
26
- }
27
- }
23
+ import { makeData , type Person } from ' ./makeData'
28
24
29
25
let globalFilter = ' '
30
26
@@ -39,18 +35,20 @@ import './index.css';
39
35
return itemRank .passed
40
36
}
41
37
38
+ let columns: ColumnDef <Person >[] = [
39
+ {
40
+ accessorFn : row => ` ${row .firstName } ${row .lastName } ` ,
41
+ id: ' fullName' ,
42
+ header: ' Name' ,
43
+ cell : info => info .getValue (),
44
+ footer : props => props .column .id ,
45
+ filterFn: ' fuzzy' ,
46
+ },
47
+ ]
48
+
42
49
const options = writable <TableOptions <any >>({
43
50
data: makeData (25 ),
44
- columns: [
45
- {
46
- accessorFn : (row ) => ` ${row .firstName } ${row .lastName } ` ,
47
- id: ' fullName' ,
48
- header: ' Name' ,
49
- cell : (info ) => info .getValue (),
50
- footer : (props ) => props .column .id ,
51
- filterFn: ' fuzzy' ,
52
- },
53
- ],
51
+ columns ,
54
52
filterFns: {
55
53
fuzzy: fuzzyFilter ,
56
54
},
@@ -62,8 +60,19 @@ import './index.css';
62
60
})
63
61
64
62
const table = createSvelteTable (options )
63
+
64
+ const handleKeyUp = (e : any ) => {
65
+ $table .setGlobalFilter (String (e ?.target ?.value ))
66
+ }
65
67
</script >
66
- <input type ="text" placeholder ="Global filter" class ="border w-full p-1" bind:value ={globalFilter } on:keyup ={(e ) => $table .setGlobalFilter (String (e .target .value ))} />
68
+
69
+ <input
70
+ type =" text"
71
+ placeholder =" Global filter"
72
+ class =" border w-full p-1"
73
+ bind:value ={globalFilter }
74
+ on:keyup ={handleKeyUp }
75
+ />
67
76
<div class =" h-2" />
68
77
<table class =" w-full" >
69
78
<thead >
@@ -99,4 +108,4 @@ import './index.css';
99
108
</tbody >
100
109
</table >
101
110
<div class =" h-2" />
102
- <pre >"globalFilter": "{$table .getState ().globalFilter }"</pre >
111
+ <pre >"globalFilter": "{$table .getState ().globalFilter }"</pre >
0 commit comments