Fix/issue 27 server side sorting - #39
Conversation
|
rebase this on the latest from main |
02058b6 to
335c647
Compare
| // If we have initial characters and this is not a pagination request, | ||
| const activeSort = sorting[0]; | ||
| const sortBy = activeSort?.id; | ||
| const sortOrder = activeSort?.desc ? "desc" : "asc"; |
There was a problem hiding this comment.
Let’s make the table’s default sort explicit. With the current code, no active sort produces sortBy=undefined but sortOrder="asc". The initial page is level-descending, while later pagination requests become level-ascending. Defaulting to level/desc keeps every page consistently ordered:
const sortBy = activeSort?.id ?? "level";
const sortOrder = activeSort
? activeSort.desc
? "desc"
: "asc"
: "desc";| orderByClause = `(C.full_response_json->'character'->>'mana')::int ${orderDirection}, C.character_db_id DESC`; | ||
| } else if (filter.sortBy === "level") { | ||
| orderByClause = `C.level ${orderDirection}, C.character_db_id DESC`; | ||
| } |
There was a problem hiding this comment.
CharacterTable can send sortBy="highestSkLevel", but none of the branches above handle it, so clicking that column currently falls back to sorting by character level. Let's add this branch before the ordering block ends:
} else if (filter.sortBy === "highestSkLevel") {
orderByClause = `
(C.full_response_json->'realSkills'->0->>'level')::int
${orderDirection}
NULLS LAST,
C.character_db_id DESC
`;
}| columns, | ||
| data: tableDisplayData, | ||
| manualPagination: true, | ||
| manualSorting: true, |
There was a problem hiding this comment.
Mantine React Table enables multi-column sorting by default, but this implementation only sends sorting[0] to the API. Shift-clicking another sortable column therefore displays multiple sort indicators while the server ignores every key after the first. Please set enableMultiSort: false, or extend the API to support all selected keys.
Summary of Changes:
ORDER BYhandling (level,name,life,mana) ingetFilteredCharacters()prior to paginationLIMIT/OFFSET.sortBy&sortOrderquery params in/api/characters.charactersAPI.getCharacters().manualSorting: true,sortingstate, andonSortingChangehandler to refetch page 1 with global sorting when column headers are clicked.