| 200px | 1fr | cell 2 | cell 3 |
|---|
Appearance
Appearance
import Table from '@ui/Table.vue'Arrange cells in a grid.
For every row, add exactly one element per column.
Design [Penpot]Prop grid-template-columns: An array of the column widths. You can make a column either fixed-width or use part of the available space:
100px: Exactly this widthauto: The the widest cell in the column1fr: A certain fraction of the remaining spaceThe whole table always has a width of 100% (or stretch, if inside a flex or grid context). If the minimum sizes don't fit, all cells will shrink proportionally.
<Table :grid-template-columns="['100px', 'auto', '2fr', '1fr']">
<b>100px</b>
<b>auto</b>
<b>2fr</b>
<b>1fr</b>
</Table>Use the #header slot to add items to the header. Make sure to add one item per column.
<Table :grid-template-columns="['3fr', '1fr']">
<template #header>
<label >Column 1</label>
<label >Column 2</label>
</template>
<label>A</label>
<label>B</label>
</Table>style=grid-row: span 3. In this case, you have to remove the corresponding cells directly below.<Table :grid-template-columns="['48px', '48px', 'auto', 'auto', 'auto', '48px', '64px', '48px']">
<template #header>
<label></label>
<label></label>
<label>Title</label>
<label>Album</label>
<label>Artist</label>
<label></label>
<label>⏱</label>
<label></label>
</template>
<!-- Row 1 -->
<div> </div>
<div>C1</div>
<div>Title 1</div>
<div></div>
<div>Artist 1</div>
<div></div>
<div>D1</div>
<div>⌄</div>
<!-- Row 2 -->
<div>B2</div>
<div>C2</div>
<div>Title 2</div>
<div style="grid-row: span 2; height: auto; background: blue;">Album 2</div>
<div>Artist 2</div>
<div>F2</div>
<div>D2</div>
<div>⌄</div>
<!-- Row 3 -->
<div>B3</div>
<div>C3</div>
<div>Title 3</div>
<div>Artist 3</div>
<div>F3</div>
<div>D3</div>
<div>⌄</div>
<!-- Row 4 -->
<div>B4</div>
<div>C4</div>
<div>Title 4</div>
<div></div>
<div></div>
<div>F4</div>
<div>D4</div>
<div>⌄</div>
</Table>To add class names and other properties to the table header, set the header-props prop. In the following example, the whole header section is made inert.
Note that style properties may not have an effect because the header section is display: contents. Instead, add a custom attribute and add scoped style rule targeting your attribute.
<Table
:grid-template-columns="['1fr', '1fr']"
:header-props="{ inert: '' }"
>
<template #header>
<label>
<Button low-height primary @click="console.log('clicked 1')">1</Button>
</label>
<label>
<Button low-height primary @click="console.log('clicked 2')">2</Button>
</label>
</template>
</Table>Using this component
Note that the current implementation does not use the semantic HTML5 element <table> by default. You may want to use semantic elements for the table slots to ensure screen readers and other assistive technology recognizes it as a table.
| 200px | 1fr | cell 2 | cell 3 |
|---|
<Table
is-table
:grid-template-columns="['200px', '1fr', 'auto']"
>
<th>200px</th>
<th>1fr</th>
<th><Button>th</Button></th>
<td><Button>cell 1</Button></td>
<td>cell 2</td>
<td>cell 3</td>
<td><Button>cell 4</Button></td>
<td><Button>cell 5</Button></td>
<td><Button>cell 6</Button></td>
</Table>