All Projects → ashishgkwd → ngx-mat-daterange-picker

ashishgkwd / ngx-mat-daterange-picker

Licence: other
Date range picker component based of Angular Material Calendar component and configurable date presets. Packaged using ng-packagr.

Programming Languages

typescript
32286 projects
CSS
56736 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ngx-mat-daterange-picker

Materialtimecontrol
Time component for angular/Material2 (5.0.0-rc0)
Stars: ✭ 81 (+145.45%)
Mutual labels:  angular-material, angular5
Celerio Angular Quickstart
Generate an Angular 5 CRUD application from an existing database schema (we provide a sample one)
Stars: ✭ 483 (+1363.64%)
Mutual labels:  angular-material, angular5
Amexio.github.io
Amexio is a rich set of Angular 7 (170+) components powered by HTML5 & CSS3 for Responsive Design and with 80+ Material Design Themes, UI Components, Charts, Gauges, Data Point Widgets, Dashboards. Amexio is completely Open Sourced and Free. It's based on Apache 2 License. You can use it in your production grade work today at no cost or no obligation.
Stars: ✭ 163 (+393.94%)
Mutual labels:  angular-material, angular5
Angularconcepts
Key Angular Concepts using Latest Angular version 5
Stars: ✭ 31 (-6.06%)
Mutual labels:  angular-material, angular5
Angular5 Example Shopping App
Angular 5 Example Shopping App + Angular Material + Responsive
Stars: ✭ 120 (+263.64%)
Mutual labels:  angular-material, angular5
Learn Angular From Scratch Step By Step
Angular step by step tutorial covering from basic concepts of Angular Framework to building a complete Angular app using Angular Material components. We will go through the main building blocks of an Angular 7 application as well as the best practices for building a complete app with Angular.
Stars: ✭ 140 (+324.24%)
Mutual labels:  angular-material, angular5
Angular5 Seed
Angular5 Seed for Application
Stars: ✭ 222 (+572.73%)
Mutual labels:  angular-material, angular5
angular-rollbar-source-maps
Angular 2+ implementation to upload sourcemaps to Rollbar
Stars: ✭ 17 (-48.48%)
Mutual labels:  angular5
nglp-angular-material-landing-page
NGLP is an Angular Material Landing Page.
Stars: ✭ 32 (-3.03%)
Mutual labels:  angular-material
TASK-Management-System
Spring Boot and Angular 7 web application for task management .
Stars: ✭ 34 (+3.03%)
Mutual labels:  angular-material
ng-mat-select-infinite-scroll
Infinite Scroll directive for angular material select component
Stars: ✭ 39 (+18.18%)
Mutual labels:  angular-material
okta-spring-boot-2-angular-5-example
A Cool Cars Example that showcases Spring Boot 2, Angular 5, and Okta's Support for both.
Stars: ✭ 134 (+306.06%)
Mutual labels:  angular5
ASPNETcoreAngularJWT
Angular in ASP.NET Core with JWT solution by systemjs
Stars: ✭ 48 (+45.45%)
Mutual labels:  angular-material
extensions
Angular Material Extensions Library.
Stars: ✭ 203 (+515.15%)
Mutual labels:  angular-material
course
gary60405.github.io/course/
Stars: ✭ 17 (-48.48%)
Mutual labels:  angular-material
materialdrive
Google Drive with Angular Material
Stars: ✭ 43 (+30.3%)
Mutual labels:  angular-material
ngx-carousel
Angular Universal carousel is an lightweight , touchable and responsive library
Stars: ✭ 14 (-57.58%)
Mutual labels:  angular5
ng2-timezone-selector
A simple Angular module to create a timezone selector using moment-timezone.
Stars: ✭ 12 (-63.64%)
Mutual labels:  angular5
metadatamanagement
Metadatamanagement (MDM) - Data Search for Higher Education Research and Science Studies
Stars: ✭ 21 (-36.36%)
Mutual labels:  angular-material
Keyist-Ecommerce
🔑 A simple ecommerce site powered with Spring Boot + Angular 10 + Ngrx + OAuth2
Stars: ✭ 220 (+566.67%)
Mutual labels:  angular5

CircleCI Maintainability Test Coverage Angular_Version 9

NgxMatDaterangePicker

Angular Material Date range picker with configurable Date presets.

Fully compatible with latest Angular versions. Please see the installation table below for version compatability.

Packaged using ng-packagr

Demo

https://ashishgkwd.github.io/ngx-mat-daterange-picker/

ngx-mat-daterange-picker.gif

Installation

Angular Version Compatible version
9.0 and below v1.1.5
5.0 and below v0.0.2

For Angular v6 and above:

npm install ngx-mat-daterange-picker --save
or
yarn add ngx-mat-daterange-picker --save

For Angular v5 and below:

npm install ngx-mat-daterange-picker@0.0.2 --save
or
yarn add ngx-mat-daterange-picker@0.0.2 --save

NOTE: Angular Material requires the BrowserAnimationsModule and as per #5684 BrowserAnimationsModule should only be imported in your app/main module.

app.module.ts

