I want to create a parent component for a bootstrap-vue table with custom data rendering (templates).
Right now, this kinda looks like this:
<b-table
:items="result"
:fields="fields"
:current-page="currentPage"
:per-page="perPage">
<template slot="Index" slot-scope="data">
{{ data.index + 1 }}
</template>
<!-- more templates for various columns here -->
</b-table>
<b-pagination
align="center"
:total-rows="result.length"
v-model="currentPage"
:per-page="perPage"
/>
The reason I want to wrap this in a component is because I use this table layout, including the pagination and all of its attributes (like striped, bordered, etc.) multiple times.
The only thing that changes, are the column-templates.
I know, the Vue way to do that would be to create a slot like <slot name="x"></slot>
and fill it with <template slot="x">...</template>
. For one thing, that would coincide with the bootstrap-vue template
and on the other hand, bootstrap-vue only seems to render the templates correctly, if they are placed right inside b-table
.
Basically, what I want to achieve is a component like this:
<b-table>
<slot name="templates"/>
</b-table>
<b-pagination stuff.../>
And use it in a child component like this:
<TemplateTable>
<template slot="templates">
<template slot="Index" slot-scope="data">
{{ data.index + 1 }}
</template>
<!-- more templates -->
</template>
</TableTemplate>
Has anyone done something like this and figured out a way to solve it?