-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from DevExpress-Examples/Angular-example
Angular example
- Loading branch information
Showing
10 changed files
with
109 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,24 @@ | ||
<div class="default-style"> | ||
<dx-button [text]="buttonText" (onClick)="onClick($event)"></dx-button> | ||
</div> | ||
<dx-date-box | ||
[value]="now" | ||
type="date" | ||
[width]="400" | ||
label="Date with the short year" | ||
[displayFormat]="format" | ||
> | ||
</dx-date-box> | ||
<dx-data-grid | ||
id="grid" | ||
[dataSource]="employees" | ||
[width]="400" | ||
keyExpr="ID" | ||
[showBorders]="true" | ||
> | ||
<dxo-editing mode="cell" [allowUpdating]="true"></dxo-editing> | ||
<dxi-column dataField="FirstName"></dxi-column> | ||
<dxi-column dataField="LastName"></dxi-column> | ||
<dxi-column | ||
dataField="BirthDate" | ||
dataType="date" | ||
[editorOptions]="editorOptions" | ||
></dxi-column> | ||
</dx-data-grid> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
.default-style { | ||
margin: 50px; | ||
.demo-container { | ||
margin: 100px; | ||
width: 90vh; | ||
} | ||
|
||
|
||
#grid { | ||
margin-top: 50px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
import { Component } from '@angular/core'; | ||
import { ClickEvent } from 'devextreme/ui/button'; | ||
import { Format } from 'devextreme/localization'; | ||
import { formatter, parser } from '../utils'; | ||
import { Employee, Service } from './app.service'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.scss'], | ||
providers: [Service], | ||
}) | ||
export class AppComponent { | ||
title = 'Angular'; | ||
employees: Employee[]; | ||
|
||
counter = 0; | ||
now: Date = new Date(); | ||
|
||
buttonText = 'Click count: 0'; | ||
format: Format = { | ||
parser: (val) => parser(val), | ||
formatter: (val) => formatter(val), | ||
}; | ||
|
||
onClick(e: ClickEvent): void { | ||
this.counter++; | ||
this.buttonText = `Click count: ${this.counter}`; | ||
editorOptions = { | ||
displayFormat: this.format, | ||
}; | ||
|
||
constructor(service: Service) { | ||
this.employees = service.getEmployees(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
export interface Employee { | ||
ID: number; | ||
|
||
FirstName: string; | ||
|
||
LastName: string; | ||
|
||
Prefix: string; | ||
|
||
Position: string; | ||
|
||
BirthDate: string; | ||
|
||
HireDate: string; | ||
|
||
Address: string; | ||
} | ||
|
||
const employees: Employee[] = [{ | ||
ID: 1, | ||
FirstName: 'John', | ||
LastName: 'Heart', | ||
Prefix: 'Mr.', | ||
Position: 'CEO', | ||
BirthDate: '1964/03/16', | ||
HireDate: '1995/01/15', | ||
Address: '351 S Hill St.', | ||
}, { | ||
ID: 2, | ||
FirstName: 'Olivia', | ||
LastName: 'Peyton', | ||
Prefix: 'Mrs.', | ||
Position: 'Sales Assistant', | ||
BirthDate: '1981/06/03', | ||
HireDate: '2012/05/14', | ||
Address: '807 W Paseo Del Mar', | ||
}]; | ||
|
||
@Injectable() | ||
export class Service { | ||
getEmployees(): Employee[] { | ||
return employees; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export function parser(value: string): Date | number { | ||
const parts = value.split('/'); | ||
if (parts.length !== 3) return Date.parse(value); | ||
let year = Number(parts[2]); | ||
if (year < 100) year += 2000; | ||
return new Date(year, Number(parts[0]) - 1, Number(parts[1])); | ||
} | ||
|
||
export function formatter(value: number | Date): string { | ||
return typeof value !== 'number' ? value.toLocaleDateString() : ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters