-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.component.ts
58 lines (50 loc) · 1.86 KB
/
app.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Component, ViewChild, AfterViewChecked } from '@angular/core';
import { DxDataGridComponent, DxDataGridTypes } from 'devextreme-angular/ui/data-grid';
import notify from 'devextreme/ui/notify';
import { Customer, Service } from './app.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
providers: [Service],
})
export class AppComponent implements AfterViewChecked {
@ViewChild(DxDataGridComponent, { static: false }) dataGrid: DxDataGridComponent | undefined;
checked = false;
changes: DxDataGridTypes.DataChange[] = [];
pattern = /^\(\d{3}\) \d{3}-\d{4}$/i;
customers: Customer[];
constructor(service: Service) {
this.customers = service.getCustomers();
this.validateVisibleRows = this.validateVisibleRows.bind(this);
}
validateVisibleRows(): void {
const dataGridInstance = this?.dataGrid?.instance;
const fakeChanges = dataGridInstance
? dataGridInstance.getVisibleRows().map((row: DxDataGridTypes.Row): DxDataGridTypes.DataChange => ({ type: 'update', key: row.key, data: {} }))
: [];
this.changes = [...this.changes, ...fakeChanges];
this.checked = true;
}
ngAfterViewChecked(): void {
if (this.changes.length && this.checked) {
this.checked = false;
const dataGridInstance = this?.dataGrid?.instance;
dataGridInstance?.repaint();
// @ts-expect-error - getController is a private method
dataGridInstance?.getController('validating').validate(true).then((result: Boolean) => {
const message = result ? 'Validation is passed' : 'Validation is failed';
const type = result ? 'success' : 'error';
notify({
message,
type,
position: {
offset: '0 50',
at: 'bottom',
of: '.demo-container',
},
});
});
}
}
}