-
Notifications
You must be signed in to change notification settings - Fork 672
Expand file tree
/
Copy pathapp.component.ts
More file actions
96 lines (79 loc) · 2.4 KB
/
app.component.ts
File metadata and controls
96 lines (79 loc) · 2.4 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import {ChangeDetectionStrategy, Component, enableProdMode, provideZoneChangeDetection} from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { DxNumberBoxModule, DxCheckBoxModule, DxSelectBoxModule } from 'devextreme-angular';
import { DataSource } from 'devextreme-angular/common/data';
import { DxSelectBoxTypes } from 'devextreme-angular/ui/select-box';
import { Product, Service, SimpleProduct } from './app.service';
if (!/localhost/.test(document.location.host)) {
enableProdMode();
}
let modulePrefix = '';
// @ts-ignore
if (window && window.config?.packageConfigPaths) {
modulePrefix = '/app';
}
@Component({
changeDetection: ChangeDetectionStrategy.Eager,
selector: 'demo-app',
templateUrl: `.${modulePrefix}/app.component.html`,
styleUrls: [`.${modulePrefix}/app.component.css`],
providers: [Service],
imports: [
DxSelectBoxModule,
DxNumberBoxModule,
DxCheckBoxModule,
],
})
export class AppComponent {
products: Product[];
simpleProducts: SimpleProduct[];
productsDataSource: DataSource;
product: number;
searchModeOption = 'contains';
searchExprOption = 'Name';
searchTimeoutOption = 200;
minSearchLengthOption = 0;
showDataBeforeSearchOption = false;
searchExprOptionItems = [{
name: "'Name'",
value: 'Name',
}, {
name: "['Name', 'Category']",
value: ['Name', 'Category'],
}];
constructor(service: Service) {
this.products = service.getProducts();
this.simpleProducts = service.getSimpleProducts();
this.product = this.simpleProducts[0].ID;
this.productsDataSource = new DataSource({
store: {
data: this.simpleProducts,
type: 'array',
key: 'ID',
},
});
}
addCustomItem(data: DxSelectBoxTypes.CustomItemCreatingEvent) {
if (!data.text) {
data.customItem = null;
return;
}
const productIds = this.simpleProducts.map((item) => item.ID);
const incrementedId = Math.max.apply(null, productIds) + 1;
const newItem = {
Name: data.text,
ID: incrementedId,
};
data.customItem = this.productsDataSource.store().insert(newItem)
.then(() => this.productsDataSource.load())
.then(() => newItem)
.catch((error) => {
throw error;
});
}
}
bootstrapApplication(AppComponent, {
providers: [
provideZoneChangeDetection({ eventCoalescing: true, runCoalescing: true }),
],
});