MigsLab UIVue 3 component workshop

Components

Table

A styled native table. You write the <th>, <tr> and <td> cells; the table handles borders, striping, hover, a sticky header and row selection.

import { TableComponent, TableHeaderComponent, TableBodyComponent, TableRowComponent, TableFooterComponent } from '@/MigsLab/shared'

Example

Border
NameAgeCity
Alice30New York
Bob25Los Angeles
Charlie35Chicago
Diana28San Francisco
Ethan41Seattle
Fiona33Austin
George29Boston
Total: 7 entries
<TableComponent border-type="rows" alternate-row-color outer-border hoverable sticky-header max-height="14rem">
  <template #header>
    <TableHeaderComponent>
      <th>Name</th>
      <th>Age</th>
    </TableHeaderComponent>
  </template>

  <template #body>
    <TableBodyComponent>
      <tr v-for="person in people" :key="person.id">
        <td>{{ person.name }}</td>
        <td>{{ person.age }}</td>
      </tr>
    </TableBodyComponent>
  </template>

  <template #footer>
    <TableFooterComponent>
      <td colspan="2">Total: {{ people.length }}</td>
    </TableFooterComponent>
  </template>
</TableComponent>

Row selection

Use TableRowComponent with a unique value for each row. selectable lets users click rows; show-checkbox also adds a checkbox column with select-all in the header. Selected rows turn a darker gray (--ml-selected).

NameAgeCity
Alice30New York
Bob25Los Angeles
Charlie35Chicago
Diana28San Francisco
Ethan41Seattle
Fiona33Austin
George29Boston
Selected ids: 2
const selectedIds = ref<OptionValue[]>([])

<TableComponent v-model:selected="selectedIds" selectable show-checkbox>
  <template #header>
    <TableHeaderComponent>
      <th>Name</th>
    </TableHeaderComponent>
  </template>

  <template #body>
    <TableBodyComponent>
      <TableRowComponent v-for="person in people" :key="person.id" :value="person.id">
        <td>{{ person.name }}</td>
      </TableRowComponent>
    </TableBodyComponent>
  </template>
</TableComponent>

API

TableComponent props

NameType Default Description
borderType'rows' | 'all' | 'columns' | 'none''rows'Which cell borders to draw.
alternateRowColorbooleanfalseStripe every other body row.
outerBorderbooleanfalseBorder around the whole table.
hoverablebooleanfalseHighlight body rows on hover.
stickyHeaderbooleanfalseKeep header cells visible while scrolling.
maxHeightstringundefinedMaximum height; the table scrolls inside it.
v-model:selected(string | number)[][]Values of the selected rows.
selectablebooleanfalseClicking a TableRowComponent toggles its selection.
showCheckboxbooleanfalseAdds a checkbox column (and select-all when multiple). Implies selectable.
multiplebooleantrueAllow more than one selected row.

TableRowComponent props

NameType Default Description
valuestring | numberundefinedUnique row value used for selection. Rows without a value cannot be selected.

Slots

NameDescription
headerTableHeaderComponent with <th> cells.
bodyTableBodyComponent with <tr> rows.
defaultAlternative to the body slot.
footerTableFooterComponent with <td> cells.