Composables
useTableRows
Search, filter, sort and cut records into pages, for a table or any other list.
Usage
useTableRows is the engine of the Table. Use it on its own to give the same search, filters, sort and pages to another layout, like a grid of cards.
<script setup lang="ts">
import { defineTableColumns, type TableSort, useTableRows } from '@kuina-ui/vue'
import { ref } from 'vue'
interface Transaction {
id: string
merchant: string
date: string
amount: number
}
const transactions: Transaction[] = [
{ id: 'txn-1048', merchant: 'Corner Coffee', date: '2026-11-24', amount: -6.75 },
{ id: 'txn-1047', merchant: 'Acme Corp', date: '2026-11-21', amount: 4850 },
{ id: 'txn-1046', merchant: 'Streamly', date: '2026-11-19', amount: -11.99 },
{ id: 'txn-1045', merchant: 'Skyway Airlines', date: '2026-11-16', amount: -428.4 },
]
const transactionColumns = defineTableColumns<Transaction>([
{ key: 'merchant' },
{ key: 'date', type: 'date' },
{ key: 'amount', type: 'decimal', formatOptions: { style: 'currency', currency: 'USD' } },
])
const searchQuery = ref('')
const sort = ref<TableSort>([{ key: 'date', direction: 'descending' }])
const page = ref(1)
const { visibleRows, matchingRowCount, pageCount } = useTableRows(transactions, {
columns: transactionColumns,
searchQuery,
sort,
page,
rowsPerPage: 12,
})
</script>
<template>
<KInput v-model="searchQuery" type="search" aria-label="Search transactions" />
<div class="grid grid-cols-3 gap-4">
<article v-for="transaction in visibleRows" :key="transaction.id" class="rounded-xl border border-line p-4">
<h3 class="font-medium">{{ transaction.merchant }}</h3>
<p class="text-muted">{{ transaction.date }}</p>
<p class="tabular-nums">{{ transaction.amount }}</p>
</article>
</div>
<p>{{ matchingRowCount }} transactions, page {{ page }} of {{ pageCount }}</p>
<KPagination v-model:page="page" :page-count="pageCount" :rows-per-page-options="[]" />
</template>
Every option takes a value, a ref or a getter. The columns say how to read, search, format and compare each field, exactly like the columns of the table; without them, they are built from the first record.
Given as a ref, the page goes back to 1 when the search, a filter or the sort changes, and moves back when the page no longer exists.
With the Nuxt module, useTableRows and defineTableColumns are auto-imported. In a Vue app, import them from @kuina-ui/vue.
API
useTableRows(rows, options?)
Options
| Option | Type |
|---|---|
columns | TableColumn<Row>[] |
columnTypes | Record<string, TableColumnType> |
locale | string |
searchQuery | string |
searchMatcher | (row, searchQuery) => boolean |
columnFilters | Record<string, unknown> |
sort | { key, direction }[] |
page | number, or a ref to keep in range |
rowsPerPage | number |
serverSide | boolean, to leave the records as they come |
rowKey | keyof Row | (row) => string | number, 'id' by default, to find the pinned rows |
pinnedRows | (string | number)[], the keys of the records to keep first, whatever the sort |
childrenKey | string, to keep a record when one of its children matches |
Returned values
| Value | Type | |
|---|---|---|
visibleRows | ComputedRef<Row[]> | The records of the current page. |
matchingRows | ComputedRef<Row[]> | Every record that matches the search and the filters. |
sortedRows | ComputedRef<Row[]> | The matching records, sorted. |
matchingRowCount | ComputedRef<number> | |
pageCount | ComputedRef<number> | At least 1. |
resolvedColumns | ComputedRef<TableColumn<Row>[]> | The given columns, or the built ones. |