-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
414 lines (411 loc) · 14.4 KB
/
index.js
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
var dataKey = "Full_Name";
function findItem(items, key, withIndex) {
var item;
for (var i = 0; i < items.length; i++) {
item = items[i];
if (item[dataKey] === key) {
return withIndex ? { item, items, index: i } : item;
}
item = item.items && findItem(item.items, key, withIndex);
if (item) {
return item;
}
}
}
$(function () {
$("#employees").dxTreeList({
dataSource: {
key: dataKey,
load: function () {
return employees;
},
insert: function (values) {
var parentItem = findItem(employees, values.Parent_ID);
delete values.Parent_ID;
if (!parentItem) {
employees.push(values);
} else {
parentItem.items = parentItem.items || [];
parentItem.items.push(values);
}
},
update: function (key, values) {
var item = findItem(employees, key);
if (item) {
Object.assign(item, values);
}
},
remove: function (key) {
var itemWithIndex = findItem(employees, key, true);
if (itemWithIndex) {
itemWithIndex.items.splice(itemWithIndex.index, 1);
}
}
},
dataStructure: "tree",
keyExpr: dataKey,
itemsExpr: "items",
parentIdExpr: "Parent_ID",
columns: [{
dataField: "Title",
caption: "Position"
}, {
dataField: "Full_Name",
validationRules: [{ type: "required" }]
}, "City", "State", "Mobile_Phone", {
dataField: "Hire_Date",
dataType: "date"
}],
editing: {
mode: "cell",
allowAdding: true,
allowUpdating: true,
allowDeleting: true
},
expandedRowKeys: ["John Heart"],
showRowLines: true,
showBorders: true,
columnAutoWidth: true
});
});
var employees = [{
"Full_Name": "John Heart",
"Prefix": "Mr.",
"Title": "CEO",
"City": "Los Angeles",
"State": "California",
"Email": "[email protected]",
"Skype": "jheart_DX_skype",
"Mobile_Phone": "(213) 555-9392",
"Birth_Date": "1964-03-16",
"Hire_Date": "1995-01-15",
"items": [{
"Full_Name": "Samantha Bright",
"Prefix": "Dr.",
"Title": "COO",
"City": "Los Angeles",
"State": "California",
"Email": "[email protected]",
"Skype": "samanthab_DX_skype",
"Mobile_Phone": "(213) 555-2858",
"Birth_Date": "1966-05-02",
"Hire_Date": "2004-05-24",
"items": [{
"Full_Name": "Kevin Carter",
"Prefix": "Mr.",
"Title": "Shipping Manager",
"City": "San Diego",
"State": "California",
"Email": "[email protected]",
"Skype": "kevinc_DX_skype",
"Mobile_Phone": "(213) 555-2840",
"Birth_Date": "1978-01-09",
"Hire_Date": "2009-08-11",
"items": [{
"Full_Name": "Davey Jones",
"Prefix": "Mr.",
"Title": "Shipping Assistant",
"City": "Pasadena",
"State": "California",
"Email": "[email protected]",
"Skype": "davidj_DX_skype",
"Mobile_Phone": "(626) 555-0281",
"Birth_Date": "1983-03-06",
"Hire_Date": "2011-04-24"
}, {
"Full_Name": "Victor Norris",
"Prefix": "Mr.",
"Title": "Shipping Assistant",
"City": "Little Rock",
"State": "Arkansas",
"Email": "[email protected]",
"Skype": "victorn_DX_skype",
"Mobile_Phone": "(213) 555-9278",
"Birth_Date": "1986-07-23",
"Hire_Date": "2012-07-23"
}, {
"Full_Name": "Mary Stern",
"Prefix": "Ms.",
"Title": "Shipping Assistant",
"City": "Beaver",
"State": "Utah",
"Email": "[email protected]",
"Skype": "marys_DX_skype",
"Mobile_Phone": "(818) 555-7857",
"Birth_Date": "1982-04-08",
"Hire_Date": "2012-08-12"
}, {
"Full_Name": "Robin Cosworth",
"Prefix": "Mrs.",
"Title": "Shipping Assistant",
"City": "Los Angeles",
"State": "California",
"Email": "[email protected]",
"Skype": "robinc_DX_skype",
"Mobile_Phone": "(818) 555-0942",
"Birth_Date": "1981-06-12",
"Hire_Date": "2012-09-01"
}]
}]
}, {
"Full_Name": "Arthur Miller",
"Prefix": "Mr.",
"Title": "CTO",
"City": "Denver",
"State": "Colorado",
"Email": "[email protected]",
"Skype": "arthurm_DX_skype",
"Mobile_Phone": "(310) 555-8583",
"Birth_Date": "1972-07-11",
"Hire_Date": "2007-12-18",
"items": [{
"Full_Name": "Brett Wade",
"Prefix": "Mr.",
"Title": "IT Manager",
"City": "Reno",
"State": "Nevada",
"Email": "[email protected]",
"Skype": "brettw_DX_skype",
"Mobile_Phone": "(626) 555-0358",
"Birth_Date": "1968-12-01",
"Hire_Date": "2009-03-06",
"items": [{
"Full_Name": "Taylor Riley",
"Prefix": "Mr.",
"Title": "Network Admin",
"City": "San Jose",
"State": "California",
"Email": "[email protected]",
"Skype": "taylorr_DX_skype",
"Mobile_Phone": "(310) 555-7276",
"Birth_Date": "1982-08-14",
"Hire_Date": "2012-04-14"
}, {
"Full_Name": "Amelia Harper",
"Prefix": "Mrs.",
"Title": "Network Admin",
"City": "Los Angeles",
"State": "California",
"Email": "[email protected]",
"Skype": "ameliah_DX_skype",
"Mobile_Phone": "(213) 555-4276",
"Birth_Date": "1983-11-19",
"Hire_Date": "2011-02-10"
}, {
"Full_Name": "Wally Hobbs",
"Prefix": "Mr.",
"Title": "Programmer",
"City": "Chatsworth",
"State": "California",
"Email": "[email protected]",
"Skype": "wallyh_DX_skype",
"Mobile_Phone": "(818) 555-8872",
"Birth_Date": "1984-12-24",
"Hire_Date": "2011-02-17"
}, {
"Full_Name": "Brad Jameson",
"Prefix": "Mr.",
"Title": "Programmer",
"City": "San Fernando",
"State": "California",
"Email": "[email protected]",
"Skype": "bradleyj_DX_skype",
"Mobile_Phone": "(818) 555-4646",
"Birth_Date": "1988-10-12",
"Hire_Date": "2011-03-02"
}, {
"Full_Name": "Karen Goodson",
"Prefix": "Miss",
"Title": "Programmer",
"City": "South Pasadena",
"State": "California",
"Email": "[email protected]",
"Skype": "kareng_DX_skype",
"Mobile_Phone": "(626) 555-0908",
"Birth_Date": "1987-04-26",
"Hire_Date": "2011-03-14"
}, {
"Full_Name": "Morgan Kennedy",
"Prefix": "Mrs.",
"Title": "Graphic Designer",
"City": "San Fernando Valley",
"State": "California",
"Email": "[email protected]",
"Skype": "morgank_DX_skype",
"Mobile_Phone": "(818) 555-8238",
"Birth_Date": "1984-07-17",
"Hire_Date": "2012-01-11",
"items": [{
"Full_Name": "Violet Bailey",
"Prefix": "Ms.",
"Title": "Jr Graphic Designer",
"City": "La Canada",
"State": "California",
"Email": "[email protected]",
"Skype": "violetb_DX_skype",
"Mobile_Phone": "(818) 555-2478",
"Birth_Date": "1985-06-10",
"Hire_Date": "2012-01-19"
}]
}]
}, {
"Full_Name": "Barb Banks",
"Prefix": "Mrs.",
"Title": "Support Manager",
"City": "Phoenix",
"State": "Arizona",
"Email": "[email protected]",
"Skype": "barbarab_DX_skype",
"Mobile_Phone": "(310) 555-3355",
"Birth_Date": "1979-04-14",
"Hire_Date": "2002-08-07",
"items": [{
"Full_Name": "Kelly Rodriguez",
"Prefix": "Ms.",
"Title": "Support Assistant",
"City": "Boise",
"State": "Idaho",
"Email": "[email protected]",
"Skype": "kellyr_DX_skype",
"Mobile_Phone": "(818) 555-9248",
"Birth_Date": "1988-05-11",
"Hire_Date": "2012-10-13"
}, {
"Full_Name": "James Anderson",
"Prefix": "Mr.",
"Title": "Support Assistant",
"City": "Atlanta",
"State": "Georgia",
"Email": "[email protected]",
"Skype": "jamesa_DX_skype",
"Mobile_Phone": "(323) 555-4702",
"Birth_Date": "1987-01-29",
"Hire_Date": "2012-10-18"
}, {
"Full_Name": "Antony Remmen",
"Prefix": "Mr.",
"Title": "Support Assistant",
"City": "Boise",
"State": "Idaho",
"Email": "[email protected]",
"Skype": "anthonyr_DX_skype",
"Mobile_Phone": "(310) 555-6625",
"Birth_Date": "1986-02-19",
"Hire_Date": "2013-01-19"
}]
}]
}, {
"Full_Name": "Robert Reagan",
"Prefix": "Mr.",
"Title": "CMO",
"City": "Bentonville",
"State": "Arkansas",
"Email": "[email protected]",
"Skype": "robertr_DX_skype",
"Mobile_Phone": "(818) 555-2387",
"Birth_Date": "1974-09-07",
"Hire_Date": "2002-11-08",
"items": [{
"Full_Name": "Ed Holmes",
"Prefix": "Dr.",
"Title": "Sales Manager",
"City": "Malibu",
"State": "California",
"Email": "[email protected]",
"Skype": "edwardh_DX_skype",
"Mobile_Phone": "(310) 555-1288",
"Birth_Date": "1973-07-14",
"Hire_Date": "2005-06-19",
"items": [{
"Full_Name": "Sammy Hill",
"Prefix": "Mr.",
"Title": "Sales Assistant",
"City": "Pasadena",
"State": "California",
"Email": "[email protected]",
"Skype": "sammyh_DX_skype",
"Mobile_Phone": "(626) 555-7292",
"Birth_Date": "1984-02-17",
"Hire_Date": "2012-02-01"
}, {
"Full_Name": "Olivia Peyton",
"Prefix": "Mrs.",
"Title": "Sales Assistant",
"City": "Atlanta",
"State": "Georgia",
"Email": "[email protected]",
"Skype": "oliviap_DX_skype",
"Mobile_Phone": "(310) 555-2728",
"Birth_Date": "1981-06-03",
"Hire_Date": "2012-05-14"
}]
}]
}, {
"Full_Name": "Greta Sims",
"Prefix": "Ms.",
"Title": "HR Manager",
"City": "Atlanta",
"State": "Georgia",
"Email": "[email protected]",
"Skype": "gretas_DX_skype",
"Mobile_Phone": "(818) 555-6546",
"Birth_Date": "1977-11-22",
"Hire_Date": "1998-04-23",
"items": [{
"Full_Name": "Sandra Johnson",
"Prefix": "Mrs.",
"Title": "Controller",
"City": "Beaver",
"State": "Utah",
"Email": "[email protected]",
"Skype": "sandraj_DX_skype",
"Mobile_Phone": "(562) 555-2082",
"Birth_Date": "1974-11-15",
"Hire_Date": "2005-05-11"
}, {
"Full_Name": "Cindy Stanwick",
"Prefix": "Ms.",
"Title": "HR Assistant",
"City": "Little Rock",
"State": "Arkansas",
"Email": "[email protected]",
"Skype": "cindys_DX_skype",
"Mobile_Phone": "(818) 555-6655",
"Birth_Date": "1985-06-05",
"Hire_Date": "2008-03-24"
}, {
"Full_Name": "Marcus Orbison",
"Prefix": "Mr.",
"Title": "Travel Coordinator",
"City": "Los Angeles",
"State": "California",
"Email": "[email protected]",
"Skype": "marcuso_DX_skype",
"Mobile_Phone": "(213) 555-7098",
"Birth_Date": "1982-03-02",
"Hire_Date": "2005-05-19"
}, {
"Full_Name": "Sandy Bright",
"Prefix": "Ms.",
"Title": "Benefits Coordinator",
"City": "Denver",
"State": "Colorado",
"Email": "[email protected]",
"Skype": "sandrab_DX_skype",
"Mobile_Phone": "(818) 555-0524",
"Birth_Date": "1983-09-11",
"Hire_Date": "2005-06-04"
}, {
"Full_Name": "Ken Samuelson",
"Prefix": "Dr.",
"Title": "Ombudsman",
"City": "St. Louis",
"State": "Missouri",
"Email": "[email protected]",
"Skype": "kents_DX_skype",
"Mobile_Phone": "(562) 555-9282",
"Birth_Date": "1972-09-11",
"Hire_Date": "2009-04-22"
}]
}]
}];