Skip to content

Commit 9a59df3

Browse files
committed
Fix query table sorting not accounting for hidden fields
Fixes #1880
1 parent 44fe80f commit 9a59df3

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

specifyweb/frontend/js_src/lib/components/queryresultstable.tsx

+19-4
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export function QueryResultsTable({
282282
readonly sortConfig?: RA<QueryField['sortType']>;
283283
readonly onSelected?: (resource: RA<number>) => void;
284284
readonly onSortChange?: (
285-
fieldIndex: number,
285+
fieldSpec: QueryFieldSpec,
286286
direction: 'ascending' | 'descending' | undefined
287287
) => void;
288288
readonly createRecordSet: JSX.Element | undefined;
@@ -469,7 +469,8 @@ export function QueryResultsTable({
469469
sortConfig={sortConfig?.[index]}
470470
onSortChange={
471471
typeof handleSortChange === 'function'
472-
? (sortType): void => handleSortChange?.(index, sortType)
472+
? (sortType): void =>
473+
handleSortChange?.(fieldSpec, sortType)
473474
: undefined
474475
}
475476
/>
@@ -642,8 +643,22 @@ export function QueryResultsWrapper({
642643
totalCount,
643644
fieldSpecs,
644645
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,
647662
createRecordSet,
648663
extraButtons,
649664
})

0 commit comments

Comments
 (0)