Handling Dates with JavaScript Calendars Package | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (15)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (67)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (920)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (37)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (151)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (41)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (508)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)

Handling Dates with JavaScript Calendars Package

This blog is intended to give you a clear understanding of the best way to utilize the Essential JS 2 calendars package to choose the best-suited UI components to handle date-time values in your modern web apps.

From the package name itself, you knew that the package was going to have a calendar component. Yes, of course you’re right, but this package not only holds the calendar, it has a huge set of UI components (date picker, time picker, date-time picker, and date-range picker) to handle the date values as a single selection or range of selections in web applications.

The core intention of the calendars package is to cover all the possibilities of date-time value handling in the web with the most flexible and best-suited UI tools. They should help user interaction be smoother in applications and reduce the job of developers handling date-value codes in the development process.

As I mentioned earlier, the calendars package includes the following set of components:

What has been considered in developing these components?

UX design of components in calendars package

What will initially cause more users to choose one application over another? Most of them will go with the simplest and best UX design of the application. So, the best-designed application requires the best-designed subset of UI tools.

Here the components in the calendars package are made with a simple and excellent UX design that fits into our multiple-device world.

You can see in the following screen shot a component’s UX design covering all the required use cases for selecting a date and time as quickly as possible.

calendar

  1. Header text specifies the name of the current month that is displayed in the calendar table.
  2. Up and down arrows to navigate the previous and next months in calendar.
  3. Header of the days of the week.
  4. Week number of the year.
  5. Dates in calendar table.
  6. Today button in footer to quickly pick today’s date.

The header text of the calendar is clickable to drill down from month to year as well as year to decade and vice versa. It gives a nice experience to end users for selecting far off dates in an easy, fast way. Let’s see the UX of a drilled-down calendar in month view.

month calendar

The drill-down or up options not only give users an easy way to select a date, they also allow you to change the calendar so that only the month or year can be selected as values. So, you can use the calendar to act as a month or year picker.
This is a cool way you can make use of a single component as a date, month, or year picker based on your application choice. Following, you can see the year view of calendar.
year calendar
As we have seen the calendar design, now let’s see the date picker UX design that covers both desktop and mobile devices.
datepicker
  1. Text box in which to enter a date value.
  2. Cross icon allows clearing of the value in the text box.
  3. Drop-down calendar icon to pop up the calendar and pick a date.
  4. Header that displays the name of the month, year, or decade shown in the calendar table.
  5. Up and down arrows to navigate the previous and next months in the calendar.
  6. Header with days of the week.
  7. Selected date.
  8. Week number of the year.
  9. All the dates in the calendar table.
  10. Today button in footer to pick today’s date in the calendar.
You may think there’s no major difference between calendar and date picker, but there’s a difference. Date picker is an editable input form component and only takes HTML input for rendering, whereas calendar can be used in form or anywhere as inline and takes all elements for rendering.
In mobile devices, the date picker is more adaptive, as seen in the following screenshot, and gives a better user experience.
datepicker
Here the calendar pop-up is placed at the center of the device for easy interaction.Well, now let’s see the simple time picker component that pops out of the time list to select the time value.
timepicker
  1. Text box in which to enter the time value.
  2. Cross icon allows clearing of the value in the text box.
  3. Drop-down time icon to pop up the time list and pick the time.
  4. Default scroller to scroll and pick the time easily.
  5. Selected time value highlighted in list.
In mobile devices, the pop-up comes over the text box so that you can easily pick the time value from pop-up time list.
timepicker
Next is the date-time picker. The UX design of the date-time picker component is a combination of both the date picker and time picker. So only the text box holds the two icons, date and time, to pop out the calendar and select a date and time list from which to select the time.
datetimepicker
Finally, we are going to see the UX of date-range picker. This component is for selecting two dates as the start and end of a range. It presents nice user interaction on the desktop by showing two consecutive months in parallel, as shown in the following image.
daterangepicker
  1. Text box in which to enter the start and end date values.
  2. Drop-down range calendar icon to pop up the date-range calendar.
  3. Represents the selected start and end month.
  4. Represents the number of days in the selected date range.
  5. Previous and next month navigation pointer.
  6. Header text representing the name of the current month shown.
  7. Selected start date in left-side calendar.
  8. Selected end date in right-side calendar.
  9. Apply button to update the selected date-range value.
  10. Cancel button to cancel the selection of a date range.
But if the same UX design is used for mobile, then it’s definitely not going to have the best user interaction for choosing start and end dates. Well, it won’t happen: the UX design of the component switches automatically with the devices or minimal resolution to bring the best user-friendly UI, as shown in the following.
daterangepicker
  1. Toggle button to change the start date and end date selection.
  2. Represents the number of days in the selected date range.
  3. Header text with the name of the month being shown.
  4. Selected start date.
  5. Selected end date.
  6. Today’s date is highlighted.
  7. Apply button to update the selected date-range value.
  8. Cancel button to cancel the selection of a date range.
