Table

A data table; the first row is the header. It can also show a collection.

When to use it

Data with rows and columns: prices by plan, opening hours, a comparison. The first row is the header. It can also show a collection.

When not to

Page layout (use Layout mode or columns) and a few facts (use facts).

Accessibility

A real table with its header cells, so screen readers read each cell with its column. Wide tables scroll sideways on small screens.

See it live

The component library shows this component in the default theme, in every variant: open it in the component library

The table example as the component library shows it in the default theme

Where it is used

The starter sites that use it, each at a page that shows it:

Fields

What the component’s dialog asks for. In a Doc, keyed rows start with the key; rows in order follow the order below. Each row is one item, its cells in the order of the fields.

Field

Key

Kind

Required

Header row

header

Plain text, one line

No

Cell

cell

Text with headings, lists, links and bold

No

Collection (a Sheet or JSON file in the data folder)

source

A value from a short list, or a setting

No

Columns to show, in order (from a collection)

columns

A value from a short list, or a setting

No

Headings of the columns, in the same order (from a collection)

labels

A value from a short list, or a setting

No

How many

limit

A value from a short list, or a setting

No

Order

sort

A value from a short list, or a setting

No

Keep only the items whose field or column has a value, as category = Mains or start >= today

filter

A value from a short list, or a setting

No

Variants

A variant changes how the component looks. Write it in parentheses after the name in the table’s first cell, several separated by commas.

Variant

Write in the first cell

Striped rows

table (striped)

Comparison (yes and no as marks)

table (compare)

From a collection

Instead of writing its items one by one, the block can show the items of a collection: a Sheet tab or a JSON file in the content/data folder. Add these rows to the table, a name in the first cell and its value in the second:

  • source: the name of the collection, such as menu (required)
  • sort: the column to order the items by; a minus before it, such as -date, orders them backwards
  • limit: the most items to show
  • filter: keep only the items whose column has a value, such as category = Mains
  • columns: the columns to show, separated by commas, in that order
  • labels: the headings of those columns, separated by commas (a translated page writes its own)

The first row of the collection names its columns. A name that matches no collection raises the warning unknown_data_source.

Warnings it can raise

The editor and the build say these when a block of this component needs a fix. All warnings are listed in the warnings reference.

Code

What it says

unknown_data_source

No collection named "{source}" in the data folder.

In Google Docs

A component is a table. Its first cell names it; the rows below hold its fields. This is the example table: The first row of the table here only names the columns; the Doc table is the rows below it.

Column 1

Column 2

Column 3

table

Trip

Days

Level

Alps traverse

7

Hard

Coastal cycling

3

Easy

In a page file

In a site kept as a folder or in Git, the same component is a block of the page’s JSON file:

JSON
{
  "name": "table",
  "variants": [
    "striped"
  ],
  "rows": [
    [
      "Trip",
      "Days",
      "Level"
    ],
    [
      "Alps traverse",
      "7",
      "Hard"
    ],
    [
      "Coastal cycling",
      "3",
      "Easy"
    ]
  ]
}

Markup and classes

What the component writes takes these classes, for a theme’s CSS: the component’s own name, name__part for its parts and name--variant for each variant (the variant’s plain name is there too).

Class

What it marks

table

The component

table__grid

A part of it

table__mark

A part of it

table__mark--no

A part of it

table__mark--yes

A part of it

table--striped

A variant

table--compare

A variant

The HTML the example above writes, as the component library builds it in the default theme:

html
<div class="table">
<table class="table__grid">
  <thead><tr><th scope="col"><p>Trip</p></th><th scope="col"><p>Days</p></th><th scope="col"><p>Level</p></th></tr></thead>
  <tbody>
    <tr><td><p>Alps traverse</p></td><td><p>7</p></td><td><p>Hard</p></td></tr>
    <tr><td><p>Coastal cycling</p></td><td><p>3</p></td><td><p>Easy</p></td></tr>
  </tbody>
</table>
</div>

Visitor texts

Texts it shows visitors, in the page’s language. Every one is in the visitor texts reference.

Key

Text

site.table.yes

Yes

site.table.no

No

Extending it

Its files in SeedPage. A theme or a site changes the markup by giving a file of the same name (the Liquid part), and a new component can extend this one.

  • src/components/table.js
  • src/components/table/table.liquid