@@ -25,6 +25,7 @@ import {
25
25
getPaginationRowModel ,
26
26
getSortedRowModel ,
27
27
flexRender ,
28
+ SortingFn ,
28
29
} from "@tanstack/react-table" ;
29
30
import {
30
31
Table ,
@@ -89,6 +90,19 @@ export default function QuestionRepositoryContent() {
89
90
{ value : CATEGORY . Arrays , label : "Arrays" } ,
90
91
{ value : CATEGORY . Recursion , label : "Recursion" } ,
91
92
] ;
93
+ const complexityOrder : { [ key in COMPLEXITY ] : number } = {
94
+ [ COMPLEXITY . Easy ] : 1 ,
95
+ [ COMPLEXITY . Medium ] : 2 ,
96
+ [ COMPLEXITY . Hard ] : 3 ,
97
+ } ;
98
+
99
+ // To sort the questions by complexity level
100
+ const complexitySortingFn : SortingFn < QuestionDto > = ( rowA , rowB , columnId ) => {
101
+ const valueA = rowA . getValue ( columnId ) as COMPLEXITY ;
102
+ const valueB = rowB . getValue ( columnId ) as COMPLEXITY ;
103
+
104
+ return complexityOrder [ valueA ] - complexityOrder [ valueB ] ;
105
+ } ;
92
106
93
107
// Define columns with filtering and sorting
94
108
const complexityFilter = ( row : any , columnId : string , filterValue : string [ ] ) => { //TODO: row : any
@@ -143,6 +157,7 @@ export default function QuestionRepositoryContent() {
143
157
< DifficultyBadge complexity = { row . original . q_complexity } />
144
158
) ,
145
159
filterFn : complexityFilter ,
160
+ sortingFn : complexitySortingFn ,
146
161
} ,
147
162
{
148
163
accessorKey : "q_category" ,
@@ -239,7 +254,7 @@ export default function QuestionRepositoryContent() {
239
254
< EmptyPlaceholder />
240
255
) : (
241
256
< div className = "rounded-md border" >
242
- < Table >
257
+ < Table className = "table-fixed" >
243
258
< TableHeader >
244
259
{ table . getHeaderGroups ( ) . map ( ( headerGroup ) => (
245
260
< TableRow key = { headerGroup . id } >
0 commit comments