|
1 |
| -<template> |
2 |
| - <div id="app"> |
3 |
| - <DxDataGrid |
4 |
| - ref="grid" |
5 |
| - :data-source="{ store: employeeStore }" |
6 |
| - :show-borders="true" |
7 |
| - :repaint-changes-only="true" |
8 |
| - > |
9 |
| - <DxEditing |
10 |
| - :allow-updating="true" |
11 |
| - :allow-adding="true" |
12 |
| - :allow-deleting="true" |
13 |
| - :use-icons="true" |
14 |
| - mode="popup" |
15 |
| - /> |
16 |
| - <DxColumn data-field="FirstName" data-type="string" /> |
17 |
| - <DxColumn data-field="LastName" data-type="string" /> |
18 |
| - <DxColumn data-field="BirthDate" data-type="date" /> |
19 |
| - <DxColumn data-field="Position" data-type="string" :width="170" /> |
20 |
| - <DxColumn data-field="HireDate" data-type="date" /> |
21 |
| - <DxColumn data-field="Address" data-type="string" /> |
22 |
| - <DxColumn type="buttons"> |
23 |
| - <DxButton name="edit" :on-click="editRow" /> |
24 |
| - <DxButton name="delete" /> |
25 |
| - </DxColumn> |
26 |
| - <DxToolbar> |
27 |
| - <DxItem |
28 |
| - location="after" |
29 |
| - template="addRowTemplate" |
30 |
| - /> |
31 |
| - </DxToolbar> |
32 |
| - |
33 |
| - <template #addRowTemplate> |
34 |
| - <DxAddRowButton |
35 |
| - icon="plus" |
36 |
| - @click="addRow" |
37 |
| - /> |
38 |
| - </template> |
39 |
| - </DxDataGrid> |
40 |
| - |
41 |
| - <DxPopup |
42 |
| - :title="this.isNewRecord ? 'Add' : 'Edit'" |
43 |
| - height="auto" |
44 |
| - :close-on-outside-click="true" |
45 |
| - :visible.sync="visible" |
46 |
| - > |
47 |
| - <DxToolbarItem |
48 |
| - widget="dxButton" |
49 |
| - location="after" |
50 |
| - toolbar="bottom" |
51 |
| - :options="{ |
52 |
| - text: 'Confirm', |
53 |
| - type: 'success', |
54 |
| - onClick: confirmChanges |
55 |
| - }" |
56 |
| - /> |
57 |
| - <DxToolbarItem |
58 |
| - widget="dxButton" |
59 |
| - location="after" |
60 |
| - toolbar="bottom" |
61 |
| - :options="{ |
62 |
| - text: 'Cancel', |
63 |
| - onClick: hidePopup |
64 |
| - }" |
65 |
| - /> |
66 |
| - |
67 |
| - <DxForm |
68 |
| - :validationGroup="validationGroupName" |
69 |
| - :form-data.sync="formData" |
70 |
| - > |
71 |
| - <DxGroupItem |
72 |
| - :col-count="2" |
73 |
| - > |
74 |
| - <DxSimpleItem data-field="FirstName" :validation-rules="validationRules.firstName" > |
75 |
| - <DxLabel template="nameLabel" /> |
76 |
| - </DxSimpleItem> |
77 |
| - |
78 |
| - <DxSimpleItem data-field="Position" editor-type="dxSelectBox" :editor-options="positionEditorOptions" > |
79 |
| - <DxLabel template="positionLabel" /> |
80 |
| - </DxSimpleItem> |
81 |
| - |
82 |
| - <DxSimpleItem data-field="LastName" :validation-rules="validationRules.lastName" > |
83 |
| - <DxLabel template="nameLabel" /> |
84 |
| - </DxSimpleItem> |
85 |
| - |
86 |
| - <DxSimpleItem data-field="Address"> |
87 |
| - <DxLabel template="addressLabel" /> |
88 |
| - </DxSimpleItem> |
89 |
| - |
90 |
| - <DxSimpleItem data-field="BirthDate" editor-type="dxDateBox" :validation-rules="validationRules.birthDate" > |
91 |
| - <DxLabel template="dateLabel" /> |
92 |
| - </DxSimpleItem> |
93 |
| - |
94 |
| - <DxSimpleItem data-field="HireDate" editor-type="dxDateBox" > |
95 |
| - <DxLabel template="dateLabel" /> |
96 |
| - </DxSimpleItem> |
97 |
| - |
98 |
| - <DxSimpleItem data-field="Notes" :col-span="2" editor-type="dxTextArea" :editor-options="notesEditorOptions"> |
99 |
| - <DxLabel template="notesLabel" /> |
100 |
| - </DxSimpleItem> |
101 |
| - |
102 |
| - <DxSimpleItem data-field="Phone" :editor-options="phoneEditorOptions" :validation-rules="validationRules.phone"> |
103 |
| - <DxLabel template="phoneLabel" /> |
104 |
| - </DxSimpleItem> |
105 |
| - |
106 |
| - <DxSimpleItem data-field="Email" :validation-rules="validationRules.email"> |
107 |
| - <DxLabel template="emailLabel" /> |
108 |
| - </DxSimpleItem> |
109 |
| - </DxGroupItem> |
| 1 | +<script setup lang="ts"> |
| 2 | +import { RouterView } from 'vue-router'; |
| 3 | +</script> |
110 | 4 |
|
111 |
| - <template #nameLabel="{ data }"> |
112 |
| - <LabelTemplate |
113 |
| - :data="data" |
114 |
| - icon="user" |
115 |
| - /> |
116 |
| - </template> |
117 |
| - <template #positionLabel="{ data }"> |
118 |
| - <LabelTemplate |
119 |
| - :data="data" |
120 |
| - icon="info" |
121 |
| - /> |
122 |
| - </template> |
123 |
| - <template #dateLabel="{ data }"> |
124 |
| - <LabelTemplate |
125 |
| - :data="data" |
126 |
| - icon="event" |
127 |
| - /> |
128 |
| - </template> |
129 |
| - <template #addressLabel="{ data }"> |
130 |
| - <LabelTemplate |
131 |
| - :data="data" |
132 |
| - icon="home" |
133 |
| - /> |
134 |
| - </template> |
135 |
| - <template #notesLabel="{ data }"> |
136 |
| - <LabelNotesTemplate |
137 |
| - :data="data" |
138 |
| - /> |
139 |
| - </template> |
140 |
| - <template #phoneLabel="{ data }"> |
141 |
| - <LabelTemplate |
142 |
| - :data="data" |
143 |
| - icon="tel" |
144 |
| - /> |
145 |
| - </template> |
146 |
| - <template #emailLabel="{ data }"> |
147 |
| - <LabelTemplate |
148 |
| - :data="data" |
149 |
| - icon="email" |
150 |
| - /> |
151 |
| - </template> |
152 |
| - </DxForm> |
153 |
| - </DxPopup> |
154 |
| - </div> |
| 5 | +<template> |
| 6 | + <div class="main"> |
| 7 | + <RouterView/> |
| 8 | + </div> |
155 | 9 | </template>
|
156 |
| - |
157 |
| -<script> |
158 |
| -import DxDataGrid, { DxColumn, DxButton, DxEditing, DxToolbar, DxItem } from 'devextreme-vue/data-grid'; |
159 |
| -import DxPopup, { DxToolbarItem } from 'devextreme-vue/popup' |
160 |
| -import DxForm, { DxSimpleItem, DxLabel, DxGroupItem } from 'devextreme-vue/form'; |
161 |
| -import DxAddRowButton from 'devextreme-vue/button'; |
162 |
| -import validationEngine from 'devextreme/ui/validation_engine'; |
163 |
| -import 'devextreme-vue/text-area'; |
164 |
| -
|
165 |
| -import LabelTemplate from './LabelTemplate.vue'; |
166 |
| -import LabelNotesTemplate from './LabelNotesTemplate.vue'; |
167 |
| -
|
168 |
| -import ArrayStore from 'devextreme/data/array_store'; |
169 |
| -
|
170 |
| -import { employees, positions } from './data.js'; |
171 |
| -
|
172 |
| -const employeeStore = new ArrayStore({ |
173 |
| - data: employees, |
174 |
| - key: 'ID', |
175 |
| -}); |
176 |
| -
|
177 |
| -export default { |
178 |
| - name: "App", |
179 |
| - components: { |
180 |
| - DxDataGrid, |
181 |
| - DxColumn, |
182 |
| - DxButton, |
183 |
| - DxEditing, |
184 |
| - DxToolbar, |
185 |
| - DxItem, |
186 |
| - DxAddRowButton, |
187 |
| - DxPopup, |
188 |
| - DxToolbarItem, |
189 |
| - DxForm, |
190 |
| - DxSimpleItem, |
191 |
| - DxLabel, |
192 |
| - DxGroupItem, |
193 |
| - LabelTemplate, |
194 |
| - LabelNotesTemplate, |
195 |
| - }, |
196 |
| - data() { |
197 |
| - return { |
198 |
| - formData: {}, |
199 |
| - isNewRecord: null, |
200 |
| - visible: false, |
201 |
| - employeeStore, |
202 |
| - validationGroupName: "gridForm", |
203 |
| - positionEditorOptions: { items: positions, searchEnabled: true }, |
204 |
| - notesEditorOptions: { height: 90, maxLength: 200 }, |
205 |
| - phoneEditorOptions: { |
206 |
| - mask: "+1 (X00) 000-0000", |
207 |
| - maskRules: { X: /[02-9]/ }, |
208 |
| - maskInvalidMessage: "The phone must have a correct USA phone format", |
209 |
| - }, |
210 |
| - validationRules: { |
211 |
| - firstName: [{ type: "required", message: "First Name is required." }], |
212 |
| - lastName: [{ type: "required", message: "Last Name is required." }], |
213 |
| - phone: [{ type: "required", message: "Phone number is required." }], |
214 |
| - email: [{ type: "email", message: "Email is incorrect." }], |
215 |
| - birthDate: [ |
216 |
| - { |
217 |
| - type: "required", |
218 |
| - message: "Birth Date is required.", |
219 |
| - invalidDateMessage: "The date must have the following format: mm/dd/yyyy", |
220 |
| - }, |
221 |
| - ] |
222 |
| - } |
223 |
| - } |
224 |
| - }, |
225 |
| - methods: { |
226 |
| - showPopup(isNewRecord, formData) { |
227 |
| - this.formData = formData; |
228 |
| - this.isNewRecord = isNewRecord; |
229 |
| - this.visible = true; |
230 |
| - }, |
231 |
| - addRow() { |
232 |
| - this.showPopup(true, {}); |
233 |
| - }, |
234 |
| - editRow(e) { |
235 |
| - this.showPopup(false, {...e.row.data}); |
236 |
| - }, |
237 |
| - confirmChanges() { |
238 |
| - const result = validationEngine.validateGroup(this.validationGroupName); |
239 |
| -
|
240 |
| - if (!result.isValid) |
241 |
| - return; |
242 |
| -
|
243 |
| - if (this.isNewRecord) |
244 |
| - this.employeeStore.insert(this.formData); |
245 |
| - else |
246 |
| - this.employeeStore.update(this.formData["ID"], this.formData); |
247 |
| -
|
248 |
| - this.grid.refresh(true); |
249 |
| - this.hidePopup(); |
250 |
| - }, |
251 |
| - hidePopup() { |
252 |
| - this.visible = false; |
253 |
| - } |
254 |
| - }, |
255 |
| - computed: { |
256 |
| - grid: function() { |
257 |
| - return this.$refs.grid.instance; |
258 |
| - } |
259 |
| - } |
260 |
| -} |
261 |
| -</script> |
0 commit comments