This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdate-header-template.tsx
More file actions
90 lines (86 loc) · 4.29 KB
/
date-header-template.tsx
File metadata and controls
90 lines (86 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import {
ScheduleComponent, ViewsDirective, ViewDirective, Day, Week, WorkWeek, Month, TimelineMonth,
RenderCellEventArgs, EventRenderedArgs, Inject, Resize, DragAndDrop
} from '@syncfusion/ej2-react-schedule';
import { scheduleData, applyCategoryColor } from './datasource';
import './date-header-template.css';
import { Internationalization, extend } from '@syncfusion/ej2-base';
import { SampleBase } from '../common/sample-base';
/**
* Schedule date header template sample
*/
export class DateHeaderTemplate extends SampleBase<{}, {}> {
private scheduleObj: ScheduleComponent;
private data: Object[] = extend([], scheduleData, null, true) as Object[];
private instance: Internationalization = new Internationalization();
private getDateHeaderText(value: Date): string {
return this.instance.formatDate(value, { skeleton: 'Ed' });
}
private getWeather(value: Date) {
switch (value.getDay()) {
case 0:
return '<img className="weather-image" src= "src/schedule/images/weather-clear.svg" /><div className="weather-text">25°C</div>';
case 1:
return '<img class="weather-image" src="src/schedule/images/weather-clouds.svg"/><div class="weather-text">18°C</div>';
case 2:
return '<img class="weather-image" src="src/schedule/images/weather-rain.svg"/><div class="weather-text">10°C</div>';
case 3:
return '<img class="weather-image" src="src/schedule/images/weather-clouds.svg"/><div class="weather-text">16°C</div>';
case 4:
return '<img class="weather-image" src="src/schedule/images/weather-rain.svg"/><div class="weather-text">8°C</div>';
case 5:
return '<img class="weather-image" src="src/schedule/images/weather-clear.svg"/><div class="weather-text">27°C</div>';
case 6:
return '<img class="weather-image" src="src/schedule/images/weather-clouds.svg"/><div class="weather-text">17°C</div>';
default:
return null;
}
}
private dateHeaderTemplate(props): JSX.Element {
return (<div><div>{this.getDateHeaderText(props.date)}</div><div className="date-text"
dangerouslySetInnerHTML={{ __html: this.getWeather(props.date) }}></div></div>);
}
private onRenderCell(args: RenderCellEventArgs): void {
if (args.elementType === 'monthCells' && this.scheduleObj.currentView === 'Month') {
let ele: Element = document.createElement('div');
ele.innerHTML = this.getWeather(args.date);
(args.element).appendChild(ele.firstChild);
}
}
private onEventRendered(args: EventRenderedArgs): void {
applyCategoryColor(args, this.scheduleObj.currentView);
}
render() {
return (
<div className='schedule-control-section'>
<div className='control-section'>
<div className='control-wrapper'>
<ScheduleComponent width='100%' height='650px' cssClass='schedule-date-header-template' ref={t => this.scheduleObj = t}
renderCell={this.onRenderCell.bind(this)} eventRendered={this.onEventRendered.bind(this)} selectedDate={new Date(2018, 1, 15)}
eventSettings={{ dataSource: this.data }} dateHeaderTemplate={this.dateHeaderTemplate.bind(this)}>
<ViewsDirective>
<ViewDirective option='Day' />
<ViewDirective option='Week' />
<ViewDirective option='WorkWeek' />
<ViewDirective option='Month' />
<ViewDirective option='TimelineMonth' />
</ViewsDirective>
<Inject services={[Day, Week, WorkWeek, Month, TimelineMonth, Resize, DragAndDrop]} />
</ScheduleComponent>
</div>
</div>
<div id='action-description'>
<p>This demo depicts the way to add images and custom text to the date header bar by making use of the date header template
option.</p>
</div>
<div id='description'>
<p>In this demo, the <code>dateHeaderTemplate</code> option is used to customize the date header cells of day,
week and workweek views. In month view, the date header is not applicable and therefore the same customizations can be
added beside the date text in the month cells by making use of the <code>renderCells</code> event.</p>
</div>
</div>
);
}
}