Soracom

Design System
  1. Home
  2. Design system
  3. Elements
  4. Datatable

Datatable

Options

Basic usage

html
Copy

Visual states

The 4x preset visual states - alert, warning, success and info, can be applied to table rows

html
Copy

Highlight

Highlight a specific row.

html
Copy

Highlight a specific row with a visual state.

html
Copy

Row striping

Row striping requires the table to have a class of --striped, and for the table rows to be contained in a <tbody> element.

html
Copy

The datatable footer element uses the html tfoot element - it’s intended to be used for permanently displayed content, for example when you need to show a button to “Add a new row”.

For temporary messages such as “No items found” see No items

Footer with inline text content

html
Copy

Footer with ds-text content

html
Copy

Footer with button element

html
Copy

No items

When a filter or the default state of a table has no rows, use a td with colspan="999" to display a temporary message.

For persistent messages such as “Add a row” see Footer

html
Copy

Headers

Multiple rows

Table headers may contain multiple rows.

html
Copy

Multiple columns

Table headers may span multiple columns using the standard colspan attribute.

html
Copy

Header column styling

html
Copy

Columns

Column alignment

Adding --center or --right to all of the th and td elements within a column will align the contents.

Due to limitations in html/css, you must apply this class to each corresponding td and th - you can’t just set the th only.

Example showing right and center alignment

html
Copy

Column styling

html
Copy

Column sorting

For column sorting, in the th use a button with ds-button --label and the recommended icon modifiers shown below.

Sorting of the column data requires additional javascript

Button styled as column label

html
Copy

Example showing the various column sorting buttons

html
Copy

Column widths

By default the columns will be sized using html tables automatic sizing. There are three options which can be applied to control this:

Min

All thead tr th with the class --min will be reduced to the minimum width based on th content (without wrapping the th), or the narrowest the columns td will allow (with wrapping), the other columns will be sized according to standard html table sizing.

html
Copy
Max

All thead tr th with the class --max will be expanded to the maximum width, while all other columns will be reduced to the minimum based on the same rules as --min.

html
Copy
First min

The contents of the first column will not wrap, and will be the minimum width of the content

html
Copy

Global width classes

ds-datatable supports global width classes.

To set the width of a column, add the width class to the appropriate thead > th.

The th content width will limit the minimum column width.
The total widths of the th elements will determine the minimum width of the table.
Some td content will limit the minimum column width (for example form elements)
-w width

Table column widths will be the set width, widths are not responsive, they will force the table to overflow if neccessary.

html
Copy
-wmin min width

Table column widths will be the minimum width or wider if space permits.

html
Copy
-wmax max width
-wmax is not supported for table column widths

Column overflow

ds-datatable supports global --overflow classes.

Set the width of each columns td using the global size classes and the --overflow class.

--overflow will limit the content to a single line, and display an ellipsis if the content is wider than the column.
--overflow should be limited to cells with text-like content only.
html
Copy

Row spacing

Compact

html
Copy

Condensed

Condensed spacing should only be used in limited scenarios, it is preferable to use the default spacing or compact.

html
Copy

Loading state

A datatable can be triggered to display a loading state - where the datatable contents are hidden, and the replaced by a centered spinning loading icon – without affecting the dimensions of the datatable.

Additional options are available using Message state

Default

html
Copy

Alternative loading-refresh icon

html
Copy

Custom icon by adding any icon class

html
Copy

Message state

Message state extends and can be used with Loading state. If a datatable has a data-attribute data-ds-message the datatable contents are hidden, and replaced by an icon and the text of the data-ds-message.

html
Copy

Loading state with a message

html
Copy

You can set a custom icon

html
Copy

You can set a custom icon, with the loading state animation

html
Copy

Sticky

The table header thead can be made sticky by adding the class --sticky. The effect is only apparent if the parent container (containing the ds-datatable element) has a set height, with the contents set to overflow.

The ds-datatable in the example below has a parent element with --20-h to limit the height of the container forcing the contents to overflow and scroll. Read more about the Sizing classes.

Datatable with a sticky header and its parent container set to 200px in height

html
Copy

First column

The first column can be made sticky by adding the class --pin-first to the ds-datatable. The effect is only apparent if the datatable is wider than it’s parent container.

Datatable with a sticky header and its parent container set to 200px in height

html
Copy

Responsive support

To enable support for responsive datatables on mobile devices, add:

  • An empty data-label attribute to the thead element to trigger hiding the standard column headers. This will be used in future to allow setting of a mobile specific header.

  • An empty data-label attribute to each tr inside the tbody element, this will trigger responsive columns layout. This will be used in future to allow setting of a mobile specific per-row headings.

  • A data-label attribute to each td with the title of the appropriate column.

Resize the example below to see responsive support

html
Copy

Styles

Custom styles exist for specific use cases.

Embedded style

This style includes a border around the datatable, row striping and drop-shadow on the header and is useful when a datatable is displayed inline next to other field elements.

html
Copy

Plain

html
Copy

Spreadsheet

html
Copy

Tests

Mixed form content

Mixed text/image content

Mixed content with default display

html
Copy

Mixed content with condensed display

html
Copy

Text only content

Text only content with default display

html
Copy

Text only content with condensed display

html
Copy

Mixed content with buttons in different visual states

html
Copy

Highlight row in embedded datatable

html
Copy

Embedded style with responsive support

html
Copy

Multiple highlighted rows

html
Copy

Embedded style multiple highlighted rows

html
Copy

Multiple row header, colspan, sticky header

html
Copy

Manifest

The component manifest describes this component's API — its modifiers, structure, data attributes, CSS custom properties, accessibility notes, and example markup. It is consumed by tooling such as AI assistants and code generators.

Latest version: https://assets.soracom.io/sds/latest/ds-datatable/index.mjs

index.mjs
Copy