Skip to content

Commit 8f2e5e9

Browse files
docs(scheduler): start and end slot dates KB
1 parent 2fa8fe7 commit 8f2e5e9

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import * as React from 'react';
2+
import * as ReactDOM from 'react-dom';
3+
import {
4+
Scheduler,
5+
AgendaView,
6+
TimelineView,
7+
DayView,
8+
WeekView,
9+
MonthView,
10+
} from '@progress/kendo-react-scheduler';
11+
import { sampleData, displayDate } from './events-utc';
12+
13+
const App = () => {
14+
const [start, setStart] = React.useState('');
15+
const [end, setEnd] = React.useState('');
16+
const [date, setDate] = React.useState(displayDate);
17+
const [view, setView] = React.useState('day');
18+
19+
const handleDateChange = (event) => {
20+
setDate(event.value);
21+
};
22+
23+
const handleViewChange = (event) => {
24+
setView(event.value);
25+
};
26+
27+
React.useEffect(() => {
28+
if (document) {
29+
const allSlots = document.querySelectorAll(
30+
'.k-scheduler-body .k-scheduler-cell.k-slot-cell'
31+
);
32+
const firstSlot = allSlots[0];
33+
const lastSlot = allSlots[allSlots.length - 1];
34+
35+
setStart(
36+
new Date(parseInt(firstSlot.getAttribute('data-slot-start'), 10))
37+
);
38+
39+
setEnd(new Date(parseInt(lastSlot.getAttribute('data-slot-end'), 10)));
40+
}
41+
}, [date, view]);
42+
43+
return (
44+
<div>
45+
<div>start: {start.toString()}</div>
46+
<div>end: {end.toString()}</div>
47+
<Scheduler
48+
data={sampleData}
49+
date={date}
50+
onDateChange={handleDateChange}
51+
view={view}
52+
onViewChange={handleViewChange}
53+
>
54+
<AgendaView />
55+
<TimelineView />
56+
<DayView />
57+
<WeekView />
58+
<MonthView />
59+
</Scheduler>
60+
</div>
61+
);
62+
};
63+
64+
ReactDOM.render(<App />, document.querySelector('my-app'));
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: Scheduler start and end date values
3+
description: An example on how to retrieve the date values of the first and last slot of the KendoReact Scheduler.
4+
type: how-to
5+
page_title: Get the date values of the first and last slot - KendoReact Scheduler
6+
slug: scheduler-start-end-date-values
7+
tags: scheduler, kendoreact, start, end, slot, view
8+
res_type: kb
9+
category: knowledge-base
10+
---
11+
12+
## Environment
13+
14+
<table>
15+
<tbody>
16+
<tr>
17+
<td>Product Version</td>
18+
<td>7.0.2</td>
19+
</tr>
20+
<tr>
21+
<td>Product</td>
22+
<td>Progress® KendoReact</td>
23+
</tr>
24+
</tbody>
25+
</table>
26+
27+
28+
## Description
29+
30+
I want to get the first and last date in my current Scheduler view. These start and end values should be updated when I change the view (DayView, WeekView, etc.), or when I navigate to a different date.
31+
32+
## Solution
33+
34+
Get these values using the `data-slot-start` and `data-slot-end` properties of the SchedulerSlot.
35+
36+
First, retrieve the first and last slots using the `.k-scheduler-body .k-scheduler-cell.k-slot-cell` class, where the first item in the array represents the first slot while the last one represents the last one. This allows you to get the date value of the `data-slot-start` of the first slot, and `data-slot-end` of the last slot. This should be done in the [useEffect](https://react.dev/reference/react/useEffect) hook where the date and view should be added to the dependency array because we want the start and end dates to be updated when the view or date is updated.
37+
38+
Following is an example demonstrates this approach:
39+
40+
{% meta id height:500 %}
41+
{% embed_file scheduler/start-end-dates/main.jsx preview %}
42+
{% embed_file shared/events-utc.js preview %}
43+
{% endmeta %}

0 commit comments

Comments
 (0)