1
1
import { Meta } from "@storybook/react" ;
2
2
import { StoryObj } from "@storybook/react" ;
3
3
import React , { useState } from "react" ;
4
- import { DataTable } from "./index" ;
5
- import { ColumnDef , RowSelectionState } from "@tanstack/react-table" ;
4
+ import { DataTable , injectSortingArrowIcons } from "./index" ;
5
+ import { ColumnDef , RowSelectionState , SortingState } from "@tanstack/react-table" ;
6
6
import { Checkbox } from "../Checkbox" ;
7
7
8
8
type DummyData = {
@@ -92,8 +92,23 @@ export const CustomizedVariant: Story = {
92
92
}
93
93
} ;
94
94
95
+ injectSortingArrowIcons ( {
96
+ ArrowUp : ( ) => < div > ↑</ div > ,
97
+ ArrowDown : ( ) => < div > ↓</ div >
98
+ } ) ;
99
+
95
100
const CustomizedDataTable = ( ) => {
96
101
const [ rowSelection , setRowSelection ] = useState < RowSelectionState > ( { } ) ;
102
+ const [ sorting , setSorting ] = useState < SortingState > ( [
103
+ {
104
+ id : "name" ,
105
+ desc : true
106
+ } ,
107
+ {
108
+ id : "age" ,
109
+ desc : false
110
+ }
111
+ ] ) ;
97
112
98
113
return (
99
114
< div >
@@ -103,6 +118,8 @@ const CustomizedDataTable = () => {
103
118
getRowId = { ( x ) => x . id . toString ( ) }
104
119
rowSelection = { rowSelection }
105
120
onRowSelectionChange = { setRowSelection }
121
+ sorting = { sorting }
122
+ onSortingChange = { setSorting }
106
123
/>
107
124
108
125
< div className = "mt-4" >
@@ -146,11 +163,13 @@ const colsCustomized: ColumnDef<DummyData, unknown>[] = [
146
163
{
147
164
id : "name" ,
148
165
header : "Name" ,
149
- accessorKey : "name"
166
+ accessorKey : "name" ,
167
+ enableSorting : true
150
168
} ,
151
169
{
152
170
id : "age" ,
153
171
header : "Age" ,
154
- accessorKey : "age"
172
+ accessorKey : "age" ,
173
+ enableSorting : true
155
174
}
156
175
] ;
0 commit comments