11import { Meta } from "@storybook/react" ;
22import { StoryObj } from "@storybook/react" ;
33import 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" ;
66import { Checkbox } from "../Checkbox" ;
77
88type DummyData = {
@@ -92,8 +92,23 @@ export const CustomizedVariant: Story = {
9292 }
9393} ;
9494
95+ injectSortingArrowIcons ( {
96+ ArrowUp : ( ) => < div > ↑</ div > ,
97+ ArrowDown : ( ) => < div > ↓</ div >
98+ } ) ;
99+
95100const CustomizedDataTable = ( ) => {
96101 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+ ] ) ;
97112
98113 return (
99114 < div >
@@ -103,6 +118,8 @@ const CustomizedDataTable = () => {
103118 getRowId = { ( x ) => x . id . toString ( ) }
104119 rowSelection = { rowSelection }
105120 onRowSelectionChange = { setRowSelection }
121+ sorting = { sorting }
122+ onSortingChange = { setSorting }
106123 />
107124
108125 < div className = "mt-4" >
@@ -146,11 +163,13 @@ const colsCustomized: ColumnDef<DummyData, unknown>[] = [
146163 {
147164 id : "name" ,
148165 header : "Name" ,
149- accessorKey : "name"
166+ accessorKey : "name" ,
167+ enableSorting : true
150168 } ,
151169 {
152170 id : "age" ,
153171 header : "Age" ,
154- accessorKey : "age"
172+ accessorKey : "age" ,
173+ enableSorting : true
155174 }
156175] ;
0 commit comments