-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTableHeader.tsx
58 lines (48 loc) · 1.49 KB
/
TableHeader.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { flexRender } from '@tanstack/react-table'
import Filter from './Filter'
const TableHeader = ({ headerGroup, filterableInputs }) => {
const renderSortingIcon = (sortDirection: 'asc' | 'desc' | null) => {
const iconMapping = {
asc: 'bi-arrow-up',
desc: 'bi-arrow-down',
inactive: 'bi-arrow-down-up inactive',
}
const iconClass = sortDirection
? iconMapping[sortDirection]
: iconMapping['inactive']
return <i className={`bi ${iconClass} ms-1`} />
}
const createColumnHeader = (header) => {
const columnData = header.column
return (
<button
className="btn btn-sort d-flex justify-content-between"
onClick={columnData.getToggleSortingHandler()}
>
{!header.isPlaceholder &&
flexRender(columnData.columnDef.header, header.getContext())}
{columnData.getCanSort() && renderSortingIcon(columnData.getIsSorted())}
</button>
)
}
return (
<tr key={headerGroup.id}>
{headerGroup.headers.map((header) => {
const hasFilter =
filterableInputs.includes(header.id.toString()) &&
header.column.getCanFilter()
return (
<th
key={header.id}
className={`border ${!hasFilter ? 'align-top' : ''}`}
colSpan={header.colSpan}
>
{createColumnHeader(header)}
{hasFilter && <Filter column={header.column} />}
</th>
)
})}
</tr>
)
}
export default TableHeader