Is it possible to merge to values and put into one column in v-data-table?
List.vue
<template>
<v-app>
<v-data-table
:items="items"
:headers="headers"
/>
</v-app>
</template>
<script>
export default {
data() {
return {
items: [
{ first_name: "Peter", last_name: "Johnson" },
{ first_name: "Simon", last_name: "Walker" }
],
headers: [
{ text: "first_name", value: "first_name" },
{ text: "last_name", value: "last_name" },
]
};
}
};
</script>
For example I want to put Peter Johnson
in Full name
column of my v-data-table, While it doesn't have Full name
column.
You can render a virtual column with the use of slots with v-data-table
. But you need to have a column full_name
.
<v-data-table :headers="headers" :items="items">
<template #item.full_name="{ item }">{{ item.first_name }} {{ item.last_name }}</template>
</v-data-table>
export default {
data() {
return {
items: [
{ first_name: "Peter", last_name: "Johnson" },
{ first_name: "Simon", last_name: "Walker" }
],
headers: [{ text: "Full Name", value: "full_name" }]
};
}
};
On Pierre Said's answer, 'v-slot' directive doesn't support any modifier. (eslint-plugin-vue)
<v-data-table :headers="headers" :items="items">
<template v-slot:[`item.full_name`]="{ item }">{{ item.first_name }} {{ item.last_name }}</template>
</v-data-table>
只需在后端添加一个“全名”虚拟列,或者使用计算属性。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.