QTable slots let you replace any part of a Quasar table, from one cell to the whole row, while QTable keeps doing the sorting, filtering and pagination. The trick is picking the smallest slot that does the job. This post builds one projects table and uses a different slot for each piece: a progress bar cell, a row actions menu, a header with a tooltip, a column picker, expandable rows, a totals row and an empty state. Everything is checked against Quasar 2.35.2.
The column definitions behind it (field, format, align, autoWidth) are covered in Quasar QTable columns. Here we stay on the template side.
| Area | Slots |
|---|---|
| Above the table | top, top-left, top-right, top-selection |
| Header | header, header-cell, header-cell-[name], header-selection |
| Body | body, body-cell, body-cell-[name], body-expand, body-selection |
| Extra rows | top-row, bottom-row, footer |
| Below the table | bottom, pagination, no-data |
| Other | item (grid mode), loading |
The rule of thumb: body-cell-[name] over body-cell over body, and the same for the header. The narrower the slot, the more QTable still does for you.
import type { QTableColumn } from 'quasar'
interface Project {
id: number
name: string
owner: string
budget: number
spent: number
tasks: string[]
}
const money = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 })
const columns: QTableColumn<Project>[] = [
{ name: 'expand', label: '', autoWidth: true, required: true },
{ name: 'name', label: 'Project', field: 'name', align: 'left', sortable: true, required: true },
{ name: 'owner', label: 'Owner', field: 'owner', align: 'left', sortable: true },
{ name: 'budget', label: 'Budget', field: 'budget', sortable: true, format: (val: number) => money.format(val) },
{
name: 'usage',
label: 'Used',
field: row => row.spent / row.budget,
sortable: true,
format: (val: number) => `${Math.round(val * 100)}%`,
},
{ name: 'actions', label: '', align: 'right', autoWidth: true, required: true },
]Two columns, expand and actions, have no field. They exist only to give a slot a place to render, and QTable skips them when sorting and filtering.
body-cell-[name] replaces the cells of one column. Its scope has row (the raw row), value (the formatted value), col and the row's expand and selected state. Here the usage column draws a bar next to the percentage:
<template #body-cell-usage="props">
<q-td :props="props">
<div class="row items-center no-wrap q-gutter-sm">
<q-linear-progress
:value="Math.min(props.row.spent / props.row.budget, 1)"
:color="props.row.spent > props.row.budget ? 'negative' : 'primary'"
rounded
size="6px"
style="width: 80px"
/>
<span>{{ props.value }}</span>
</div>
</q-td>
</template><q-td :props="props"> matters. It applies the column's alignment and its classes and style, so the cell lines up with its header. A bare <td> loses all of that.
QLinearProgress takes a value from 0 to 1, hence the Math.min for projects over budget. Sorting still works, because it uses the field function, not the slot.
The actions column is the most common custom column in admin screens. A menu keeps it to one icon wide:
<template #body-cell-actions="props">
<q-td :props="props">
<q-btn flat round dense icon="more_vert" aria-label="Project actions">
<q-menu auto-close>
<q-list dense style="min-width: 140px">
<q-item clickable @click="openProject(props.row)">
<q-item-section>Open</q-item-section>
</q-item>
<q-item clickable @click="archiveProject(props.row)">
<q-item-section class="text-negative">Archive</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
</q-td>
</template>An icon-only button needs an aria-label, or a screen reader announces it as "button". autoWidth: true on the column keeps it from taking a share of the table's width.
header-cell-[name] replaces one header cell. Use <q-th :props="props"> and QTable keeps the sort arrow, the click-to-sort and the keyboard handling:
<template #header-cell-usage="props">
<q-th :props="props">
{{ props.col.label }}
<q-icon name="info_outline" size="xs" class="q-ml-xs">
<q-tooltip>Spent as a share of the budget</q-tooltip>
</q-icon>
</q-th>
</template>The top slot replaces everything above the table: the title, top-left and top-right. Use top-right when you only want to add something next to the title. Here we take the whole bar for a title and a column picker bound to visible-columns:
<q-table
:rows="rows"
:columns="columns"
row-key="id"
:visible-columns="visibleColumns"
flat
bordered
>
<template #top>
<div class="text-h6">Projects</div>
<q-space />
<q-select
v-model="visibleColumns"
:options="optionalColumns"
option-value="name"
option-label="label"
emit-value
map-options
multiple
dense
outlined
options-dense
display-value="Columns"
style="min-width: 140px"
/>
</template>
</q-table>const optionalColumns = columns.filter(col => !col.required)
const visibleColumns = ref(optionalColumns.map(col => col.name))Columns marked required ignore visible-columns, so the project name, the expand button and the actions can't be hidden. Only the optional ones go into the picker.
Since Quasar 2.34, the body-expand slot renders an extra row after each body row, while QTable keeps rendering the rows themselves. Every body slot's scope has a writable expand flag, so a button in a cell can toggle it:
<template #body-cell-expand="props">
<q-td :props="props">
<q-btn
flat
round
dense
size="sm"
:icon="props.expand ? 'expand_less' : 'expand_more'"
:aria-label="props.expand ? 'Hide tasks' : 'Show tasks'"
:aria-expanded="props.expand"
@click="props.expand = !props.expand"
/>
</q-td>
</template>
<template #body-expand="props">
<q-tr v-if="props.expand" :props="props">
<q-td colspan="100%">
<div class="text-caption text-grey-7 q-mb-xs">Open tasks</div>
<div v-for="task in props.row.tasks" :key="task">{{ task }}</div>
</q-td>
</q-tr>
</template>The slot is called for every row, so the v-if on expand is what keeps closed rows empty. To animate it, keep the <q-tr> rendered with the expandable prop and wrap the cell's content in a q-slide-transition. To open rows from outside, for example after a search, bind v-model:expanded to an array of row keys.
The body slot replaces the entire row, so you build every cell yourself. Reach for it only when the row isn't a set of columns any more, such as an avatar and two lines of text spanning what would be several columns. Two things change when you do:
<q-td> needs key="columnName" (or col-name) next to :props="props", so it can find its column definition. A cell whose column is hidden by visible-columns renders nothing.body-expand is ignored. Render the expansion row inside body yourself, with its own key.bottom-row adds a row after the body rows, and its scope has the visible cols, so the totals follow the column picker:
<template #bottom-row="props">
<q-tr class="text-weight-medium">
<q-td v-for="col in props.cols" :key="col.name" :class="`text-${col.align}`">
{{ totals[col.name] ?? '' }}
</q-td>
</q-tr>
</template>const totals = computed<Record<string, string>>(() => ({
name: `${rows.value.length} projects`,
budget: money.format(rows.value.reduce((sum, row) => sum + row.budget, 0)),
}))The footer slot (2.26+) renders the same kind of content in a real <tfoot>, which suits a totals row you want to make sticky with CSS. Note that these totals cover all rows, not the current page or filter.
When there are no rows, or the filter matches none, QTable shows a message in the bottom bar. The no-data slot gets that message (and the current filter) and lets you add an action:
<template #no-data="{ message }">
<div class="full-width column items-center q-pa-lg text-grey-7">
<q-icon name="folder_open" size="md" />
<div class="q-mt-sm">{{ message }}</div>
<q-btn flat no-caps color="primary" label="Create a project" class="q-mt-sm" @click="createProject" />
</div>
</template>Why is my body-cell slot not aligned with the header? You used a plain <td>, or forgot :props="props" on <q-td>.
Is props.value the raw or the formatted value? Formatted. Use props.row.someField for the raw value.
How do I make a whole row clickable? Listen to @row-click on q-table; you don't need a slot. Stop the click from bubbling in action buttons with @click.stop.
Can I use slots in grid mode? Grid mode uses the item slot instead of the body slots, with the same row scope.
The Data Tables Block has 17 Components built on these slots. Two are Free: both add an Edit button to each row with a body-cell-actions slot. Others use body-cell slots for status badges and avatars, the full body slot for multi-line rows, and multiple selection. Open one, check which slot does what, and swap in your columns.