Skip to content

Commit 9e51381

Browse files
committed
add Calendar KB article
1 parent ec237d4 commit 9e51381

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: Add a badge to the Calendar cells based on a condition
3+
description: An example on how to show a badge based on a condition in the Kendo UI for Vue Calendar.
4+
type: how-to
5+
page_title: Conditionally render a badge - Kendo UI for Vue Calendar
6+
slug: calendar-add-badge-conditionally
7+
tags: calendar, kendo ui for vue, badge, cell, conditionally
8+
res_type: kb
9+
category: knowledge-base
10+
---
11+
12+
<table>
13+
<tbody>
14+
<tr>
15+
<td>Product Version</td>
16+
<td>4.3.2</td>
17+
</tr>
18+
<tr>
19+
<td>Product</td>
20+
<td>Progress® Kendo UI for Vue Native</td>
21+
</tr>
22+
</tbody>
23+
</table>
24+
25+
26+
## Description
27+
28+
How can I render a badge for specific calendar cells based on a condition?
29+
30+
## Solution
31+
32+
Use the [`cell`](slug:api_dateinputs_calendarprops#toc_cell) prop to render a custom component that will render a [Badge](slug:overview_badge) based on the required condition.
33+
34+
### Runnable example
35+
36+
The following example showcases how to render the Badge for the first three dates:
37+
38+
{% meta id:index height:560 %}
39+
{% embed_file calendar-add-badge-conditionally/main.vue preview %}
40+
{% embed_file calendar-add-badge-conditionally/Cell.vue %}
41+
{% embed_file calendar-add-badge-conditionally/main.js %}
42+
{% endmeta %}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<template>
2+
<calendar-cell
3+
:is-selected="isSelected"
4+
@click="handleClick"
5+
:style="cellStyle"
6+
>
7+
<span class="sent-items">
8+
{{ formattedValue }}
9+
<Badge
10+
v-if="shouldShowBadge"
11+
:theme-color="'tertiary'"
12+
:rounded="'full'"
13+
:size="'small'"
14+
>34</Badge
15+
>
16+
</span>
17+
</calendar-cell>
18+
</template>
19+
20+
<script>
21+
import { CalendarCell } from '@progress/kendo-vue-dateinputs';
22+
import { BadgeContainer, Badge } from '@progress/kendo-vue-indicators';
23+
24+
export default {
25+
name: 'CustomCalendarCell',
26+
props: CalendarCell.props,
27+
components: {
28+
'calendar-cell': CalendarCell,
29+
BadgeContainer,
30+
Badge,
31+
},
32+
emits: {
33+
click: null,
34+
},
35+
computed: {
36+
cellStyle: function () {
37+
return this.$props.isWeekend ? { opacity: '.7' } : { fontWeight: 'bold' };
38+
},
39+
shouldShowBadge() {
40+
const day = new Date(this.$props.value).getDate();
41+
return day <= 3 && !this.$props.isOtherMonth;
42+
},
43+
},
44+
methods: {
45+
handleClick: function (e) {
46+
this.$emit('click', this.$props.value, e);
47+
},
48+
},
49+
};
50+
</script>
51+
52+
<style>
53+
.sent-items {
54+
position: relative;
55+
overflow: visible;
56+
}
57+
</style>
58+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { createApp } from 'vue'
2+
import App from './main.vue'
3+
4+
createApp(App).mount('#app')
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<template>
2+
<div class="example-config">
3+
<calendar :cell="customCell" >
4+
<template v-slot:myTemplate="{props}">
5+
<custom v-bind="props"/>
6+
</template>
7+
</calendar>
8+
</div>
9+
</template>
10+
<script>
11+
import { Calendar } from '@progress/kendo-vue-dateinputs';
12+
import Cell from './Cell';
13+
14+
export default {
15+
components: {
16+
'calendar': Calendar,
17+
'custom': Cell
18+
},
19+
data: function(){
20+
return {
21+
customCell: 'myTemplate'
22+
};
23+
}
24+
};
25+
26+
</script>
27+

0 commit comments

Comments
 (0)