1+ package main
2+
3+ import (
4+ "fmt"
5+
6+ "github.com/wavetermdev/waveterm/tsunami/app"
7+ "github.com/wavetermdev/waveterm/tsunami/ui"
8+ "github.com/wavetermdev/waveterm/tsunami/vdom"
9+ )
10+
11+ // Sample data structure for the table
12+ type Person struct {
13+ Name string `json:"name"`
14+ Age int `json:"age"`
15+ Email string `json:"email"`
16+ City string `json:"city"`
17+ }
18+
19+ // Create the table component for Person data
20+ var PersonTable = ui.MakeTableComponent [Person ]("PersonTable" )
21+
22+ // Sample data
23+ var sampleData = []Person {
24+ {Name : "Alice Johnson" , Age : 28 , Email : "alice@example.com" , City : "New York" },
25+ {Name : "Bob Smith" , Age : 34 , Email : "bob@example.com" , City : "Los Angeles" },
26+ {Name : "Carol Davis" , Age : 22 , Email : "carol@example.com" , City : "Chicago" },
27+ {Name : "David Wilson" , Age : 41 , Email : "david@example.com" , City : "Houston" },
28+ {Name : "Eve Brown" , Age : 29 , Email : "eve@example.com" , City : "Phoenix" },
29+ {Name : "Frank Miller" , Age : 37 , Email : "frank@example.com" , City : "Philadelphia" },
30+ {Name : "Grace Lee" , Age : 25 , Email : "grace@example.com" , City : "San Antonio" },
31+ {Name : "Henry Taylor" , Age : 33 , Email : "henry@example.com" , City : "San Diego" },
32+ {Name : "Ivy Chen" , Age : 26 , Email : "ivy@example.com" , City : "Dallas" },
33+ {Name : "Jack Anderson" , Age : 31 , Email : "jack@example.com" , City : "San Jose" },
34+ }
35+
36+ // The App component is the required entry point for every Tsunami application
37+ var App = app .DefineComponent ("App" , func (_ struct {}) any {
38+ app .UseSetAppTitle ("Table Test Demo" )
39+
40+ // Define table columns
41+ columns := []ui.TableColumn [Person ]{
42+ {
43+ AccessorKey : "Name" ,
44+ Header : "Full Name" ,
45+ Sortable : true ,
46+ Width : "200px" ,
47+ },
48+ {
49+ AccessorKey : "Age" ,
50+ Header : "Age" ,
51+ Sortable : true ,
52+ Width : "80px" ,
53+ },
54+ {
55+ AccessorKey : "Email" ,
56+ Header : "Email Address" ,
57+ Sortable : true ,
58+ Width : "250px" ,
59+ },
60+ {
61+ AccessorKey : "City" ,
62+ Header : "City" ,
63+ Sortable : true ,
64+ Width : "150px" ,
65+ },
66+ }
67+
68+ // Handle row clicks
69+ handleRowClick := func (person Person , idx int ) {
70+ fmt .Printf ("Clicked on row %d: %s from %s\n " , idx , person .Name , person .City )
71+ }
72+
73+ // Handle sorting
74+ handleSort := func (column string , direction string ) {
75+ fmt .Printf ("Sorting by %s in %s order\n " , column , direction )
76+ }
77+
78+ return vdom .H ("div" , map [string ]any {
79+ "className" : "max-w-6xl mx-auto p-6 space-y-6" ,
80+ },
81+ vdom .H ("div" , map [string ]any {
82+ "className" : "text-center" ,
83+ },
84+ vdom .H ("h1" , map [string ]any {
85+ "className" : "text-3xl font-bold text-white mb-2" ,
86+ }, "Table Component Demo" ),
87+ vdom .H ("p" , map [string ]any {
88+ "className" : "text-gray-300" ,
89+ }, "Testing the Tsunami table component with sample data" ),
90+ ),
91+
92+ vdom .H ("div" , map [string ]any {
93+ "className" : "bg-gray-800 p-4 rounded-lg" ,
94+ },
95+ PersonTable (ui.TableProps [Person ]{
96+ Data : sampleData ,
97+ Columns : columns ,
98+ OnRowClick : handleRowClick ,
99+ OnSort : handleSort ,
100+ DefaultSort : "Name" ,
101+ Selectable : true ,
102+ Pagination : & ui.PaginationConfig {
103+ PageSize : 5 ,
104+ CurrentPage : 0 ,
105+ ShowSizes : []int {5 , 10 , 25 },
106+ },
107+ }),
108+ ),
109+
110+ vdom .H ("div" , map [string ]any {
111+ "className" : "text-center text-gray-400 text-sm" ,
112+ }, "Click on rows to see interactions. Try sorting by clicking column headers." ),
113+ )
114+ })
0 commit comments