Components Data display

Table

Display tabular records with a caption and column headers.

Live previewGo + HTML
Edition inventory
EditionFormatCopies
CoastlineFolio120
Night shiftPocket75
Open studioTabloid240

Usage

Give Caption a descriptive title. Headers is an ordered list of column names. Populate Rows with the same number of cell values as there are headers.

Register table with Head and pass its properties to Render. Go setup guide

Go usage
Go usage
err := mono.UI.Render(w, "table", mono.Props{
	"Caption": "Edition inventory",
	"Headers": []any{
		"Edition",
		"Format",
		"Copies",
	},
	"Rows": []any{
		[]any{
			"Coastline",
			"Folio",
			"120",
		},
		[]any{
			"Night shift",
			"Pocket",
			"75",
		},
		[]any{
			"Open studio",
			"Tabloid",
			"240",
		},
	},
})
Rendered HTML
Rendered HTML
<div data-mono="table" id="demo-table">
  <div class="mu-table-viewport" role="region" aria-label="Edition inventory" tabindex="0"><table>
    <caption>Edition inventory</caption>
    <thead><tr><th scope="col">Edition</th><th scope="col">Format</th><th scope="col">Copies</th></tr></thead>
    <tbody><tr><td>Coastline</td><td>Folio</td><td>120</td></tr><tr><td>Night shift</td><td>Pocket</td><td>75</td></tr><tr><td>Open studio</td><td>Tabloid</td><td>240</td></tr></tbody>
  </table></div>
</div>
Go template
Go template
<div data-mono="table" id="{{.ID}}">
  <div class="mu-table-viewport" role="region" aria-label="{{.Caption}}" tabindex="0"><table>
    <caption>{{.Caption}}</caption>
    <thead><tr>{{range .Headers}}<th scope="col">{{.}}</th>{{end}}</tr></thead>
    <tbody>{{range .Rows}}<tr>{{range .}}<td>{{.}}</td>{{end}}</tr>{{end}}</tbody>
  </table></div>
</div>
Component CSS
Component CSS
[data-mono="table"] .mu-table-viewport { overflow-x:auto; }
[data-mono="table"] table { width:100%; border-collapse:collapse; text-align:start; font-size:.9rem; }
[data-mono="table"] caption { padding:0 0 .6rem; text-align:start; font-weight:650; }
[data-mono="table"] :is(th,td) { padding:.6rem .75rem; text-align:start; border-bottom:1px solid #d7d7d7; }
[data-mono="table"] thead th { background:#f1f1f1; color:#252525; }
Use the HTML in a static site

Copy the rendered HTML above. Download these assets into the same folder as your page, then add the tags below to its head.

Shared CSS Component CSS

HTML head
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./table.css">

Copy into your project

Run this command from the Mono checkout. Set -out to the component directory in your application.

Terminal
go run ./cmd/mono-ui add -out ./components table
Example properties (JSON)
example.json
{
  "Caption": "Edition inventory",
  "Headers": [
    "Edition",
    "Format",
    "Copies"
  ],
  "Rows": [
    [
      "Coastline",
      "Folio",
      "120"
    ],
    [
      "Night shift",
      "Pocket",
      "75"
    ],
    [
      "Open studio",
      "Tabloid",
      "240"
    ]
  ]
}