That design brings the Date-range picker as more adaptive and can show a single calendar for start and end date selection. Another preferred use case in this component is a predefined set of ranges from which to make a quick selection. Here, the presets are presented as a drop-down list that works in all devices as shown in the following.
preset range

From the UX design, it’s clear that these components are more user friendly in all devices because they cover all required use cases.

Functionalities covered in components

Not only do these components provide better user experience through UX design, they also cover all functionalities in the basis of the 80:20 rule with flexible options that will fulfill all business needs in modern applications. Here are these features:

Month or year selection—In calendar and date picker, these provide flexible options to select only the month or year as a date value.

Date range—Restricts the range of dates that can be selected.

Globalization—Supports globalization (internationalization and localization) to translate the names of months, days, and the today button text to any supported language.

First day of week—Change the first day of weeks in every month.

Disabled dates—Any date can be disabled to prevent selection.

Customization—You have complete control over the appearance of the date components.

Highlight weekends—Highlight every weekend in a month.

Week number—Show the week number of selected dates by enabling the week number options.

Formatting—Input values can be set to be custom formatted apart from the default culture-specific date format.

Validation—Allows only valid values to be entered in input by validating that values are not invalid, disabled, or out-of-min or out-of-max of the date range. The disabled and out-of-date-range values are set to be in a disabled state that prevents the end user from selecting them.

Predefined ranges—In date-range picker, define a preset of ranges to allow end users to select a frequently used date range.

When to use which component

Calendar acts as an inline component and is best suited when you want to visualize data on specific date.

Date Picker is a form component used to get or set a date value, so it’s best suited when only using a date as a value.

Time Picker is a form component used to get or set a time value, so it’s best suited when only using a time as a value.

Date-Time Picker is a form component used to get or set a date-time value, so it’s best suited when using a date as well as a time value.

Date-Range Picker is a form component used to get or set start and end date values, so it’s best suited when using a range of dates.

Summary

I hope now you understand the Syncfusion JavaScript calendars package and its available components, including their usage and when they best suit your applications. Stay tuned for other blogs about our Essential JS 2 components and their features.

Try our date-time components by downloading from the free trial or GitHub. Feel free to have a look at our online samples and documentation to explore other available options. If you have any questions or require clarification, please let us know in the comments section below. You can also contact us through our support forum or Direct-Trac. We are always happy to assist you!

If you like this blog post, we think you’ll also like the following free e-books:

 

Tags:

Share this post:

Comments (4)

Hello! Is it possible to have users select time on the date range picker? And would that be mobile friendly as well?

Hi Faith,

At present there’s no option to select the time on date range picker. We have already logged a feature request on this requirement and sure it will be mobile friendly on selecting the date and time range. You could have track the feature status from this feedback https://www.syncfusion.com/feedback/5760/new-datetimerangepicker-control.

Also there’s an option to enter the date time range value in date range picker without UI interaction on selecting time, to do so please refer this sample https://ej2.syncfusion.com/demos/#/material/daterangepicker/date-format.html.

I’m using the date picker control and the situation is as follows:

In an application for booking appointments in a medical clinic, , I need to block a period of consecutive dates (for example, when a doctor is on vacations), showing an icon, so that the user understands why, in that period, the appointments are not possible for that doctor. Is this possible? Can you show me how (with code, if possible)? Thanks

Hello Fausto,

Yes. It is possible to show an icon for a specified date or a range of dates. In RenderDayCell event, you can get the details of the cell which is currently being rendered. With the help of this event callback, you can add the icon to the respective calendar date cell. Also you can set the property isDisabled of RenderDayCellEventArgs as true to block a certain date gets selected. Please find the code snippet and sampe below. In this sample we have added icons to the dates which are in the range between 10 and 20.

[code]
function customDates(args: RenderDayCellEventArgs): void {
/*Date need to be customized*/
if (args.date.getDate() >= 10 && args.date.getDate() <= 20) {
// To disable the current cell
args.isDisabled = true;
let span: HTMLElement;
span = document.createElement("span");
span.setAttribute("class", "fa fa-exclamation");
args.element.firstElementChild.setAttribute(
"title",
"Doctor is in Vacation !"
);
args.element.appendChild(span);
}
}

/*Override the default pointer events css from none to auto to display tooltip when hover*/
.e-calendar .e-content td.e-disabled {
pointer-events: auto;
}
/*When active set none to prevent click in disabled element*/
.e-calendar .e-content td.e-disabled:active {
pointer-events: none;
}

Sample Link : https://stackblitz.com/edit/special-dates

Regards,
Saravanan G

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed