Class IgxDatePickerComponent

Ignite UI for Angular Date Picker - Documentation

The Ignite UI Date Picker displays a popup calendar that lets users select a single date.

Example:

<igx-date-picker [(ngModel)]="selectedDate"></igx-date-picker>

Hierarchy

  • IgxDatePickerComponent

Implements

  • IDatePicker
  • ControlValueAccessor
  • EditorProvider
  • OnInit
  • AfterViewInit
  • OnDestroy

Constructors

constructor

Properties

calendar

cancelButtonLabel

cancelButtonLabel: string

An @Input property that renders cancel button with custom label.

<igx-date-picker cancelButtonLabel="Close" todayButtonLabel="Today"></igx-date-picker>

collapsed

collapsed: boolean = true

dateFormatParts

dateFormatParts: any[] = []

disabled

disabled: boolean

An @Input property that disables the IgxDatePickerComponent.

<igx-date-picker [disabled]="'true'" cancelButtonLabel="cancel" todayButtonLabel="today"></igx-date-picker>

displayValuePipe

displayValuePipe: DatePickerDisplayValuePipe = new DatePickerDisplayValuePipe(this)

element

element: ElementRef

formatter

formatter: function

An @Input property that applies a custom formatter function on the selected or passed date.

public date: Date = new Date();
private dayFormatter = new Intl.DateTimeFormat("en", { weekday: "long" });
private monthFormatter = new Intl.DateTimeFormat("en", { month: "long" });
public formatter = (date: Date) => { return `You selected
                    ${this.dayFormatter.format(date)},
                    ${date.getDate()} ${this.monthFormatter.format(date)},
                    ${date.getFullYear()}`;
}
<igx-date-picker [value]="date" [formatter]="formatter"></igx-date-picker>

Type declaration

    • (val: Date): string
    • Parameters

      • val: Date

      Returns string

hasHeader

hasHeader: boolean = true

id

id: string = `igx-date-picker-${NEXT_ID++}`

An @Input property that sets the value of id attribute. If not provided it will be automatically generated.

<igx-date-picker [id]="'igx-date-picker-3'" cancelButtonLabel="cancel" todayButtonLabel="today"></igx-date-picker>

inputMask

inputMask: string

inputValuePipe

inputValuePipe: DatePickerInputValuePipe = new DatePickerInputValuePipe(this)

invalidDate

invalidDate: string = ""

isEmpty

isEmpty: boolean = true

isSpinLoop

isSpinLoop: boolean = true

An @Input property that sets whether the IgxDatePickerComponent date parts would spin continuously or stop when min/max is reached.

<igx-date-picker [isSpinLoop]="false"></igx-date-picker>

label

label: string = "Date"

An @Input property that sets the IgxDatePickerComponent label. The default label is 'Date'.

<igx-date-picker [label]="Calendar"></igx-date-picker>

labelVisibility

labelVisibility: boolean = true

An @Input property that sets the IgxDatePickerComponent label visibility. By default the visibility is set to true. <igx-date-picker [labelVisibility]="false">

locale

locale: "en"

An @Input property that sets locales. Default locale is en.

<igx-date-picker locale="ja-JP" [value]="date"></igx-date-picker>

mask

mask: string

Returns the date mask of the IgxDatePickerComponent when in editable dropdown mode.

@ViewChild("MyDatePicker")
public datePicker: IgxDatePickerComponent;
ngAfterViewInit(){
   let mask = this.datePicker.mask;
}

mode

mode: InteractionMode = InteractionMode.Dialog

An @Input property that sets whether IgxDatePickerComponent is in dialog or drop down mode.

<igx-date-picker mode="dropdown"></igx-date-picker>

onClosed

onClosed: EventEmitter<IgxDatePickerComponent> = new EventEmitter<IgxDatePickerComponent>()

An event that is emitted after the IgxDatePickerComponent is closed.

onClosing

onClosing: EventEmitter<CancelableBrowserEventArgs> = new EventEmitter<CancelableBrowserEventArgs>()

An event that is emitted when the IgxDatePickerComponent is being closed.

onDisabledDate

onDisabledDate: EventEmitter<IDatePickerDisabledDateEventArgs> = new EventEmitter<IDatePickerDisabledDateEventArgs>()

An @Output property that fires when the user types/spins to a disabled date in the date-picker editor.

public onDisabledDate(event){
   alert("This date is disabled!");
}
<igx-date-picker (onDisabledDate)="onDisabledDate($event)"></igx-date-picker>

onOpened

onOpened: EventEmitter<IgxDatePickerComponent> = new EventEmitter<IgxDatePickerComponent>()

An event that is emitted when the IgxDatePickerComponent calendar is opened.

onSelection

onSelection: EventEmitter<Date> = new EventEmitter<Date>()

An @Output property that is fired when selection is made in the calendar.

public selection(event){
   alert("A date has been selected!");
}
<igx-date-picker (onSelection)="selection($event)" cancelButtonLabel="cancel" todayButtonLabel="today"></igx-date-picker>

onValidationFailed

onValidationFailed: EventEmitter<IDatePickerValidationFailedEventArgs> = new EventEmitter<IDatePickerValidationFailedEventArgs>()

An @Output property that fires when the user types/spins invalid date in the date-picker editor.

public onValidationFailed(event){
   alert("This date is not valid!");
}
<igx-date-picker (onValidationFailed)="onValidationFailed($event)"></igx-date-picker>

