|
| 1 | +# igx-date-range Component |
| 2 | + |
| 3 | +The `igx-date-range` component allows you to select a range of dates from a calendar which is presented into a single or two non-editable input fields. |
| 4 | + |
| 5 | +A getting started guide can be found [here](). |
| 6 | + |
| 7 | +## Dependencies |
| 8 | +In order to use the `igx-date-range` component you must import the `BrowserAnimationModule` **once** in your application: |
| 9 | +```typescript |
| 10 | +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
| 11 | +@NgModule({ |
| 12 | + imports: [ |
| 13 | + ... |
| 14 | + BrowserAnimationsModule |
| 15 | + ... |
| 16 | + ] |
| 17 | +}) |
| 18 | +export class AppModule { } |
| 19 | +``` |
| 20 | + |
| 21 | +# Usage |
| 22 | +Import the `IgxDateRangeModule` in the module that you want to use it in: |
| 23 | +```typescript |
| 24 | +import { IgxDateRangeModule } from 'igniteui-angular'; |
| 25 | + |
| 26 | +@NgModule({ |
| 27 | + imports: [IgxDateRangeModule] |
| 28 | +}) |
| 29 | +export class AppModule { } |
| 30 | +``` |
| 31 | + |
| 32 | +As for the component that you want to use `igx-date-range` in, import `IgxDateRangeComponent` and then declare it in the template, like so: |
| 33 | + |
| 34 | +```typescript |
| 35 | +import { IgxDateRangeComponent } from 'igniteui-angular'; |
| 36 | + |
| 37 | +@Component({ |
| 38 | + selector: 'my-component' |
| 39 | + template: ` |
| 40 | + <igx-date-range> |
| 41 | + <input igxDateRange> |
| 42 | + </igx-date-range>`, |
| 43 | + |
| 44 | +}) |
| 45 | +export class MyComponent { |
| 46 | + @ViewChild(IgxDateRangeComponent, { read: IgxDateRangeComponent, static: false }) |
| 47 | + public dateRange: IgxDateRangeComponent; |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +Basic initialization with a single input: |
| 52 | +```html |
| 53 | +<igx-date-range> |
| 54 | + <input igxDateRange> |
| 55 | +</igx-date-range> |
| 56 | +``` |
| 57 | + |
| 58 | +Basic initialization with two inputs: |
| 59 | +```html |
| 60 | +<igx-date-range> |
| 61 | + <input igxDateRangeStart> |
| 62 | + <input igxDateRangeEnd> |
| 63 | +</igx-date-range> |
| 64 | +``` |
| 65 | + |
| 66 | +`IgxDateRange` with `Today` and `Done` buttons: |
| 67 | +```html |
| 68 | +<igx-date-range [todayButtonText]="'Show Today'" [doneButtonText]="'Close'"> |
| 69 | + <input igxDateRage> |
| 70 | +</igx-date-range> |
| 71 | +``` |
| 72 | + |
| 73 | +`IgxDateRange` with first day of the week set to `Monday` and handler when a range selection is made: |
| 74 | +```html |
| 75 | +<igx-date-range [weekStart]="2" (rangeSelected)="onRangeSelected($event)"> |
| 76 | + <input igxDateRange> |
| 77 | +</igx-date-range> |
| 78 | +``` |
| 79 | + |
| 80 | +`IgxDateRange` that opens a calendar with more than `2` views and also hides days that are not part of each month: |
| 81 | +```html |
| 82 | +<igx-date-range [monthsViewNumber]="5" [hideOutsideDays]="'true'"> |
| 83 | + <input igxDateRange> |
| 84 | +</igx-date-range> |
| 85 | +``` |
| 86 | + |
| 87 | +`IgxDateRange` in a drop `down-mode`, the `Done` button is only visible when in a `dialog` mode: |
| 88 | +```html |
| 89 | +<igx-date-range [mode]="'dropdown'"> |
| 90 | + <input igxDateRange> |
| 91 | +</igx-date-range> |
| 92 | +``` |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | +# API |
| 97 | + |
| 98 | +### Inputs |
| 99 | +| Name | Type | Description | |
| 100 | +|:-----------------|:-------------------|:------------| |
| 101 | +| mode | InteractionMode | Property which sets whether `IgxDateRangeComponent` is in dialog or dropdown mode. | |
| 102 | +| monthsViewNumber | number | Property which sets the number displayed month views. Default is `2`. | |
| 103 | +| hideOutsideDays | boolean | Property which sets the whether dates that are not part of the current month will be displayed. Default value is `false`. | |
| 104 | +| weekStart | number | Property which sets the start day of the week. Can be assigned to a numeric value or to `WEEKDAYS` enum value. | |
| 105 | +| locale | string | Property which gets the `locale` of the calendar. Default value is `"en"`. | |
| 106 | +| formatter | function => string | Property that applies a custom formatter function on the selected or passed date. | |
| 107 | +| todayButtonText | string | Property that changes the default text of the `today` button. Default value is `Today`. | |
| 108 | +| doneButtonText | string | Property that changes the default text of the `done` button. It will show up only in `dialog` mode. Default value is `Done`. | |
| 109 | +| overlaySettings | OverlaySettings | Property that changes the default overlay settings used by the `IgxDateRangeComponent`. | |
| 110 | + |
| 111 | +### Outputs |
| 112 | +| Name | Type | Description | |
| 113 | +|:-----------------|:----------------------|:------------| |
| 114 | +| rangeSelected | IgxDateRangeComponent | An event that is emitted when a full range was selected in the `IgxDateRangeComponent`. | |
| 115 | +| onOpened | IgxDateRangeComponent | An event that is emitted when the `IgxDateRangeComponent` is opened. | |
| 116 | +| onClosed | IgxDateRangeComponent | An event that is emitted when the `IgxDateRangeComponent` is closed. | |
| 117 | + |
| 118 | +### Methods |
| 119 | +| Name | Arguments | Return Type | Description | |
| 120 | +|:-----------:|:--------------|:------------|:------------| |
| 121 | +| open | n/a | void | Opens the date picker's dropdown or dialog. | |
| 122 | +| close | n/a | void | Closes the date picker's dropdown or dialog. | |
| 123 | +| selectToday | n/a | void | Selects the today date if no previous selection is made. If there is a previous selection, it does a range selection to today. | |
| 124 | +| value | n/a | Date or Date[] | Gets the currently selected value / range from the calendar. | |
| 125 | +| selectRange | startDate, endDate | void | Selects a range of dates, cancels previous selection. | |
0 commit comments