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

OptionType
columnsTableColumn<Row>[]
columnTypesRecord<string, TableColumnType>
localestring
searchQuerystring
searchMatcher(row, searchQuery) => boolean
columnFiltersRecord<string, unknown>
sort{ key, direction }[]
pagenumber, or a ref to keep in range
rowsPerPagenumber
serverSideboolean, to leave the records as they come
rowKeykeyof 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
childrenKeystring, to keep a record when one of its children matches

Returned values

ValueType
visibleRowsComputedRef<Row[]>The records of the current page.
matchingRowsComputedRef<Row[]>Every record that matches the search and the filters.
sortedRowsComputedRef<Row[]>The matching records, sorted.
matchingRowCountComputedRef<number>
pageCountComputedRef<number>At least 1.
resolvedColumnsComputedRef<TableColumn<Row>[]>The given columns, or the built ones.
Copyright © 2026