Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Examples/Gallery/Data/GlassTableExample.swift8// Module : Examples9// Repository : https://git.spboucher.ai/sp-glasskit10// Project Website : https://glass.spboucher.ai11// Created : 2026-12-0212// Last Modified : 2026-12-0213//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import SPGlassKit4344public struct GlassTableExample: GlassExample {45 public static let componentID = "glass-table"4647 struct Station: Identifiable {48 let id: String49 let name: String50 let line: String51 let dailyRiders: Int52 let opened: Int53 }5455 // Fictitious data.56 private let stations = [57 Station(id: "s1", name: "Harbour Square", line: "Blue", dailyRiders: 48_200, opened: 1987),58 Station(id: "s2", name: "Élan–Université", line: "Green", dailyRiders: 31_750, opened: 2004),59 Station(id: "s3", name: "North Mills", line: "Blue", dailyRiders: 9_640, opened: 1991),60 Station(id: "s4", name: "Parc des Érables", line: "Orange", dailyRiders: 22_310, opened: 2016),61 Station(id: "s5", name: "Old Foundry", line: "Green", dailyRiders: 9_640, opened: 1979),62 ]6364 private let columns: [GlassTableColumn<Station>] = [65 GlassTableColumn("Station", id: "name") { $0.name },66 GlassTableColumn("Line", id: "line") { $0.line },67 GlassTableColumn("Daily riders", id: "riders", sortingBy: { $0.dailyRiders }) { $0.dailyRiders.formatted(.number) },68 GlassTableColumn("Opened", id: "opened", sortingBy: { $0.opened }) { $0.opened.formatted(.number.grouping(.never)) },69 ]7071 @State private var sort: GlassTableSort? = GlassTableSort(columnID: "riders", order: .reverse)72 @State private var selection: Set<String> = ["s2"]73 @State private var showsEmpty = false7475 public init() {}7677 public var body: some View {78 VStack(alignment: .leading, spacing: 12) {79 Toggle("Show the empty state", isOn: $showsEmpty)80 Text("\(selection.count) selected")81 .font(.callout)82 .foregroundStyle(.secondary)83 GlassTable(showsEmpty ? [] : stations, columns: columns, sort: $sort, selection: .multiple($selection), emptyTitle: "No station")84 .frame(minHeight: 320)85 }86 .padding()87 }88}8990#Preview("GlassTable") { GlassTableExample() }91