1import { Component, Input } from "@angular/core";
2import {SimpleTableComponent} from "@simple-table/angular";import type { AngularHeaderObject, Row, Theme } from "@simple-table/angular";
3import { nestedHeadersConfig } from "./nested-headers.demo-data";
4import "@simple-table/angular/styles.css";
5
6@Component({
7 selector: "nested-headers-demo",
8 standalone: true,
9 imports: [SimpleTableComponent],
10 template: `
11 <simple-table
12 [rows]="rows"
13 [defaultHeaders]="headers"
14 [height]="height"
15 [theme]="theme"
16 [columnResizing]="columnResizing"
17 ></simple-table>
18 `,
19})
20export class NestedHeadersDemoComponent {
21 @Input() height: string | number = "400px";
22 @Input() theme?: Theme;
23
24 readonly rows: Row[] = nestedHeadersConfig.rows;
25 readonly headers: AngularHeaderObject[] = nestedHeadersConfig.headers;
26 readonly columnResizing = nestedHeadersConfig.tableProps.columnResizing;
27}
28
29
30// nested-headers.demo-data.ts
31// Self-contained demo table setup for this example.
32import type { AngularHeaderObject } from "@simple-table/angular";
33
34
35export const nestedHeadersHeaders: AngularHeaderObject[] = [
36 { accessor: "id", label: "ID", width: 80, isSortable: true, type: "number" },
37 { accessor: "name", label: "Name", width: "1fr", isSortable: true, type: "string" },
38 {
39 accessor: "score",
40 label: "Test Scores",
41 width: 300,
42 isSortable: false,
43 type: "number",
44 children: [
45 { accessor: "mathScore", label: "Math", width: 100, isSortable: true, type: "number", align: "right" },
46 { accessor: "scienceScore", label: "Science", width: 100, isSortable: true, type: "number", align: "right" },
47 { accessor: "historyScore", label: "History", width: 100, isSortable: true, type: "number", align: "right" },
48 ],
49 },
50 { accessor: "grade", label: "Overall Grade", width: 120, isSortable: true, type: "string", align: "center" },
51];
52
53export const nestedHeadersData = [
54 { id: 1, name: "Aria Chen", mathScore: 94, scienceScore: 89, historyScore: 92, grade: "A" },
55 { id: 2, name: "Kai Rodriguez", mathScore: 81, scienceScore: 85, historyScore: 78, grade: "B" },
56 { id: 3, name: "Luna Nakamura", mathScore: 96, scienceScore: 94, historyScore: 93, grade: "A" },
57 { id: 4, name: "Phoenix Williams", mathScore: 72, scienceScore: 75, historyScore: 69, grade: "C" },
58 { id: 5, name: "River Martinez", mathScore: 87, scienceScore: 91, historyScore: 83, grade: "B" },
59 { id: 6, name: "Sage Thompson", mathScore: 79, scienceScore: 74, historyScore: 82, grade: "B" },
60 { id: 7, name: "Nova Patel", mathScore: 93, scienceScore: 88, historyScore: 95, grade: "A" },
61 { id: 8, name: "Atlas Kim", mathScore: 86, scienceScore: 82, historyScore: 89, grade: "B" },
62 { id: 9, name: "Zara Hassan", mathScore: 91, scienceScore: 97, historyScore: 87, grade: "A" },
63 { id: 10, name: "Orion Singh", mathScore: 77, scienceScore: 73, historyScore: 80, grade: "B" },
64 { id: 11, name: "Echo Volkov", mathScore: 95, scienceScore: 92, historyScore: 98, grade: "A" },
65];
66
67export const nestedHeadersConfig = {
68 headers: nestedHeadersHeaders,
69 rows: nestedHeadersData,
70 tableProps: { columnResizing: true },
71} as const;
72