import {BrowserAnimationsModule} from '@angular/platform-browser/animations';

@NgModule({
  ...
  imports: [BrowserAnimationsModule],
  ...
})

Peer Dependencies

Please note and install the following peer dependencies necessary for Angular v6

"peerDependencies": {
    "@angular/animations": "^9.1.0",
    "@angular/cdk": "^9.1.0",
    "@angular/material": "^9.1.0"
  }

Example

Import NgxMatDrpModule module in your application module.

app.module.ts

import { NgxMatDrpModule } from 'ngx-mat-daterange-picker';

@NgModule({
  ...,
  imports: [..., NgxMatDrpModule, ...],
  ...
})
export class AppModule { }

Setup the NgxDrpOptions configuration required by the component and the handler function to receive the Range object on Date selection.

app.component.ts

import { Component } from '@angular/core';
import { NgxDrpOptions, PresetItem, Range } from 'ngx-mat-daterange-picker';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  range:Range = {fromDate:new Date(), toDate: new Date()};
  options:NgxDrpOptions;
  presets:Array<PresetItem> = [];

  ngOnInit() {
    const today = new Date();
    const fromMin = new Date(today.getFullYear(), today.getMonth()-2, 1);
    const fromMax = new Date(today.getFullYear(), today.getMonth()+1, 0);
    const toMin = new Date(today.getFullYear(), today.getMonth()-1, 1);
    const toMax = new Date(today.getFullYear(), today.getMonth()+2, 0);

    this.setupPresets();
    this.options = {
                    presets: this.presets,
                    format: 'mediumDate',
                    range: {fromDate:today, toDate: today},
                    applyLabel: "Submit",
                    calendarOverlayConfig: {
                      shouldCloseOnBackdropClick: false,
                      hasBackDrop: false
                    }
                    // defaultUnselect: true,
                    // cancelLabel: "Cancel",
                    // excludeWeekends:true,
                    // fromMinMax: {fromDate:fromMin, toDate:fromMax},
                    // toMinMax: {fromDate:toMin, toDate:toMax}
                  };
  }
  
  // handler function that receives the updated date range object
  updateRange(range: Range){
    this.range = range;
  }  
  
  // helper function to create initial presets
  setupPresets() {

    const backDate = (numOfDays) => {
      const today = new Date();
      return new Date(today.setDate(today.getDate() - numOfDays));
    }
    
    const today = new Date();
    const yesterday = backDate(1);
    const minus7 = backDate(7)
    const minus30 = backDate(30);
    const currMonthStart = new Date(today.getFullYear(), today.getMonth(), 1);
    const currMonthEnd = new Date(today.getFullYear(), today.getMonth()+1, 0);
    const lastMonthStart = new Date(today.getFullYear(), today.getMonth()-1, 1);
    const lastMonthEnd = new Date(today.getFullYear(), today.getMonth(), 0);
    
    this.presets =  [
      {presetLabel: "Yesterday", range:{ fromDate:yesterday, toDate:today }},
      {presetLabel: "Last 7 Days", range:{ fromDate: minus7, toDate:today }},
      {presetLabel: "Last 30 Days", range:{ fromDate: minus30, toDate:today }},
      {presetLabel: "This Month", range:{ fromDate: currMonthStart, toDate:currMonthEnd }},
      {presetLabel: "Last Month", range:{ fromDate: lastMonthStart, toDate:lastMonthEnd }}
    ]
  }
}

Pass the reference of the new range selection handler function to selectedDateRangeChanged event emitter and the NgxDrpOptions options reference to the options input property.

app.compnent.html

<ngx-mat-drp (selectedDateRangeChanged)="updateRange($event)" [options]="options" #dateRangePicker></ngx-mat-drp>

Reset the date using ViewChild reference:

@ViewChild('dateRangePicker') dateRangePicker;

...

const today = new Date();
const resetRange = {fromDate: today, toDate: today};
this.dateRangePicker.resetDates(resetRange); // will trigger selectedDateRangeChanged

Configuration

export interface PresetItem {
    presetLabel: string;
    range: Range;
}

export interface Range {
    fromDate: Date;
    toDate: Date;
}

export interface CalendarOverlayConfig {
    panelClass?: string;
    hasBackdrop?: boolean;
    backdropClass?: string;
    shouldCloseOnBackdropClick?: boolean;
}

export interface NgxDrpOptions {
    presets: Array<PresetItem>;
    format: string;
    range: Range;
    excludeWeekends?: boolean;
    locale?: string;
    fromMinMax?: Range;
    toMinMax?: Range;
    applyLabel?: string;
    cancelLabel?: string;
    animation?: boolean;
    calendarOverlayConfig?: CalendarOverlayConfig;
    placeholder?: string;
    startDatePrefix?: string;
    endDatePrefix?: string;
}

Build

Run ng build to build the project. The build artifacts will be stored in the dist/ directory. Use the --prod flag for a production build.

Run npm run packagr to build the library project. The build artifacts will be stored in the dist/.

Running unit tests

Run ng test to execute the unit tests via Karma.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].