-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add table sorting #1152
base: main
Are you sure you want to change the base?
Add table sorting #1152
Conversation
Fixes #1120.
} | ||
|
||
button.onclick = () => { | ||
const isAscending = header.getAttribute("aria-sort") !== "ascending"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty confusing assignment. I think that your intent is to say that the sort should be ascending when the current state is not ascending, but the negation and naming here makes it look backwards. Maybe:
const isAscending = header.getAttribute("aria-sort") !== "ascending"; | |
const sortAscending = header.getAttribute("aria-sort") !== "ascending"; |
return ascending | ||
? a.localeCompare(b, undefined, { numeric: sortNumerically }) | ||
: b.localeCompare(a, undefined, { numeric: sortNumerically }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ascending | |
? a.localeCompare(b, undefined, { numeric: sortNumerically }) | |
: b.localeCompare(a, undefined, { numeric: sortNumerically }); | |
[a, b] = ascending ? [a, b] : [b, a]; | |
return a.localeCompare(b, undefined, { numeric: sortNumerically }); |
if (isInitDescending) { | ||
header.setAttribute("aria-sort", "descending"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the code, it wasn't clear to me that this column was:
a) reverse-sorted to begin with
b) effectively the primary sort column for the table
A comment to that effect might help.
} | ||
const button = document.createElement("button"); | ||
const isInitDescending = header.classList.contains("more-info"); | ||
const sortNumerically = isInitDescending; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const sortNumerically = isInitDescending; | |
const sortNumerically = isInitDescending; // Coincidentally, this is the only numeric column. |
return; | ||
} | ||
const button = document.createElement("button"); | ||
const isInitDescending = header.classList.contains("more-info"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const isInitDescending = header.classList.contains("more-info"); | |
// "more-info" is the column that starts out being sorted; in reverse order. | |
const isInitDescending = header.classList.contains("more-info"); |
Fixes #1120.