I would like to display the array of objects inside el-table-column in the loop. For each name and surname of the example, I would like to display iterated costData property values in the next columns. I managed to find a solution which I paste below. Is it possible to achieve the same result without repeating the same loop for each column? Preferably I would also like to display normal table cells, not custom div tags, as in my solution. I would be glad for any help
Table data prop:
[
{
"name":"Jon",
"surname":"Doe",
"costData":[
{
"cost":"b",
"totalCost":"d",
"serviceName":""
},
{
"cost":"b",
"totalCost":"d",
"serviceName":""
},
{
"cost":"b",
"totalCost":"d",
"serviceName":""
}
]
}
]
<template>
<el-table :data="tableData">
<el-table-column prop="name" label="Name" width="120" />
<el-table-column prop="surname" label="Surname" width="120" />
<el-table-column prop="costData" :label="cost" width="160">
<template slot-scope="scope">
<div v-for="(item, index) in scope.row.costData" :key="index">
{{ item.serviceName }}
</div>
</template>
</el-table-column>
<el-table-column prop="costData" :label="totalCost" width="160">
<template slot-scope="scope">
<div v-for="(item, index) in scope.row.totalCost" :key="index">
{{ item.cost }}
</div>
</template>
</el-table-column>
<el-table-column prop="costData" :label="totalCost" width="160">
<template slot-scope="scope">
<div v-for="(item, index) in scope.row.totalCost" :key="index">
{{ item.totalCost }}
</div>
</template>
</el-table-column>
</el-table>
</template>
<script lang="ts">
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';
@Component({})
export default class FuelTable extends Vue {
@Prop({ default: null })
tableData: any;
}
</script>