Skip to content

Highlight the current column that a table is being sorted by #1165

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

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/ts/controllers/s-table.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import * as Stacks from "../stacks";

const sortedHeaderBackground = 'bg-powder-200';
const sortedColumnBackground = 'bg-powder-100';

export class TableController extends Stacks.StacksController {
static targets = ["column"];
readonly columnTarget!: Element;
Expand All @@ -19,6 +22,8 @@ export class TableController extends Stacks.StacksController {
isCurrrent && direction !== "none"
);

target.classList.toggle(sortedHeaderBackground, isCurrrent);

target
.querySelectorAll(".js-sorting-indicator")
.forEach(function (icon) {
Expand Down Expand Up @@ -136,6 +141,13 @@ export class TableController extends Stacks.StacksController {
data.forEach(function (tup) {
const row = rows[tup[1]];
row.parentElement?.removeChild(row);

for (let i = 0; i < row.cells.length; i++) {
const cell = row.cells.item(i);

cell?.classList.toggle(sortedColumnBackground, i === colno);
}

if (firstBottomRow) {
tbody.insertBefore(row, firstBottomRow);
} else {
Expand Down