Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ng-material-date-range-picker

Kumar-Aakash641MIT1.2.14TypeScript support: included

This library provides the date range selection with two views.

dateRange, date, datePicker, matDateRangePicker, matDatePicker, matDate, material, angular, calender, multi-calender

readme

ng-material-date-range-picker

Date range view

Description:

This library is build on top of angular material date-picker to provide date range selection with two views and predefined date options.

Latest Version:

Angular Version Latest Library version
v16 1.2.10
v17 2.2.4

Getting Started with Ng Material Date Range Picker

The following section explains the steps required to create a simple 2 view Date Range Picker component and demonstrates its basic usage.

Dependencies

To use the 2 view Date Range Picker component in your application, install the following dependency packages:

1. angular (version 16.x)
2. angular-material (version 16.x)
2. bootstrap (version 5.0)

Setup Angular Environment

Angular provides an easy way to set up Angular CLI projects using the Angular CLI tool.

  1. Install the CLI application globally:

    npm install -g @angular/cli
  2. Create a new application:

    ng new ng-date-range-picker-app
  3. Navigate to the created project folder:

    cd ng-date-range-picker-app

Installing Dependencies

To use the 2 view Date Range Picker component in your application, install the following dependency packages:

  1. Angular Material Lib:

    npm i @angular/material@16.2.6
  2. Bootstrap CSS:

    npm i bootstrap
  3. Add bootstrap css inside angular.json:

    "styles": [
         "src/styles.css",
         "@angular/material/prebuilt-themes/indigo-pink.css"
         "node_modules/bootstrap/dist/css/bootstrap.min.css",
       ],

Installing Ng Date Range Picker Package

Range Picker package can be installed using the following command:

npm i ng-material-date-range-picker

Registering Ng Material Date Range Picker Module

Import the 2 view Date Range Picker module into your Angular application (src/app/app.module.ts):

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser';
import { NgDatePickerModule } from 'ng-material-date-range-picker';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, NgDatePickerModule,  CommonModule],
  bootstrap: [AppComponent]
})
export class AppModule { }

Adding Ng Date Range Picker Component

Modify the template in src/app/app.component.ts to render the 2 view Date Range Picker component:

import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  template: `<ng-date-range-picker></ng-date-range-picker>`
})
export class AppComponent {
  title = 'ng-date-range-picker-test';
}

Running the Application

After completing the required configuration, run the following command:

ng serve

This will display the Date Range Picker in your default browser.

Features

  • Allow to select date range with two views.
  • Predefined date support with list items.
  • User can modify predefined date list.
  • Provides complete controls on predefined date action items.

API Reference

Properties:

Name Type Description
selectedDates DateRange<Date> optional. default selection of start and end date
dateFormat string optional. default is 'dd/MM/yyyy'
dateDropDownOptions ISelectDateOption[] optional. Addition options to predefined date action list.
minDate Date optional. To specify minimum date default is current date -10 years.
maxDate Date optional. To specify max date default is current date +10 years.
selectedOptionIndex number optional. To default selected option. (by default it is 3 which is last 30 days.)
displaySelectedLabel boolean optional. To show the selected option label instead of date range
cdkConnectedOverlayPositions ConnectedPosition[] optional. To control the overlay position
staticOptionId string optional. To set id of static options container
dynamicOptionId string optional. To set id of dynamic options container

Events

Name Type Description
onDateSelectionChanged SelectedDateEvent Emits when date selection is changed. And it contains range: DateRange<Date> and selectedOption: ISelectDateOption
dateListOptions ISelectDateOption[] Emits pre-defined date action list items for configuration purpose.

Example to configure predefined visibility of predefined date action list items:

import { Component } from '@angular/core';
import { ISelectDateOption } from 'ng-date-range-picker/lib/model/select-date-option';

@Component({
  selector: 'app-root',
  template:` <ng-date-range-picker (dateListOptions)="dateListOptions($event)"></ng-date-range-picker>`
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  title = 'ng-date-range-picker-test';

  dateListOptions(optionList: ISelectDateOption[]) {
    optionList[0].isSelected = true;
    optionList[1].isVisible = false;
  }
}

In Above example first item of action list is selected and second option is hidden.

Note:

Upon clearing, it resets the minimum and maximum dates, and sets both the range and selectedOption to null.

Demo's

Demo 1

Demo 2

Playground

Stackblitz

changelog

Changelog

[1.2.14] - 2024-08-29

  • Supported control on cdkConnectedOverlayPositions.
  • Added staticOptionId - to set id for static options
  • Added dynamicOptionId - to set id for dynamic options
  • Bugfixes

[1.2.13] - 2024-08-22

  • Supported control on cdkConnectedOverlayOpen.
  • Bugfixes

[1.2.12] - 2024-08-15

  • Supported cloned dates.

[1.2.11] - 2024-08-14

  • Bugfixes
  • Added support to show selected option label.

[1.2.10] - 2024-06-16

  • Bugfixes
  • Added clear functionality.

[1.2.9] - 2024-03-24

  • Bugfixes
  • Custom option selection on specifying the selected dates.

[1.2.8] - 2024-03-23

  • Added changes to show default dates in input box.
  • Supported default option on init.
  • Fixed bug on last month selection.

[1.2.7] - 2024-03-16

  • Fixed issues on second calendar view.

[1.2.6] - 2024-03-14

  • Added min and max date support.

[1.2.5] - 2024-01-25

  • Added Dynamic Label Feature For Input Field.

[1.2.4] - 2024-01-23

  • Added backdrop click operations on calendar.

[1.2.3] - 2024-01-23

  • Supported default date selection based on default option selection.

[1.2.2] - 2024-01-20

  • Exposed Id for dropdown and calendar.
  • Exposed option to control default options.

[1.2.1] - 2023-12-30

  • Fixed position related bugs for static position.

[1.2.0] - 2023-12-29

  • Exposed Enum.
  • Exposed positioning attributes for cdkConnectedOverlay
  • Fixed bugs bugs around conflicting css with bootstrap.
  • Added attributes for to show options list as static list.

[1.1.1] - 2023-11-04

  • Added default preset options flag
  • Updated md file

[1.1.0] - 2023-11-04

  • Removed Bootstrap Library Dependency.
  • Exposed actions on predefined date menu items.
  • Added more keywords.

[1.0.2] - 2023-10-14

Added

  • Added below things in package.json file:

    1. license info
    2. keywords
    3. repository link
    4. homepage link
    5. author info

    6. Added below changes in readme.md:

    7. improved demo urls
    8. added playground url

[1.0.1] - 2023-10-11

Added

  • Added README.MD

[1.0.0] - 2023-10-11

Added

  • Initial release of the package
  • Feature 1: Allow to select date range with two views.
  • Feature 2: Predefined date support with list items.
  • Feature 3: User can modify predefined date list.
  • Feature 4: Provides complete controls on predefined date action items.