outlet

outlet: IgxOverlayOutletDirective | ElementRef

Determines the container the popup element should be attached to.

<div igxOverlayOutlet #outlet="overlay-outlet"></div>
//..
<igx-date-picker [outlet]="outlet"></igx-date-picker>
//..

Where outlet is an instance of IgxOverlayOutletDirective or an ElementRef.

rawDateString

rawDateString: string

todayButtonLabel

todayButtonLabel: string

An @Input property that renders today button with custom label.

<igx-date-picker cancelButtonLabel="cancel" todayButtonLabel="Tomorrow"></igx-date-picker>

valueChange

valueChange: EventEmitter<Date> = new EventEmitter<Date>()

An @Output property that is fired when date picker value is changed.

public valueChanged(event){
   alert("Date picker value is changed");
}
<igx-date-picker (valueChange)="valueChanged($event)" mode="dropdown"></igx-date-picker>

vertical

vertical: boolean = false

An @Input property that sets the orientation of the IgxDatePickerComponent header.

<igx-date-picker [vertical]="'true'" cancelButtonLabel="cancel" todayButtonLabel="today"></igx-date-picker>

weekStart

weekStart: WEEKDAYS | number = WEEKDAYS.SUNDAY

An @Input property that sets on which day the week starts.

<igx-date-picker [weekStart]="WEEKDAYS.FRIDAY" cancelButtonLabel="cancel" todayButtonLabel="today"></igx-date-picker>

Accessors

context

  • get context(): object

disabledDates

displayData

  • get displayData(): string
  • Returns the formatted date when IgxDatePickerComponent is in dialog mode.

    @ViewChild("MyDatePicker")
    public datePicker: IgxDatePickerComponent;
    public selection(event){
       let selectedDate = this.datePicker.displayData;
       alert(selectedDate);
    }
    <igx-date-picker #MyDatePicker (onSelection)="selection()" todayButtonLabel="today"></igx-date-picker>

    Returns string

dropDownOverlaySettings

format

  • get format(): string
  • set format(format: string): void
  • Returns the date display format of the IgxDatePickerComponent in dropdown mode.

    @ViewChild("MyDatePicker")
    public datePicker: IgxDatePickerComponent;
    ngAfterViewInit(){
       let format = this.datePicker.format;
    }

    Returns string

  • Sets the date format of the IgxDatePickerComponent when in editable dropdown mode.

    @ViewChild("MyDatePicker")
    public datePicker: IgxDatePickerComponent;
    this.datePicker.format = 'yyyy-M-d';
    }

    Parameters

    • format: string

    Returns void

formatOptions

  • Returns the format options of the IgxDatePickerComponent.

    @ViewChild("MyDatePicker")
    public datePicker: IgxDatePickerComponent;
    ngAfterViewInit(){
       let formatOptions = this.datePicker.formatOptions;
    }

    Returns IFormatOptions

  • Sets the format options of the IgxDatePickerComponent.

    public Options;
    @ViewChild("MyDatePicker")
    public datePicker: IgxDatePickerComponent;
    ngAfterViewInit(){
       this.Options = {
           day: "numeric",
           month: "long",
           weekday: "long",
           year: "numeric"
       }
    this.datePicker.formatOptions = this.Options;
    }

    Parameters

    Returns void

formatViews

  • Returns the format views of the IgxDatePickerComponent.

    @ViewChild("MyDatePicker")
    public datePicker: IgxDatePickerComponent;
    ngAfterViewInit(){
       let formatViews = this.datePicker.formatViews;
    }

    Returns IFormatViews

  • Sets the format views of the IgxDatePickerComponent.

    public Views;
    @ViewChild("MyDatePicker")
    public datePicker: IgxDatePickerComponent;
    ngAfterViewInit(){
       this.Views = {day:false, month: false, year:false};
       this.datePicker.formatViews = this.Views;
    }

    Parameters

    Returns void

modalOverlaySettings

onClose

onOpen

specialDates

template

  • get template(): TemplateRef<any>

transformedDate

  • get transformedDate(): string
  • set transformedDate(value: string): void

value

  • get value(): Date
  • set value(date: Date): void

Methods

deselectDate

  • deselectDate(): void

selectDate

  • selectDate(date: Date): void
  • Change the calendar selection and calling this method will emit the @calendar.onSelection event, which will fire @handleSelection method.

    @ViewChild("MyDatePicker")
    public datePicker: IgxDatePickerComponent;
    ngAfterViewInit(){
    this.datePicker.selectDate(this.date);
    }
    memberof

    IgxDatePickerComponent

    Parameters

    • date: Date

      passed date that has to be set to the calendar.

    Returns void

triggerTodaySelection

  • triggerTodaySelection(): void
  • Selects today's date from calendar and change the input field value, @calendar.viewDate and @calendar.value.

    @ViewChild("MyDatePicker")
    public datePicker: IgxDatePickerComponent;
    ngAfterViewInit(){
    this.datePicker.triggerTodaySelection();
    }
    memberof

    IgxDatePickerComponent

    Returns void

writeValue

  • writeValue(value: Date): void
  • Method that sets the selected date.

    public date = new Date();
    @ViewChild("MyDatePicker")
    public datePicker: IgxDatePickerComponent;
    ngAfterViewInit(){
       this.datePicker.writeValue(this.date);
    }
    memberof

    IgxDatePickerComponent

    Parameters

    • value: Date

      The date you want to select.

    Returns void