Columns
The columns prop describes the table one column at a time.
vue
<template>
<VTable :columns="columns" :data="products" clientSide :itemsPerPage="5" />
</template>
<script setup lang="ts">
import { VTable, type Column } from "v-table-system";
import { products } from "./data";
const columns: Column[] = [
{ key: "id", label: "#", width: "60px", align: "center" },
{ key: "name", label: "Product" },
{ key: "price", label: "Price", align: "right", format: (value) => `$${value.toFixed(2)}` },
{ key: "stock", label: "In stock", align: "right", format: (value) => (value ? value : "Sold out") },
// Hidden columns are not rendered and not exported
{ key: "category", label: "Category", hidden: true },
];
</script>Column options
| Option | Type | Description |
|---|---|---|
key | string | Required. The property of the row shown in this column. |
label | string | Header text. Defaults to the key. |
sortable | boolean | Shows the sort arrows. See Sorting. |
width | string | Any CSS width, such as "120px" or "20%". Columns share the width equally by default. |
align | "left" | "center" | "right" | Alignment of the header and the cells. |
hidden | boolean | Leaves the column out of the table and the CSV export. |
format | (value, row, index) => string | number | Returns the text of the cell. |
html | (value, row, index) => string | Returns the HTML of the cell. See Custom cells. |
sort | (a, b) => number | Comparator for client-side sorting. |
class | string | Class added to every cell of the column. |
headerClass | string | Class added to the header cell. |
The short form: labels
For a quick table you can pass labels instead of columns. Each label is matched to the row property with the same name. If there is none, labels are matched to the row properties by position.
vue
<template>
<VTable :labels="['name', 'category', 'price']" :data="products" />
</template>labels cannot format, align or hide a column. Use columns for that. When both are set, columns wins.