Add basic table sorting
All checks were successful
build / build (push) Successful in 1m20s

This commit is contained in:
2025-04-25 07:39:39 +09:30
parent cc5bbb9b6a
commit d225ff9048
2 changed files with 25 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ import { Column, DuckdbService } from '../duckdb.service';
template: `
@if (file() && columns().length > 0) {
<p-table
sortMode="multiple"
[reorderableColumns]="true"
[resizableColumns]="true"
columnResizeMode="expand"
@@ -37,8 +38,12 @@ import { Column, DuckdbService } from '../duckdb.service';
<ng-template #header let-columns>
<tr>
@for (col of columns; track $index) {
<th pReorderableColumn pResizableColumn>
{{ col.name }}
<th
pReorderableColumn
pResizableColumn
[pSortableColumn]="col.name"
>
{{ col.name }} <p-sortIcon [field]="col.name" />
</th>
}
</tr>
@@ -71,7 +76,6 @@ export class FileViewerComponent {
file = input<File | undefined>();
private duckdbService = inject(DuckdbService);
private cdr = inject(ChangeDetectorRef);
// Can't be computed since effect has to run first so file exists in duckdb
protected columns = signal<Column[]>([]);
@@ -92,6 +96,7 @@ export class FileViewerComponent {
this.columns(),
[],
[],
[],
);
const newValue = Array.from({ length: Number(rows.totalRows) });
this.currentValue.set(newValue);
@@ -107,6 +112,10 @@ export class FileViewerComponent {
event.first ?? 0,
event.rows ?? 0,
this.columns(),
event.multiSortMeta?.map((meta) => ({
name: meta.field,
sortType: meta.order < 0 ? 'desc' : 'asc',
})) ?? [],
[],
[],
);
@@ -122,7 +131,7 @@ export class FileViewerComponent {
}
// Can't update the current value, otherwise we get an infinite loop
this.currentValue().splice(event.first!, event.rows!, ...rows.rows);
this.cdr.markForCheck();
event.forceUpdate!();
}
}
}