Table ​
WARNING
This component is still under development. It is not yet available in releases of Codex.
Demos ​
Default ​
Column 1 | Column 2 | Column 3 |
---|---|---|
One | Two | Three |
1 | 2 | 3 |
Four | Five | Six |
4 | 5 | 6 |
Name | Value |
---|---|
View | |
Reading direction |
Exploring content and width options ​
With set column widths ​
In this demo, the second column is set to be wider than the first and third columns. You can set column widths to a percentage or specific value if table-layout: fixed
is used.
This is done via CSS in the parent component here. However, we might consider building this into the columns
prop for additional ease.
Column 1 | Column 2 | Column 3 |
---|---|---|
One | Two | Three |
1 | 2 | 3 |
Four | Five | Six |
4 | 5 | 6 |
Name | Value |
---|---|
View | |
Reading direction |
With varied content length ​
In this table, the third column's content is much longer than the other two. The column widths are naturally set accordingly. However, when you look at the table on a mobile device, the third column will be uncomfortably narrow. This could be fixed by adding a min width
as demonstrated below.
User | IP(s) | User Agent(s) |
---|---|---|
Abc | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
Twoword Username | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
Shortish | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
123.45.6.789 | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
Short | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
PascalCase | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
Name | Value |
---|---|
View | |
Reading direction |
With many columns ​
This table has a lot of columns, including two with long content. Horizontal scrolling occurs since the natural state of this table is wider than the container.
User | IP(s) | User Agent(s) | User 2 | IP(s) 2 | User Agent(s) 2 |
---|---|---|---|---|---|
Abc | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] | Abc | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
Twoword Username | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] | Twoword Username | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
Shortish | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] | Shortish | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
123.45.6.789 | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] | 123.45.6.789 | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
Short | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] | Short | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
PascalCase | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] | PascalCase | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
Name | Value |
---|---|
View | |
Reading direction |
With many columns and column min-widths ​
This is the same table as above, but a min-width
is set on the two columns with longer content to make it more readable.
User | IP(s) | User Agent(s) | User 2 | IP(s) 2 | User Agent(s) 2 |
---|---|---|---|---|---|
Abc | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] | Abc | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
Twoword Username | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] | Twoword Username | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
Shortish | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] | Shortish | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
123.45.6.789 | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] | 123.45.6.789 | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
Short | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] | Short | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
PascalCase | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] | PascalCase | 123.45.6.789 | Mozilla/5.0 (Windows NT 10.0; Win64, x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 [10] |
Name | Value |
---|---|
View | |
Reading direction |
Customizing content with slots ​
Customizing cells ​
You can customize cell content by using dynamically generated slots for each column. The name of a column's slot follows the format item-[COLUMN_ID]
. For example, in the table below, the slot to customize the "Name" column, which has an id of name
, is item-name
. You can put markup or even components inside these slots.
Name | Status | Language |
---|---|---|
JavaScript modulo 2 | Connected | javascript |
Composite modulo 2 | Connected | Composition |
number is even, python | Disconnected | python |
Name | Value |
---|---|
View | |
Reading direction |
Customizing the table body ​
Instead of passing table data in via the data
prop, you can use the default slot of the Table component to customize the table body, while continuing to use the columns
prop to pass in column information. This is useful when you want custom formatting or structure in the table body, but still want to take advantage of features built into the Table component's header, like sorting.
Column 1 | Column 2 | Column 3 |
---|---|---|
First section | ||
One | Two | Three |
1 | 2 | 3 |
Second section | ||
Four | Five | Six |
4 | 5 | 6 |
Name | Value |
---|---|
View | |
Reading direction |
Customizing all table content ​
Instead of passing data and column information in via props, you can use the default slot of the Table component to build your own table structure with all valid table elements. This can be useful for customizing table structure, like adding cells that span multiple rows or columns.
Season/series | Doctor | Episodes | Originally aired | Average viewers (millions) | |
---|---|---|---|---|---|
First aired | Last aired | ||||
Classic era | |||||
Season 1 | First Doctor | 42 | 23 November 1963 | 12 September 1964 | 8.08 |
Season 2 | 39 | 31 October 1964 | 24 July 1965 | 10.46 | |
Season 3 | 45 | 11 September 1965 | 16 July 1966 | 7.65 | |
Season 4 | Second Doctor | 43 | 10 September 1966 | 1 July 1967 | 7.1 |
Season 5 | 40 | 2 September 1967 | 1 June 1968 | 7.23 | |
Season 6 | 45 | 10 August 1968 | 21 June 1969 | 6.38 |
Name | Value |
---|---|
View | |
Reading direction |
Vue usage ​
Props ​
Prop name | Description | Type | Default |
---|---|---|---|
caption (required) | Table caption. TODO: add prop to make this visually-hidden | string | |
columns | TableColumn[] | () => { return []; } | |
data | array | [] |
Slots ​
Name | Description | Bindings |
---|---|---|
'item-' + columnId | Table cell content, per column. | item mixed - Data for the cell |
default | Custom thead, tbody, and tfoot. |