@@ -282,7 +282,7 @@ export function QueryResultsTable({
282
282
readonly sortConfig ?: RA < QueryField [ 'sortType' ] > ;
283
283
readonly onSelected ?: ( resource : RA < number > ) => void ;
284
284
readonly onSortChange ?: (
285
- fieldIndex : number ,
285
+ fieldSpec : QueryFieldSpec ,
286
286
direction : 'ascending' | 'descending' | undefined
287
287
) => void ;
288
288
readonly createRecordSet : JSX . Element | undefined ;
@@ -469,7 +469,8 @@ export function QueryResultsTable({
469
469
sortConfig = { sortConfig ?. [ index ] }
470
470
onSortChange = {
471
471
typeof handleSortChange === 'function'
472
- ? ( sortType ) : void => handleSortChange ?.( index , sortType )
472
+ ? ( sortType ) : void =>
473
+ handleSortChange ?.( fieldSpec , sortType )
473
474
: undefined
474
475
}
475
476
/>
@@ -642,8 +643,22 @@ export function QueryResultsWrapper({
642
643
totalCount,
643
644
fieldSpecs,
644
645
initialData,
645
- sortConfig : fields . map ( ( field ) => field . sortType ) ,
646
- onSortChange : handleSortChange ,
646
+ sortConfig : fields
647
+ . filter ( ( { isDisplay } ) => isDisplay )
648
+ . map ( ( { sortType } ) => sortType ) ,
649
+ onSortChange :
650
+ typeof handleSortChange === 'function'
651
+ ? ( fieldSpec , direction ) => {
652
+ /*
653
+ * If some fields are not displayed, visual index and actual
654
+ * field index differ
655
+ */
656
+ const index = fieldSpecs . indexOf ( fieldSpec ) ;
657
+ const field = displayedFields [ index ] ;
658
+ const originalIndex = allFields . indexOf ( field ) ;
659
+ handleSortChange ( originalIndex , direction ) ;
660
+ }
661
+ : undefined ,
647
662
createRecordSet,
648
663
extraButtons,
649
664
} )
0 commit comments