-
Notifications
You must be signed in to change notification settings - Fork 1
/
table.templ
63 lines (55 loc) · 991 Bytes
/
table.templ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package templdais
type TableAttrs struct {
TableName string
Columns []string
PrimaryKey string
Rows []map[string]string
Zebra bool
PinColumns bool
PinRows bool
Size string
Class string
}
func (t TableAttrs) GetTableClass() string {
var class = "table"
if t.Size != "" {
class += " " + t.Size
}
if t.Zebra {
class += " table-zebra"
}
if t.PinColumns {
class += " table-pin-columns"
}
if t.PinRows {
class += " table-pin-rows"
}
if t.Class != "" {
class += " " + t.Class
}
return trimSpaces(class)
}
templ Table(tb TableAttrs) {
<div class="overflow-x-auto">
<table class={ tb.GetTableClass() }>
<!-- head -->
<thead>
<tr>
for _, col := range tb.Columns {
<th>{ col }</th>
}
</tr>
</thead>
<tbody>
<!-- rows -->
for _, row := range tb.Rows {
<tr>
for _, col := range tb.Columns {
<td>{ row[col] }</td>
}
</tr>
}
</tbody>
</table>
</div>
}