1
+ import { getValidClassNames } from '~/libs/helpers/helpers.js' ;
1
2
import {
2
3
flexRender ,
3
4
getCoreRowModel ,
8
9
import { type ColumnDef } from '~/libs/types/types.js' ;
9
10
10
11
import { Pagination } from '../pagination/pagination.jsx' ;
12
+ import { DEFAULT_COLUMN } from './libs/constant.js' ;
11
13
import styles from './styles.module.scss' ;
12
14
13
15
type Properties < T > = {
@@ -33,6 +35,8 @@ const Table = <T,>({
33
35
const table = useReactTable ( {
34
36
data,
35
37
columns,
38
+ columnResizeMode : 'onChange' ,
39
+ defaultColumn : DEFAULT_COLUMN ,
36
40
getCoreRowModel : getCoreRowModel ( ) ,
37
41
getPaginationRowModel : getPaginationRowModel ( ) ,
38
42
initialState : {
@@ -56,13 +60,29 @@ const Table = <T,>({
56
60
{ table . getHeaderGroups ( ) . map ( ( headerGroup ) => (
57
61
< tr key = { headerGroup . id } className = { styles . tr } >
58
62
{ headerGroup . headers . map ( ( header ) => (
59
- < th key = { header . id } className = { styles . th } >
63
+ < th
64
+ key = { header . id }
65
+ className = { styles . th }
66
+ style = { {
67
+ width : header . getSize ( ) ,
68
+ } }
69
+ >
60
70
{ header . isPlaceholder
61
71
? null
62
72
: flexRender (
63
73
header . column . columnDef . header ,
64
74
header . getContext ( ) ,
65
75
) }
76
+ < div
77
+ { ...{
78
+ onMouseDown : header . getResizeHandler ( ) ,
79
+ onTouchStart : header . getResizeHandler ( ) ,
80
+ className : getValidClassNames (
81
+ styles . resizer ,
82
+ header . column . getIsResizing ( ) && styles . isResizing ,
83
+ ) ,
84
+ } }
85
+ />
66
86
</ th >
67
87
) ) }
68
88
</ tr >
@@ -75,7 +95,13 @@ const Table = <T,>({
75
95
{ table . getRowModel ( ) . rows . map ( ( row ) => (
76
96
< tr key = { row . id } className = { styles . tr } >
77
97
{ row . getVisibleCells ( ) . map ( ( cell ) => (
78
- < td key = { cell . id } className = { styles . td } >
98
+ < td
99
+ key = { cell . id }
100
+ className = { styles . td }
101
+ style = { {
102
+ width : cell . column . getSize ( ) ,
103
+ } }
104
+ >
79
105
{ flexRender ( cell . column . columnDef . cell , cell . getContext ( ) ) }
80
106
</ td >
81
107
) ) }
@@ -86,7 +112,12 @@ const Table = <T,>({
86
112
87
113
return (
88
114
< div className = { styles . container } >
89
- < table className = { styles . table } >
115
+ < table
116
+ className = { styles . table }
117
+ style = { {
118
+ width : table . getCenterTotalSize ( ) ,
119
+ } }
120
+ >
90
121
{ createThead ( ) }
91
122
{ createTbody ( ) }
92
123
</ table >
0 commit comments