SP GlassKit1.1.0

GlassTable

System Table where available and a List elsewhere, with typed sorting and selection.

  • System control
  • iOS 26 · iPadOS 26 · macOS 26
  • Version 1.1.0
  • glass-table

Drawn by the system. GlassKit configures it and leaves the glass to the system.

GlassTable running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-table

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-table
ModuleSPGlassData
Kindnative-wrapper — the system Table on macOS and regular-width iPad, a system List in compact width
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Data/GlassTableExample.swift

Minimal usage

Swift
GlassTable(cities, columns: [
    GlassTableColumn("Name", id: "name") { $0.name },
    GlassTableColumn("Population", id: "population", sortingBy: { $0.population }) {
        $0.population.formatted(.number)
    },
])

Rows are any Identifiable values. The table never modifies the host's collection: it sorts a copy for display.

Variants

VariantUse
Native tablemacOS, and iPad or iPhone in regular width. Sortable headers, system selection.
Compact listiPhone and narrow iPad windows. The first column is the row's main text, the other columns are labelled values, and a "Sort by" menu in the section header replaces the headers.
selection: .noneRows are not selectable (default).
selection: .single($id)At most one row. In the list form, tapping the selected row clears it.
selection: .multiple($ids)Any number of rows.

Columns are values:

InitialiserSorting
GlassTableColumn(title, id:, text:)By the displayed text, with localizedStandardCompare (case-insensitive, numbers by value).
GlassTableColumn(title, id:, sortingBy:, text:)By a typed Comparable value (number, date), while displaying formatted text.
GlassTableColumn(title, id:, text:, comparator:)By a custom comparison returning ComparisonResult.

Parameters

ParameterTypeDefaultMeaning
rowsSequence of Identifiable—The rows, in the host's order.
columns[GlassTableColumn<Row>]—Columns, leading to trailing.
sortBinding<GlassTableSort?>.constant(nil)Sorted column and direction; nil keeps the host's order.
selectionGlassTableSelection<Row.ID>.noneSelection mode and binding.
emptyTitleLocalizedStringKey?nilText of the empty state; defaults to the localised "No data".

GlassTableColumn.title is a LocalizedStringResource, looked up in the host application's strings.

Column options and the compact table

ModifierMeaning
column.aligned(.trailing)Trailing alignment and tabular digits, for numbers.
column.badged { row in tone }Draws the cell's text as a soft GlassBadge of the returned tone; nil keeps plain text.

In compact width, a table of up to four columns is drawn as a dense table on an opaque surface: uppercase sortable headers with a direction chevron, hairlines, the first column emphasised, and a selected row marked by an accent edge, a tint and a checkmark. A short table takes its own height; a long one scrolls and stays lazy. With more than four columns, or at accessibility text sizes, each row becomes a stack of labelled values in a List, as before. GlassTableLogic.usesDenseCompactForm(columnCount:isAccessibilitySize:) and columnWeights(count:) are pure and public.

States

  • Empty: a ContentUnavailableView with emptyTitle.
  • Sorted: the header shows the system sort indicator; in the list form the menu shows the sorted column with a chevron and exposes "Sorted ascending / descending" as its accessibility value.
  • Selected: system highlight in the table; a checkmark and the .isSelected trait in the list.
  • Pressed, focused and disabled (.disabled(_:)) are drawn by the system.

Advanced example

Swift
struct Invoice: Identifiable { let id: UUID; let client: String; let due: Date; let amount: Decimal }

@State private var sort: GlassTableSort? = GlassTableSort(columnID: "due")
@State private var selected: Invoice.ID?

GlassTable(invoices, columns: [
    GlassTableColumn("Client", id: "client") { $0.client },
    GlassTableColumn("Due", id: "due", sortingBy: { $0.due }) { $0.due.formatted(date: .abbreviated, time: .omitted) },
    GlassTableColumn("Amount", id: "amount", sortingBy: { $0.amount }) { $0.amount.formatted(.currency(code: "CAD")) },
], sort: $sort, selection: .single($selected), emptyTitle: "No invoice")

// The same pure function is available to sort data elsewhere (export, tests):
let ordered = GlassTableLogic.sorted(invoices, by: sort, columns: columns)

Accessibility

  • The native table keeps the system's table semantics, keyboard navigation and VoiceOver column reading.
  • In the list form each row is one element combining the main text and the labelled values; selection is exposed by the .isSelected trait and a checkmark, not by colour.
  • The sort direction is given by a symbol and by text ("Sorted ascending").
  • Text follows Dynamic Type; values are formatted by the host with FormatStyle.

Limits

  • Cells are text. A table with custom cell views should use the system Table directly.
  • One sort key at a time: the system table's secondary sort keys are not exposed. The sort is stable, so sorting successively by two columns gives a two-level order.
  • Rows are sorted in body on every update (O(n log n)); for very large collections sort in the model and pass sort: .constant(nil).
  • The system Table shows only its first column in compact width, which is why GlassTable switches to a list there. The switch follows horizontalSizeClass and was compiled for iOS but not exercised on a device in this phase.
  • Column widths are left to the system.

Example

Complete example (compiled with the package)
import SwiftUI
import SPGlassKit

public struct GlassTableExample: GlassExample {
    public static let componentID = "glass-table"

    struct Station: Identifiable {
        let id: String
        let name: String
        let line: String
        let dailyRiders: Int
        let opened: Int
    }

    // Fictitious data.
    private let stations = [
        Station(id: "s1", name: "Harbour Square", line: "Blue", dailyRiders: 48_200, opened: 1987),
        Station(id: "s2", name: "Élan–Université", line: "Green", dailyRiders: 31_750, opened: 2004),
        Station(id: "s3", name: "North Mills", line: "Blue", dailyRiders: 9_640, opened: 1991),
        Station(id: "s4", name: "Parc des Érables", line: "Orange", dailyRiders: 22_310, opened: 2016),
        Station(id: "s5", name: "Old Foundry", line: "Green", dailyRiders: 9_640, opened: 1979),
    ]

    private let columns: [GlassTableColumn<Station>] = [
        GlassTableColumn("Station", id: "name") { $0.name },
        GlassTableColumn("Line", id: "line") { $0.line }
            .badged { _ in .neutral },
        GlassTableColumn("Daily riders", id: "riders", sortingBy: { $0.dailyRiders }) { $0.dailyRiders.formatted(.number) }
            .aligned(.trailing),
        GlassTableColumn("Opened", id: "opened", sortingBy: { $0.opened }) { $0.opened.formatted(.number.grouping(.never)) }
            .aligned(.trailing),
    ]

    @State private var sort: GlassTableSort? = GlassTableSort(columnID: "riders", order: .reverse)
    @State private var selection: Set<String> = ["s2"]
    @State private var showsEmpty = false

    public init() {}

    public var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            Toggle("Show the empty state", isOn: $showsEmpty)
            Text("\(selection.count) selected")
                .font(.callout)
                .foregroundStyle(.secondary)
            GlassTable(showsEmpty ? [] : stations, columns: columns, sort: $sort, selection: .multiple($selection), emptyTitle: "No station")
                .frame(minHeight: 320)
        }
        .padding()
    }
}

#Preview("GlassTable") { GlassTableExample() }

Registry entry

Identifierglass-table
Version1.1.0
Depends onglass-badge, glass-components-support, glass-foundation
FrameworksSwiftUI
Public symbolsGlassTable, GlassTableColumnAlignment, GlassTableColumn, GlassTableSort, GlassTableSelection, GlassTableLogic
LicenceMIT
Manifestmanifest.json

Files