Basically I need to pass an object in as the value for all columns in my v-data-table.
For example instead of:
{
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37
}
I need to set this as an example item in "items":
{
name: 'Ice cream sandwich',
calories: {value: 237, code: x},
fat: {value: 9.0, code: y},
carbs: {value: 37, code: z}
}
I know by using template I can still display just the value since I only want to display the value and not the code :
<div id="app">
<v-app id="inspire">
<v-data-table
:headers="headers"
:items="desserts"
:page.sync="page"
:items-per-page="itemsPerPage"
hide-default-footer
class="elevation-1"
@page-count="pageCount = $event"
>
<template #item.calories="{item}">
{{item.calories.value}}
</template>
<template #item.fat="{item}">
{{item.fat.value}}
</template>
<template #item.carbs="{item}">
{{item.carbs.value}}
</template>
<template #item.iron="{item}">
{{item.iron.value}}
</template>
</v-data-table>
</v-app>
</div>
<script>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data () {
return {
page: 1,
pageCount: 0,
itemsPerPage: 10,
headers: [
{
text: 'Dessert (100g serving)',
align: 'left',
sortable: false,
value: 'name',
},
{ text: 'Calories', value: 'calories'},
{ text: 'Fat', value: 'fat'},
{ text: 'Carb', value: 'carbs'},
],
desserts: [
{
name: 'Frozen Yogurt',
calories: {value: 159, score: 'x' },
fat: {value: 80, score: 'y' },
carbs: {value: 22, score: 'z' },
}
]
}
},
})
</script>
My problem is that I will have many columns in my table and they are dynamic. (The "headers" and "items" are generated dynamically from server.) I would rather to not also generate a large number (30+) of these template conditions but I can't really see any other solution right now.