Answer the question
In order to leave comments, you need to log in
Dynamic data to Vuetify table?
I have items data:
{
"name": "Отдел 1",
"departmentKey": "web",
"m1": 45,
"color": "GOOD",
"m2": 85,
"color2": "GOOD",
}
{
"name": "Отдел 2",
"departmentKey": "devops",
"m1": 78,
"color1": "GOOD",
"m2": 58,
"color2": "GOOD",
}
<v-data-table
:headers="headers"
:items="items"
hide-default-footer
disable-pagination
class="metrics-table"
disable-sort
@click:row="handleClick"
>
<template v-slot:item.m1="{ item }">
<v-chip :color="colors[item.color1]" dark>
{{ item.m1 }}
</v-chip>
</template>
<template v-slot:item.m2="{ item }">
<v-chip :color="colors[item.color2]" dark>
{{ item.m2 }}
</v-chip>
</template>
</v-data-table>
Answer the question
In order to leave comments, you need to log in
Why make properties of metrics elements properties of parent objects? Pass the data to the component with the table as is. Only add a property to the appropriate headers elements to indicate that this column should display data from a nested metrics array, such as .
In the table component, get a list of these columns:metricsColumn: true
computed: {
metricsColumns() {
return this.headers.filter(n => n.metricsColumn);
},
},
<template
v-for="(n, i) in metricsColumns"
#[`item.${n.value}`]="{ item: { metrics: { [i]: item } } }"
>
<v-chip
:color="colors[item.metricsValueMarkName]"
:key="n.value"
dark
>
{{ item.metricsValue }}
</v-chip>
</template>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question