Skip to content

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 ​

OptionTypeDescription
keystringRequired. The property of the row shown in this column.
labelstringHeader text. Defaults to the key.
sortablebooleanShows the sort arrows. See Sorting.
widthstringAny 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.
hiddenbooleanLeaves the column out of the table and the CSV export.
format(value, row, index) => string | numberReturns the text of the cell.
html(value, row, index) => stringReturns the HTML of the cell. See Custom cells.
sort(a, b) => numberComparator for client-side sorting.
classstringClass added to every cell of the column.
headerClassstringClass 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.

Released under the Apache-2.0 License.