I've found a way to do it, using what I could read HERE. Indeed it is possible to define custom slots
.
Finally my field declaration looks like :
table_fields: [
{ key: 'username', sortable: true },
{ key: 'firstName', sortable: true },
{ key: 'lastName', sortable: true },
{ key: 'isActive', sortable: true, label: 'Status' },
{ key: 'actions', label: 'Actions' }
]
the little snippet for the custom slot :
<template v-slot:cell(isActive)="row">
<b-badge
v-if="row.item.isActive"
variant="success">
Active
</b-badge>
<b-badge
v-else
variant="warning">
Archived
</b-badge>
</template>
and my whole b-table
:
<b-table
hover
:items="users"
:fields="table_fields">
<template v-slot:cell(isActive)="row">
<b-badge
v-if="row.item.isActive"
variant="success">
Active
</b-badge>
<b-badge
v-else
variant="warning">
Archived
</b-badge>
</template>
<template v-slot:cell(actions)="row">
<span v-if="row.item.isActive">
<b-button
to="#"
size="sm"
variant="primary"
class="mr-1"
title="Edit">
<font-awesome-icon :icon="['fas', 'pen']"/>
</b-button>
<b-button
@click="archiveUser(row.item.id)"
size="sm"
class="mr-1"
title="Archive">
<font-awesome-icon :icon="['fas', 'archive']"/>
</b-button>
</span>
<b-button
v-else
@click="unarchiveUser(row.item.id)"
variant="success"
size="sm"
class="mr-1"
title="Unarchive">
<font-awesome-icon :icon="['fas', 'caret-square-up']"/>
</b-button>
<b-button
@click="deleteUser(row.item.id)"
size="sm"
variant="danger"
class="mr-1"
title="Delete">
<font-awesome-icon :icon="['fas', 'trash-alt']"/>
</b-button>
</template>
</b-table>
and what it looks like :
You can see that in the column Status
the b-badge
is displayed instead of true
or false