-
Notifications
You must be signed in to change notification settings - Fork 34
feat(#3344): add multi-column sorting to Table and TableSortHeader #3409
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
twjeffery
wants to merge
16
commits into
dev
Choose a base branch
from
tom/table-fixes
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b076582
feat(#3344): add multi-column sorting to Table and TableSortHeader
twjeffery 53750ae
refactor
vanessatran-ddi c497d0d
clean
vanessatran-ddi d2cc751
rebase
vanessatran-ddi 74def17
clean
vanessatran-ddi c58557e
add test
vanessatran-ddi f0845d1
clean
vanessatran-ddi 6457025
clean
vanessatran-ddi 8a30e23
clean
vanessatran-ddi d2c0b29
clean
vanessatran-ddi 6bd6a6d
clean
vanessatran-ddi 7796ce2
fix
vanessatran-ddi 02641bf
clean
vanessatran-ddi 53716d0
clean
vanessatran-ddi 3b739c9
add test
vanessatran-ddi c82cfcf
clean
vanessatran-ddi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
apps/prs/angular/src/routes/features/feat3344/feat3344.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| <h1>PR 4: Table & TableSortHeader V2</h1> | ||
|
|
||
| <goab-block> | ||
| <goab-details heading="Changes in this PR"> | ||
| <p> | ||
| <strong>TableSortHeader:</strong><br /> | ||
| - Always-visible sort icon (chevron-expand when unsorted)<br /> | ||
| - Arrow-up/arrow-down for sorted states<br /> | ||
| - sortOrder prop shows "1", "2" for multi-column sort<br /> | ||
| <br /> | ||
| <strong>Table:</strong><br /> | ||
| - sortMode="single" (default) or "multi" (up to 2 columns)<br /> | ||
| - Initial sort declared on headers via direction + sortOrder<br /> | ||
| - onSort callback with sortBy, sortDir, and sorts array | ||
| </p> | ||
| </goab-details> | ||
| </goab-block> | ||
|
|
||
| <goab-divider mt="l" mb="l"></goab-divider> | ||
|
|
||
| <h2>Test 1: Single-Column Sort (Default)</h2> | ||
| <p>Click column headers to sort. Only one column sorts at a time (default behavior).</p> | ||
| <p><small>Current sort: {{ formatSorts(currentSorts) }}</small></p> | ||
|
|
||
| <goab-table mt="m" (onSort)="onSingleSortChange($event)"> | ||
| <thead> | ||
| <tr> | ||
| <th> | ||
| <goab-table-sort-header name="name">Name</goab-table-sort-header> | ||
| </th> | ||
| <th> | ||
| <goab-table-sort-header name="department">Department</goab-table-sort-header> | ||
| </th> | ||
| <th class="goa-table-cell--numeric"> | ||
| <goab-table-sort-header name="salary">Salary</goab-table-sort-header> | ||
| </th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr *ngFor="let row of data"> | ||
| <td>{{ row.name }}</td> | ||
| <td>{{ row.department }}</td> | ||
| <td class="goa-table-cell--numeric">{{ formatCurrency(row.salary) }}</td> | ||
| </tr> | ||
| </tbody> | ||
| </goab-table> | ||
|
|
||
| <goab-divider mt="l" mb="l"></goab-divider> | ||
|
|
||
| <h2>Test 2: Multi-Column Sort</h2> | ||
| <p>With sortMode="multi", click columns to add them to sort order (up to 2).</p> | ||
| <p><small>Current sort: {{ formatSorts(multiSorts) }}</small></p> | ||
|
|
||
| <goab-table mt="m" sortMode="multi" (onSort)="onMultiSortChange($event)"> | ||
| <thead> | ||
| <tr> | ||
| <th> | ||
| <goab-table-sort-header name="name">Name</goab-table-sort-header> | ||
| </th> | ||
| <th> | ||
| <goab-table-sort-header name="department">Department</goab-table-sort-header> | ||
| </th> | ||
| <th class="goa-table-cell--numeric"> | ||
| <goab-table-sort-header name="salary">Salary</goab-table-sort-header> | ||
| </th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr *ngFor="let row of data"> | ||
| <td>{{ row.name }}</td> | ||
| <td>{{ row.department }}</td> | ||
| <td class="goa-table-cell--numeric">{{ formatCurrency(row.salary) }}</td> | ||
| </tr> | ||
| </tbody> | ||
| </goab-table> | ||
|
|
||
| <goab-divider mt="l" mb="l"></goab-divider> | ||
|
|
||
| <h2>Test 3: Multi Initial Sort (declarative)</h2> | ||
| <p>Two initial sorts declared on headers: Department ascending (primary), Salary descending (secondary). | ||
| Use direction + sortOrder on each header to set priority.</p> | ||
|
|
||
| <goab-table mt="m" sortMode="multi"> | ||
| <thead> | ||
| <tr> | ||
| <th> | ||
| <goab-table-sort-header name="name">Name</goab-table-sort-header> | ||
| </th> | ||
| <th> | ||
| <goab-table-sort-header name="department" direction="asc" [sortOrder]="1">Department</goab-table-sort-header> | ||
| </th> | ||
| <th class="goa-table-cell--numeric"> | ||
| <goab-table-sort-header name="salary" direction="desc" [sortOrder]="2">Salary</goab-table-sort-header> | ||
| </th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr *ngFor="let row of data"> | ||
| <td>{{ row.name }}</td> | ||
| <td>{{ row.department }}</td> | ||
| <td class="goa-table-cell--numeric">{{ formatCurrency(row.salary) }}</td> | ||
| </tr> | ||
| </tbody> | ||
| </goab-table> |
55 changes: 55 additions & 0 deletions
55
apps/prs/angular/src/routes/features/feat3344/feat3344.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { Component } from "@angular/core"; | ||
| import { CommonModule } from "@angular/common"; | ||
| import { | ||
| GoabBlock, | ||
| GoabText, | ||
| GoabDivider, | ||
| GoabDetails, | ||
| GoabTable, | ||
| GoabTableSortHeader, | ||
| } from "@abgov/angular-components"; | ||
| import { GoabTableOnSortDetail, GoabTableSortEntry } from "@abgov/ui-components-common"; | ||
|
|
||
| @Component({ | ||
| standalone: true, | ||
| selector: "abgov-feat3344", | ||
| templateUrl: "./feat3344.component.html", | ||
| imports: [ | ||
| CommonModule, | ||
| GoabBlock, | ||
| GoabText, | ||
| GoabDivider, | ||
| GoabDetails, | ||
| GoabTable, | ||
| GoabTableSortHeader, | ||
| ], | ||
| }) | ||
| export class Feat3344Component { | ||
| currentSorts: GoabTableSortEntry[] = []; | ||
| multiSorts: GoabTableSortEntry[] = []; | ||
|
|
||
| data = [ | ||
| { id: 1, name: "Alice Johnson", department: "Engineering", salary: 95000 }, | ||
| { id: 2, name: "Bob Smith", department: "Marketing", salary: 72000 }, | ||
| { id: 3, name: "Carol Williams", department: "Engineering", salary: 105000 }, | ||
| { id: 4, name: "David Brown", department: "Sales", salary: 68000 }, | ||
| { id: 5, name: "Eve Davis", department: "Marketing", salary: 78000 }, | ||
| ]; | ||
|
|
||
| formatSorts(sorts: GoabTableSortEntry[]): string { | ||
| if (sorts.length === 0) return "None"; | ||
| return sorts.map((s, i) => `${i + 1}. ${s.column} (${s.direction})`).join(", "); | ||
| } | ||
|
|
||
| onSingleSortChange(detail: GoabTableOnSortDetail) { | ||
| this.currentSorts = detail.sorts; | ||
| } | ||
|
|
||
| onMultiSortChange(detail: GoabTableOnSortDetail) { | ||
| this.multiSorts = detail.sorts; | ||
| } | ||
|
|
||
| formatCurrency(value: number): string { | ||
| return "$" + value.toLocaleString(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.