Reputation: 85
Is it possible to add specific content to the daily calendar using Vuetify? I would like add data table for every day without intervals (1AM, 2AM etc.), but it doesn't work.
I tried:
<template v-slot:day-body="{ date, week }">
specific content for selected day here...
<v-data-table></v-data-table>
</template>
If this is not possible, is there any other solution to add a daily calendar (front-end)? I can't find a similar example anywhere.
Demo code here
HTML:
<div id="app">
<v-app id="inspire">
<v-row class="fill-height">
<v-col>
<v-sheet height="64">
<v-toolbar
flat
>
<v-btn
outlined
class="mr-4"
color="grey darken-2"
@click="setToday"
>
Today
</v-btn>
<v-btn
fab
text
small
color="grey darken-2"
@click="prev"
>
<v-icon small>
mdi-chevron-left
</v-icon>
</v-btn>
<v-btn
fab
text
small
color="grey darken-2"
@click="next"
>
<v-icon small>
mdi-chevron-right
</v-icon>
</v-btn>
<v-toolbar-title v-if="$refs.calendar">
{{ $refs.calendar.title }}
</v-toolbar-title>
</v-toolbar>
</v-sheet>
<v-sheet height="600">
<v-calendar
ref="calendar"
v-model="focus"
color="primary"
:events="events"
:event-color="getEventColor"
:type="type"
:show-interval-label="false"
@click:event="showEvent"
@click:more="viewDay"
@click:date="viewDay"
@change="updateRange"
>
<template v-slot:day-body="{ date, week }">
<div class="body-content">
specific content for selected day here
</div>
</template>
</v-calendar>
</v-sheet>
</v-col>
</v-row>
</v-app>
</div>
Javascript:
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: () => ({
focus: '',
type: 'day',
selectedEvent: {},
selectedElement: null,
selectedOpen: false,
events: [],
}),
mounted () {
this.$refs.calendar.checkChange()
},
methods: {
viewDay ({ date }) {
this.focus = date
this.type = 'day'
},
getEventColor (event) {
return event.color
},
setToday () {
this.focus = ''
},
prev () {
this.$refs.calendar.prev()
},
next () {
this.$refs.calendar.next()
},
showEvent ({ nativeEvent, event }) {
const open = () => {
this.selectedEvent = event
this.selectedElement = nativeEvent.target
setTimeout(() => {
this.selectedOpen = true
}, 10)
}
if (this.selectedOpen) {
this.selectedOpen = false
setTimeout(open, 10)
} else {
open()
}
nativeEvent.stopPropagation()
},
updateRange ({ start, end }) {
const events = []
const min = new Date(`${start.date}T00:00:00`)
const max = new Date(`${end.date}T23:59:59`)
const days = (max.getTime() - min.getTime()) / 86400000
const eventCount = this.rnd(days, days + 20)
for (let i = 0; i < eventCount; i++) {
const allDay = this.rnd(0, 3) === 0
const firstTimestamp = this.rnd(min.getTime(), max.getTime())
const first = new Date(firstTimestamp - (firstTimestamp % 900000))
const secondTimestamp = this.rnd(2, allDay ? 288 : 8) * 900000
const second = new Date(first.getTime() + secondTimestamp)
events.push({
name: this.names[this.rnd(0, this.names.length - 1)],
start: first,
end: second,
color: this.colors[this.rnd(0, this.colors.length - 1)],
timed: !allDay,
})
}
this.events = events
},
rnd (a, b) {
return Math.floor((b - a + 1) * Math.random()) + a
},
},
})
Upvotes: 0
Views: 1228
Reputation: 1313
You can set :interval-count = 0
for v-calendar
and load the data table below each day separately on a different component that changes according to the date selected.
Upvotes: 2