Skip to content

Slots

Introduction

The Table component has slots that allow you to customize the rendering of the component without having to create a new component or modify the existing one. If you're not familiar with slots, you can read about them in the Vue documentation.

Global Slots

The Table component has the following high-level slots:

SlotDescription
loadingThe overlay that is displayed when the table is loading data.
topbarThe container for the content above the table (e.g., search, actions).
filtersThe container for the active filters.
tableThe container for the actual table.
theadThe actual <thead> element.
tbodyThe actual <tbody> element.
footerThe container for the content below the table (e.g., pagination).

To each of these slots, a table and actions prop is passed to the slot scope. These correspond to the composables useTable() and useActions() functions that you can read about in the Custom Table Component section.

Example

vue
<Table :resource="users">
    <template #filters="{ table, actions }">
        <p v-if="!table.hasFilters">No filters applied.</p>
        <p v-if="actions.allItemsAreSelected">All items are selected!</p>
    </template>
</Table>

Column Slots

Instead of replacing a complete section of the table, you can also replace individual column headers and cells. This is done by using dynamic slot names that correspond to the column key. For headers, the slot name is header(key), and for cells, it's cell(key).

Besides the table and actions props, the header(key) slot also receives a column prop that contains the column definition. The cell(key) slot receives column, item, and value props.

Example

vue
<Table :resource="users">
    <template #header(name)="{ column }">
        <b>Full name</b>
    </template>

    <template #cell(name)="{ column, item, value }">
        <span :title="value">{{ item.first_name }} {{ item.last_name }}</span>
    </template>
</Table>