aio-table 8.0.1 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.css +169 -159
- package/index.d.ts +98 -0
- package/index.js +449 -2898
- package/package.json +26 -28
- package/README.md +0 -792
package/index.js
CHANGED
|
@@ -1,2898 +1,449 @@
|
|
|
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
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
} else if (!_childs.length) {
|
|
451
|
-
icon = /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
452
|
-
path: _js.mdiCircleMedium,
|
|
453
|
-
size: 0.8
|
|
454
|
-
});
|
|
455
|
-
} else {
|
|
456
|
-
icon = /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
457
|
-
path: _open ? _js.mdiChevronDown : rtl ? _js.mdiChevronLeft : _js.mdiChevronRight,
|
|
458
|
-
size: 0.8
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
return {
|
|
462
|
-
row: [{
|
|
463
|
-
size: indent,
|
|
464
|
-
className: TableCLS.rowToggle,
|
|
465
|
-
html: icon,
|
|
466
|
-
align: 'v',
|
|
467
|
-
style: {
|
|
468
|
-
cursor: _show === 'relative' ? 'not-allowed' : 'pointer',
|
|
469
|
-
background: 'rgba(0,0,0,0.03)',
|
|
470
|
-
height: '100%'
|
|
471
|
-
},
|
|
472
|
-
attrs: {
|
|
473
|
-
onClick: () => {
|
|
474
|
-
if (_show === 'relative') {
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
this.toggleRow(id);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}, {
|
|
481
|
-
size: 6
|
|
482
|
-
}]
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
indent_layout(rowId) {
|
|
486
|
-
let {
|
|
487
|
-
indent,
|
|
488
|
-
rowGap,
|
|
489
|
-
rowHeight,
|
|
490
|
-
indentColor = 'lightblue'
|
|
491
|
-
} = this.props;
|
|
492
|
-
let detail = this.getRowDetailById(rowId);
|
|
493
|
-
if (!detail._level) {
|
|
494
|
-
return false;
|
|
495
|
-
}
|
|
496
|
-
let getPath = () => {
|
|
497
|
-
let dasharray = [1, 3];
|
|
498
|
-
let {
|
|
499
|
-
_level: level,
|
|
500
|
-
_parentIds,
|
|
501
|
-
_isLastChild
|
|
502
|
-
} = detail;
|
|
503
|
-
let isLastChild = _isLastChild();
|
|
504
|
-
let x0 = indent * (level - 1) + indent / 2,
|
|
505
|
-
x1 = x0 + indent / 2,
|
|
506
|
-
y0 = 0,
|
|
507
|
-
y1 = rowHeight / 2 + rowGap,
|
|
508
|
-
y2 = rowHeight + rowGap;
|
|
509
|
-
let pathes = [];
|
|
510
|
-
pathes.push( /*#__PURE__*/_react.default.createElement("path", {
|
|
511
|
-
d: `M${x0} ${y0} L${x0} ${isLastChild ? y1 : y2} Z`,
|
|
512
|
-
stroke: indentColor,
|
|
513
|
-
strokeWidth: 1,
|
|
514
|
-
strokeDasharray: dasharray
|
|
515
|
-
}));
|
|
516
|
-
pathes.push( /*#__PURE__*/_react.default.createElement("path", {
|
|
517
|
-
d: `M${x0} ${y1} L${x1} ${y1} Z`,
|
|
518
|
-
stroke: indentColor,
|
|
519
|
-
strokeWidth: 1,
|
|
520
|
-
strokeDasharray: dasharray
|
|
521
|
-
}));
|
|
522
|
-
for (let i = 1; i < _parentIds.length; i++) {
|
|
523
|
-
let {
|
|
524
|
-
_isLastChild
|
|
525
|
-
} = this.getRowDetailById(_parentIds[i]);
|
|
526
|
-
if (_isLastChild()) {
|
|
527
|
-
continue;
|
|
528
|
-
}
|
|
529
|
-
let x = (i - 0.5) * indent;
|
|
530
|
-
pathes.push( /*#__PURE__*/_react.default.createElement("path", {
|
|
531
|
-
d: `M${x} ${y0} L${x} ${y2} Z`,
|
|
532
|
-
stroke: indentColor,
|
|
533
|
-
strokeWidth: 1,
|
|
534
|
-
strokeDasharray: dasharray
|
|
535
|
-
}));
|
|
536
|
-
}
|
|
537
|
-
return pathes;
|
|
538
|
-
};
|
|
539
|
-
return {
|
|
540
|
-
size: detail._level * indent,
|
|
541
|
-
style: {
|
|
542
|
-
height: '100%',
|
|
543
|
-
overflow: 'visible'
|
|
544
|
-
},
|
|
545
|
-
html: /*#__PURE__*/_react.default.createElement("div", {
|
|
546
|
-
style: {
|
|
547
|
-
width: detail._level * indent,
|
|
548
|
-
height: '100%',
|
|
549
|
-
position: 'relative'
|
|
550
|
-
}
|
|
551
|
-
}, /*#__PURE__*/_react.default.createElement("svg", {
|
|
552
|
-
width: 20,
|
|
553
|
-
height: 20,
|
|
554
|
-
style: {
|
|
555
|
-
height: `calc(100% + ${rowGap}px)`,
|
|
556
|
-
width: '100%',
|
|
557
|
-
position: 'absolute',
|
|
558
|
-
top: -rowGap
|
|
559
|
-
}
|
|
560
|
-
}, getPath(indent, detail)))
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
getContext() {
|
|
564
|
-
let {
|
|
565
|
-
details_object,
|
|
566
|
-
rows_object,
|
|
567
|
-
rows_array
|
|
568
|
-
} = this;
|
|
569
|
-
let {
|
|
570
|
-
openDictionary
|
|
571
|
-
} = this.state;
|
|
572
|
-
return {
|
|
573
|
-
...this.props,
|
|
574
|
-
openDictionary,
|
|
575
|
-
state: this.state,
|
|
576
|
-
details_object,
|
|
577
|
-
rows_object,
|
|
578
|
-
rows_array,
|
|
579
|
-
getRowById: this.getRowById.bind(this),
|
|
580
|
-
getRowDetailById: this.getRowDetailById.bind(this),
|
|
581
|
-
isRowOpen: this.isRowOpen.bind(this),
|
|
582
|
-
SetState: obj => this.setState(obj),
|
|
583
|
-
setColumns: this.setColumns.bind(this),
|
|
584
|
-
getSearchs: this.getSearchs.bind(this),
|
|
585
|
-
toggleRow: this.toggleRow.bind(this),
|
|
586
|
-
indent_layout: this.indent_layout.bind(this),
|
|
587
|
-
toggle_layout: this.toggle_layout.bind(this),
|
|
588
|
-
translate: this.translate.bind(this),
|
|
589
|
-
groups: this.groups
|
|
590
|
-
};
|
|
591
|
-
}
|
|
592
|
-
keyDown(e) {
|
|
593
|
-
if (e.keyCode === 27) {
|
|
594
|
-
(0, _jquery.default)('.' + TableCLS.inlineEditInput).blur();
|
|
595
|
-
}
|
|
596
|
-
//else if([37,38,39,40].indexOf(e.keyCode) !== -1){this.arrow(e);}
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
arrow(e) {
|
|
600
|
-
var container = (0, _jquery.default)(this.dom.current);
|
|
601
|
-
var {
|
|
602
|
-
rtl
|
|
603
|
-
} = this.context;
|
|
604
|
-
let inputs = container.find('.' + TableCLS.inlineEditInput);
|
|
605
|
-
if (inputs.length === 0) {
|
|
606
|
-
return;
|
|
607
|
-
}
|
|
608
|
-
let focusedInput = inputs.filter(':focus');
|
|
609
|
-
if (!focusedInput.length) {
|
|
610
|
-
inputs.eq(1).focus().select();
|
|
611
|
-
return;
|
|
612
|
-
}
|
|
613
|
-
let rowId = focusedInput.attr('data-row-id');
|
|
614
|
-
let colId = focusedInput.attr('data-col-id');
|
|
615
|
-
if (e.keyCode === 40 || e.keyCode === 38) {
|
|
616
|
-
let sign = e.keyCode === 40 ? 'next' : 'prev';
|
|
617
|
-
e.preventDefault();
|
|
618
|
-
let next = inputs[sign](`[data-col-id='${colId}']`);
|
|
619
|
-
if (next.length) {
|
|
620
|
-
next.focus().select();
|
|
621
|
-
}
|
|
622
|
-
} else if (e.keyCode === 39 || e.keyCode === 37) {
|
|
623
|
-
e.preventDefault();
|
|
624
|
-
let sign = (e.keyCode === 37 ? -1 : 1) * (rtl ? -1 : 1) === 1 ? 'next' : 'prev';
|
|
625
|
-
let next = focusedInput[sign](`[data-row-id='${rowId}']`);
|
|
626
|
-
console.log(next.length);
|
|
627
|
-
if (next.length) {
|
|
628
|
-
next.focus().select();
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
toolbar_layout() {
|
|
633
|
-
return {
|
|
634
|
-
html: /*#__PURE__*/_react.default.createElement(Toolbar, null)
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
async componentDidMount() {
|
|
638
|
-
this.state.Sort.set();
|
|
639
|
-
}
|
|
640
|
-
units_layout() {
|
|
641
|
-
let {
|
|
642
|
-
columns
|
|
643
|
-
} = this.state;
|
|
644
|
-
if (this.freezeMode) {
|
|
645
|
-
let {
|
|
646
|
-
freezeSize
|
|
647
|
-
} = this.state;
|
|
648
|
-
return {
|
|
649
|
-
flex: 1,
|
|
650
|
-
gap: 8,
|
|
651
|
-
row: [{
|
|
652
|
-
gapAttrs: {
|
|
653
|
-
className: TableCLS.splitter
|
|
654
|
-
},
|
|
655
|
-
size: freezeSize,
|
|
656
|
-
onResize: freezeSize => this.setState({
|
|
657
|
-
freezeSize
|
|
658
|
-
}),
|
|
659
|
-
html: /*#__PURE__*/_react.default.createElement(TableUnit, {
|
|
660
|
-
onScroll: () => this.onScroll(0),
|
|
661
|
-
cellsType: "freezeCells",
|
|
662
|
-
columns: columns.filter(({
|
|
663
|
-
freeze
|
|
664
|
-
}) => freeze)
|
|
665
|
-
})
|
|
666
|
-
}, {
|
|
667
|
-
flex: 1,
|
|
668
|
-
html: /*#__PURE__*/_react.default.createElement(TableUnit, {
|
|
669
|
-
cellsType: "unfreezeCells",
|
|
670
|
-
columns: columns.filter(({
|
|
671
|
-
freeze
|
|
672
|
-
}) => !freeze),
|
|
673
|
-
onScroll: () => this.onScroll(1)
|
|
674
|
-
})
|
|
675
|
-
}]
|
|
676
|
-
};
|
|
677
|
-
}
|
|
678
|
-
return {
|
|
679
|
-
flex: 1,
|
|
680
|
-
html: /*#__PURE__*/_react.default.createElement(TableUnit, {
|
|
681
|
-
cellsType: "cells",
|
|
682
|
-
columns: columns,
|
|
683
|
-
onScroll: e => this.onScroll()
|
|
684
|
-
})
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
async changePaging(type, value) {
|
|
688
|
-
let {
|
|
689
|
-
paging
|
|
690
|
-
} = this.state;
|
|
691
|
-
let {
|
|
692
|
-
pages,
|
|
693
|
-
number,
|
|
694
|
-
size,
|
|
695
|
-
onChange
|
|
696
|
-
} = paging;
|
|
697
|
-
let newNumber = number;
|
|
698
|
-
let newSize = size;
|
|
699
|
-
if (type === 'prev') {
|
|
700
|
-
newNumber = number - 1;
|
|
701
|
-
} else if (type === 'next') {
|
|
702
|
-
newNumber = number + 1;
|
|
703
|
-
} else if (type === 'first') {
|
|
704
|
-
newNumber = 1;
|
|
705
|
-
} else if (type === 'last') {
|
|
706
|
-
newNumber = pages;
|
|
707
|
-
} else if (type === 'size') {
|
|
708
|
-
newSize = value;
|
|
709
|
-
}
|
|
710
|
-
if (newNumber < 1) {
|
|
711
|
-
newNumber = 1;
|
|
712
|
-
}
|
|
713
|
-
if (newNumber > pages) {
|
|
714
|
-
newNumber = pages;
|
|
715
|
-
}
|
|
716
|
-
let newPaging = {
|
|
717
|
-
...paging,
|
|
718
|
-
number: newNumber,
|
|
719
|
-
size: newSize
|
|
720
|
-
};
|
|
721
|
-
if (onChange) {
|
|
722
|
-
let res = await onChange(newPaging);
|
|
723
|
-
if (res !== false) {
|
|
724
|
-
this.setState({
|
|
725
|
-
paging: newPaging
|
|
726
|
-
});
|
|
727
|
-
}
|
|
728
|
-
} else {
|
|
729
|
-
this.setState({
|
|
730
|
-
paging: newPaging
|
|
731
|
-
});
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
paging_layout() {
|
|
735
|
-
let {
|
|
736
|
-
paging
|
|
737
|
-
} = this.state;
|
|
738
|
-
if (!paging) {
|
|
739
|
-
return false;
|
|
740
|
-
}
|
|
741
|
-
let {
|
|
742
|
-
rtl,
|
|
743
|
-
model
|
|
744
|
-
} = this.props;
|
|
745
|
-
let {
|
|
746
|
-
number = 1,
|
|
747
|
-
sizes = [1, 5, 10, 15, 20, 30, 40, 50, 70, 100, 150, 200],
|
|
748
|
-
size = sizes[0],
|
|
749
|
-
length = model.length
|
|
750
|
-
} = paging;
|
|
751
|
-
let pages = Math.ceil(length / size);
|
|
752
|
-
paging.sizes = sizes;
|
|
753
|
-
paging.pages = pages;
|
|
754
|
-
paging.size = size;
|
|
755
|
-
paging.number = number;
|
|
756
|
-
return {
|
|
757
|
-
className: TableCLS.paging,
|
|
758
|
-
style: {
|
|
759
|
-
direction: 'ltr'
|
|
760
|
-
},
|
|
761
|
-
row: [{
|
|
762
|
-
flex: 1
|
|
763
|
-
}, {
|
|
764
|
-
html: /*#__PURE__*/_react.default.createElement("button", {
|
|
765
|
-
className: TableCLS.toolbarIconButton
|
|
766
|
-
}, /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
767
|
-
path: _js.mdiChevronDoubleLeft,
|
|
768
|
-
size: 0.8
|
|
769
|
-
})),
|
|
770
|
-
attrs: {
|
|
771
|
-
onClick: () => this.changePaging(rtl ? 'last' : 'first')
|
|
772
|
-
}
|
|
773
|
-
}, {
|
|
774
|
-
html: /*#__PURE__*/_react.default.createElement("button", {
|
|
775
|
-
className: TableCLS.toolbarIconButton
|
|
776
|
-
}, /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
777
|
-
path: _js.mdiChevronLeft,
|
|
778
|
-
size: 0.8
|
|
779
|
-
})),
|
|
780
|
-
attrs: {
|
|
781
|
-
onClick: () => this.changePaging(rtl ? 'next' : 'prev')
|
|
782
|
-
}
|
|
783
|
-
}, {
|
|
784
|
-
html: rtl ? pages + ' / ' + number : number + ' / ' + pages,
|
|
785
|
-
style: {
|
|
786
|
-
fontSize: 12,
|
|
787
|
-
padding: '0 12px'
|
|
788
|
-
},
|
|
789
|
-
align: 'vh'
|
|
790
|
-
}, {
|
|
791
|
-
html: /*#__PURE__*/_react.default.createElement("button", {
|
|
792
|
-
className: TableCLS.toolbarIconButton
|
|
793
|
-
}, /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
794
|
-
path: _js.mdiChevronRight,
|
|
795
|
-
size: 0.8
|
|
796
|
-
})),
|
|
797
|
-
attrs: {
|
|
798
|
-
onClick: () => this.changePaging(rtl ? 'prev' : 'next')
|
|
799
|
-
}
|
|
800
|
-
}, {
|
|
801
|
-
html: /*#__PURE__*/_react.default.createElement("button", {
|
|
802
|
-
className: TableCLS.toolbarIconButton
|
|
803
|
-
}, /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
804
|
-
path: _js.mdiChevronDoubleRight,
|
|
805
|
-
size: 0.8
|
|
806
|
-
})),
|
|
807
|
-
attrs: {
|
|
808
|
-
onClick: () => this.changePaging(rtl ? 'first' : 'last')
|
|
809
|
-
}
|
|
810
|
-
}, {
|
|
811
|
-
html: /*#__PURE__*/_react.default.createElement(_aioButton.default, {
|
|
812
|
-
className: TableCLS.toolbarIconButton,
|
|
813
|
-
type: "select",
|
|
814
|
-
options: sizes,
|
|
815
|
-
optionValue: "option",
|
|
816
|
-
optionText: "option",
|
|
817
|
-
search: false,
|
|
818
|
-
caret: false,
|
|
819
|
-
text: size,
|
|
820
|
-
optionStyle: "{height:24}",
|
|
821
|
-
onChange: value => this.changePaging('size', value)
|
|
822
|
-
})
|
|
823
|
-
}, {
|
|
824
|
-
flex: 1
|
|
825
|
-
}]
|
|
826
|
-
};
|
|
827
|
-
}
|
|
828
|
-
setColumnIds() {
|
|
829
|
-
let {
|
|
830
|
-
columns = []
|
|
831
|
-
} = this.state;
|
|
832
|
-
for (let i = 0; i < columns.length; i++) {
|
|
833
|
-
if (!columns[i].dataColumnId) {
|
|
834
|
-
columns[i].dataColumnId = 'col' + Math.random();
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
render() {
|
|
839
|
-
let {
|
|
840
|
-
model,
|
|
841
|
-
columns,
|
|
842
|
-
className,
|
|
843
|
-
style
|
|
844
|
-
} = this.props;
|
|
845
|
-
let {
|
|
846
|
-
prevColumns
|
|
847
|
-
} = this.state;
|
|
848
|
-
let columnsStr = JSON.stringify(columns);
|
|
849
|
-
if (columnsStr !== prevColumns) {
|
|
850
|
-
let newColumns = JSON.parse(columnsStr);
|
|
851
|
-
setTimeout(() => this.setState({
|
|
852
|
-
columns: newColumns,
|
|
853
|
-
prevColumns: columnsStr
|
|
854
|
-
}, () => this.updateColumnsByStorageKey()), 0);
|
|
855
|
-
}
|
|
856
|
-
this.setColumnIds();
|
|
857
|
-
//پیجینگ را زود تر می سازیم که دیفالت هاش محاسبه بشه
|
|
858
|
-
let pagingLayout = this.paging_layout();
|
|
859
|
-
this.getModelDetails(model);
|
|
860
|
-
let context = this.getContext();
|
|
861
|
-
return /*#__PURE__*/_react.default.createElement(TableContext.Provider, {
|
|
862
|
-
value: context
|
|
863
|
-
}, /*#__PURE__*/_react.default.createElement(_reactVirtualDom.default, {
|
|
864
|
-
layout: {
|
|
865
|
-
className: TableCLS.table + (className ? ' ' + className : ''),
|
|
866
|
-
attrs: {
|
|
867
|
-
ref: this.dom,
|
|
868
|
-
onKeyDown: e => this.keyDown(e)
|
|
869
|
-
},
|
|
870
|
-
style,
|
|
871
|
-
column: [this.toolbar_layout(), this.units_layout(), pagingLayout]
|
|
872
|
-
}
|
|
873
|
-
}));
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
exports.default = Table;
|
|
877
|
-
Table.defaultProps = {
|
|
878
|
-
indent: 16,
|
|
879
|
-
columnGap: 1,
|
|
880
|
-
rowGap: 1,
|
|
881
|
-
headerHeight: 48
|
|
882
|
-
};
|
|
883
|
-
class TableUnit extends _react.Component {
|
|
884
|
-
constructor(props) {
|
|
885
|
-
super(props);
|
|
886
|
-
this.rowsRef = /*#__PURE__*/(0, _react.createRef)();
|
|
887
|
-
this.resizeDown = functions.resizeDown;
|
|
888
|
-
this.resizeMove = functions.resizeMove;
|
|
889
|
-
this.resizeUp = functions.resizeUp;
|
|
890
|
-
this.getClient = functions.getClient;
|
|
891
|
-
}
|
|
892
|
-
title_layout(column, setFlex) {
|
|
893
|
-
if (column.show === false) {
|
|
894
|
-
return false;
|
|
895
|
-
}
|
|
896
|
-
let resizable = column.resizable !== false && column.width && !column.flex;
|
|
897
|
-
let {
|
|
898
|
-
rowHeight,
|
|
899
|
-
headerHeight
|
|
900
|
-
} = this.context;
|
|
901
|
-
let {
|
|
902
|
-
width,
|
|
903
|
-
flex,
|
|
904
|
-
minWidth = 36,
|
|
905
|
-
titleAttrs = {}
|
|
906
|
-
} = column;
|
|
907
|
-
if (setFlex) {
|
|
908
|
-
width = undefined;
|
|
909
|
-
flex = 1;
|
|
910
|
-
}
|
|
911
|
-
if (width === undefined && flex === undefined) {
|
|
912
|
-
flex = 1;
|
|
913
|
-
}
|
|
914
|
-
return {
|
|
915
|
-
size: width,
|
|
916
|
-
align: 'vh',
|
|
917
|
-
flex,
|
|
918
|
-
style: {
|
|
919
|
-
minWidth,
|
|
920
|
-
height: headerHeight || rowHeight,
|
|
921
|
-
...titleAttrs.style
|
|
922
|
-
},
|
|
923
|
-
attrs: {
|
|
924
|
-
...titleAttrs,
|
|
925
|
-
'data-column-id': column.dataColumnId,
|
|
926
|
-
className: undefined,
|
|
927
|
-
style: undefined,
|
|
928
|
-
draggable: column.swap !== false,
|
|
929
|
-
onDragStart: e => {
|
|
930
|
-
if (this.downOnResizeHandle) {
|
|
931
|
-
e.stopPropagation();
|
|
932
|
-
e.preventDefault();
|
|
933
|
-
}
|
|
934
|
-
this.startColumnSwap = column;
|
|
935
|
-
},
|
|
936
|
-
onDragOver: e => {
|
|
937
|
-
e.preventDefault();
|
|
938
|
-
},
|
|
939
|
-
onDrop: () => {
|
|
940
|
-
this.endColumnSwap = column;
|
|
941
|
-
let {
|
|
942
|
-
setColumns,
|
|
943
|
-
state
|
|
944
|
-
} = this.context;
|
|
945
|
-
let {
|
|
946
|
-
columns
|
|
947
|
-
} = state;
|
|
948
|
-
if (column.swap === false) {
|
|
949
|
-
return;
|
|
950
|
-
}
|
|
951
|
-
if (this.startColumnSwap === undefined || this.startColumnSwap.dataColumnId === this.endColumnSwap.dataColumnId) {
|
|
952
|
-
return;
|
|
953
|
-
}
|
|
954
|
-
let newColumns = columns.map((c, j) => {
|
|
955
|
-
if (c.dataColumnId === this.startColumnSwap.dataColumnId) {
|
|
956
|
-
return this.endColumnSwap;
|
|
957
|
-
}
|
|
958
|
-
if (c.dataColumnId === this.endColumnSwap.dataColumnId) {
|
|
959
|
-
return this.startColumnSwap;
|
|
960
|
-
}
|
|
961
|
-
return c;
|
|
962
|
-
});
|
|
963
|
-
setColumns(newColumns);
|
|
964
|
-
}
|
|
965
|
-
},
|
|
966
|
-
className: TableCLS.title + (titleAttrs.className ? ' ' + titleAttrs.className : ''),
|
|
967
|
-
row: [this.resize_layout(column, resizable, 'start'), {
|
|
968
|
-
html: column.title || '',
|
|
969
|
-
flex: 1,
|
|
970
|
-
align: column.titleJustify !== false ? 'h' : undefined
|
|
971
|
-
}, this.filter_layout(column), this.resize_layout(column, resizable, 'end')]
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
resize_layout(column, resizable, type) {
|
|
975
|
-
if (!resizable) {
|
|
976
|
-
return {
|
|
977
|
-
size: 12
|
|
978
|
-
};
|
|
979
|
-
}
|
|
980
|
-
return {
|
|
981
|
-
size: 12,
|
|
982
|
-
className: TableCLS.resizeHandle,
|
|
983
|
-
style: {
|
|
984
|
-
cursor: 'col-resize',
|
|
985
|
-
height: '100%'
|
|
986
|
-
},
|
|
987
|
-
attrs: {
|
|
988
|
-
onMouseDown: e => this.resizeDown(e, column, type),
|
|
989
|
-
onTouchStart: e => this.resizeDown(e, column, type),
|
|
990
|
-
draggable: false
|
|
991
|
-
}
|
|
992
|
-
};
|
|
993
|
-
}
|
|
994
|
-
filter_layout(column) {
|
|
995
|
-
let {
|
|
996
|
-
translate,
|
|
997
|
-
rtl,
|
|
998
|
-
state,
|
|
999
|
-
setColumns
|
|
1000
|
-
} = this.context;
|
|
1001
|
-
let {
|
|
1002
|
-
setColumn
|
|
1003
|
-
} = state;
|
|
1004
|
-
let {
|
|
1005
|
-
filter,
|
|
1006
|
-
type = 'text'
|
|
1007
|
-
} = column;
|
|
1008
|
-
if (!filter) {
|
|
1009
|
-
return false;
|
|
1010
|
-
}
|
|
1011
|
-
if (filter === true) {
|
|
1012
|
-
filter = {};
|
|
1013
|
-
setColumn(column, {
|
|
1014
|
-
filter: {}
|
|
1015
|
-
});
|
|
1016
|
-
}
|
|
1017
|
-
let {
|
|
1018
|
-
items = [],
|
|
1019
|
-
booleanType = 'or',
|
|
1020
|
-
add,
|
|
1021
|
-
operators,
|
|
1022
|
-
valueOptions
|
|
1023
|
-
} = filter;
|
|
1024
|
-
return {
|
|
1025
|
-
html: /*#__PURE__*/_react.default.createElement(_aioButton.default, {
|
|
1026
|
-
style: {
|
|
1027
|
-
background: 'none',
|
|
1028
|
-
color: 'inherit'
|
|
1029
|
-
},
|
|
1030
|
-
type: "button",
|
|
1031
|
-
rtl: rtl,
|
|
1032
|
-
caret: false,
|
|
1033
|
-
text: /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
1034
|
-
path: items.length ? _js.mdiFilterMenu : _js.mdiFilter,
|
|
1035
|
-
size: 0.6
|
|
1036
|
-
}),
|
|
1037
|
-
popOver: () => {
|
|
1038
|
-
let {
|
|
1039
|
-
columns
|
|
1040
|
-
} = this.props;
|
|
1041
|
-
return /*#__PURE__*/_react.default.createElement(AIOTableFilterPopup, {
|
|
1042
|
-
title: column.title,
|
|
1043
|
-
translate: translate,
|
|
1044
|
-
type: type,
|
|
1045
|
-
items: items,
|
|
1046
|
-
booleanType: booleanType,
|
|
1047
|
-
add: add,
|
|
1048
|
-
operators: operators,
|
|
1049
|
-
valueOptions: valueOptions,
|
|
1050
|
-
onChangeBooleanType: booleanType => {
|
|
1051
|
-
let {
|
|
1052
|
-
filter
|
|
1053
|
-
} = column;
|
|
1054
|
-
filter.booleanType = booleanType;
|
|
1055
|
-
setColumn(column, {
|
|
1056
|
-
filter
|
|
1057
|
-
});
|
|
1058
|
-
state.saveColumnInStorage(column, 'filter', column.filter);
|
|
1059
|
-
setColumns(columns);
|
|
1060
|
-
if (column.onChangeFilter) {
|
|
1061
|
-
column.onChangeFilter(column);
|
|
1062
|
-
}
|
|
1063
|
-
},
|
|
1064
|
-
onChange: async items => {
|
|
1065
|
-
let {
|
|
1066
|
-
filter
|
|
1067
|
-
} = column;
|
|
1068
|
-
filter.items = items;
|
|
1069
|
-
setColumn(column, {
|
|
1070
|
-
filter
|
|
1071
|
-
});
|
|
1072
|
-
state.saveColumnInStorage(column, 'filter', column.filter);
|
|
1073
|
-
setColumns(columns);
|
|
1074
|
-
if (column.onChangeFilter) {
|
|
1075
|
-
column.onChangeFilter(column);
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
});
|
|
1079
|
-
}
|
|
1080
|
-
})
|
|
1081
|
-
};
|
|
1082
|
-
}
|
|
1083
|
-
group_layout(o) {
|
|
1084
|
-
let {
|
|
1085
|
-
groupHeight,
|
|
1086
|
-
rowHeight,
|
|
1087
|
-
indent,
|
|
1088
|
-
rtl,
|
|
1089
|
-
editGroupName = o => o
|
|
1090
|
-
} = this.context;
|
|
1091
|
-
let {
|
|
1092
|
-
cellsType
|
|
1093
|
-
} = this.props;
|
|
1094
|
-
return {
|
|
1095
|
-
style: {
|
|
1096
|
-
position: 'sticky',
|
|
1097
|
-
[rtl ? 'right' : 'left']: 0,
|
|
1098
|
-
height: groupHeight || rowHeight
|
|
1099
|
-
},
|
|
1100
|
-
className: TableCLS.groupRow,
|
|
1101
|
-
row: cellsType === 'unfreezeCells' ? [{
|
|
1102
|
-
flex: 1
|
|
1103
|
-
}] : [{
|
|
1104
|
-
size: 12
|
|
1105
|
-
}, {
|
|
1106
|
-
size: o.groupLevel * indent
|
|
1107
|
-
}, this.groupToggle_layout(o), {
|
|
1108
|
-
html: editGroupName(o.value),
|
|
1109
|
-
align: 'v'
|
|
1110
|
-
}]
|
|
1111
|
-
};
|
|
1112
|
-
}
|
|
1113
|
-
getGroupToggleIcon(open) {
|
|
1114
|
-
let {
|
|
1115
|
-
getToggleIcon,
|
|
1116
|
-
rtl
|
|
1117
|
-
} = this.context;
|
|
1118
|
-
if (getToggleIcon) {
|
|
1119
|
-
return getToggleIcon(!!open);
|
|
1120
|
-
}
|
|
1121
|
-
return /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
1122
|
-
path: open ? _js.mdiChevronDown : rtl ? _js.mdiChevronLeft : _js.mdiChevronRight,
|
|
1123
|
-
size: 0.8
|
|
1124
|
-
});
|
|
1125
|
-
}
|
|
1126
|
-
groupToggle_layout(o) {
|
|
1127
|
-
let {
|
|
1128
|
-
state,
|
|
1129
|
-
SetState
|
|
1130
|
-
} = this.context;
|
|
1131
|
-
let {
|
|
1132
|
-
groupsOpen
|
|
1133
|
-
} = state;
|
|
1134
|
-
return {
|
|
1135
|
-
align: 'vh',
|
|
1136
|
-
row: [{
|
|
1137
|
-
className: TableCLS.rowToggle,
|
|
1138
|
-
html: this.getGroupToggleIcon(o.groupOpen),
|
|
1139
|
-
align: 'vh',
|
|
1140
|
-
attrs: {
|
|
1141
|
-
onClick: () => SetState({
|
|
1142
|
-
groupsOpen: {
|
|
1143
|
-
...groupsOpen,
|
|
1144
|
-
[o.id]: !groupsOpen[o.id]
|
|
1145
|
-
}
|
|
1146
|
-
})
|
|
1147
|
-
}
|
|
1148
|
-
}, {
|
|
1149
|
-
size: 6
|
|
1150
|
-
}]
|
|
1151
|
-
};
|
|
1152
|
-
}
|
|
1153
|
-
row_layout(rowId, striped) {
|
|
1154
|
-
let {
|
|
1155
|
-
isRowOpen,
|
|
1156
|
-
getRowDetailById,
|
|
1157
|
-
columnGap,
|
|
1158
|
-
rowTemplate,
|
|
1159
|
-
getRowById,
|
|
1160
|
-
toggleRow,
|
|
1161
|
-
rowChilds,
|
|
1162
|
-
indent_layout,
|
|
1163
|
-
toggle_layout,
|
|
1164
|
-
rowHeight
|
|
1165
|
-
} = this.context;
|
|
1166
|
-
if (!isRowOpen(rowId)) {
|
|
1167
|
-
return false;
|
|
1168
|
-
}
|
|
1169
|
-
let rowDetail = getRowDetailById(rowId);
|
|
1170
|
-
if (rowDetail._show === false) {
|
|
1171
|
-
return false;
|
|
1172
|
-
}
|
|
1173
|
-
if (rowTemplate) {
|
|
1174
|
-
let row = getRowById(rowId);
|
|
1175
|
-
if (rowChilds) {
|
|
1176
|
-
return {
|
|
1177
|
-
style: {
|
|
1178
|
-
overflow: 'visible'
|
|
1179
|
-
},
|
|
1180
|
-
size: rowHeight,
|
|
1181
|
-
row: [indent_layout(rowId), toggle_layout(rowId, false), {
|
|
1182
|
-
flex: 1,
|
|
1183
|
-
html: rowTemplate(row, rowDetail),
|
|
1184
|
-
className: TableCLS.rowTemplate,
|
|
1185
|
-
style: {
|
|
1186
|
-
overflow: 'visible'
|
|
1187
|
-
}
|
|
1188
|
-
}, {
|
|
1189
|
-
size: 6
|
|
1190
|
-
}]
|
|
1191
|
-
};
|
|
1192
|
-
}
|
|
1193
|
-
return {
|
|
1194
|
-
html: rowTemplate(row, rowDetail, () => toggleRow(rowId))
|
|
1195
|
-
};
|
|
1196
|
-
}
|
|
1197
|
-
let {
|
|
1198
|
-
cellsType
|
|
1199
|
-
} = this.props;
|
|
1200
|
-
let cells = rowDetail['_' + cellsType];
|
|
1201
|
-
let isThereAnyFlex = false;
|
|
1202
|
-
return {
|
|
1203
|
-
className: TableCLS.row + (rowDetail._show === 'relative' ? ' row-relative-filter' : ''),
|
|
1204
|
-
gap: columnGap,
|
|
1205
|
-
style: {
|
|
1206
|
-
overflow: 'visible'
|
|
1207
|
-
},
|
|
1208
|
-
row: cells.map((cell, i) => {
|
|
1209
|
-
let res = cell(striped);
|
|
1210
|
-
let {
|
|
1211
|
-
html,
|
|
1212
|
-
size,
|
|
1213
|
-
flex,
|
|
1214
|
-
minWidth = 36,
|
|
1215
|
-
attrs
|
|
1216
|
-
} = res;
|
|
1217
|
-
if (size === undefined && flex === undefined) {
|
|
1218
|
-
flex = 1;
|
|
1219
|
-
}
|
|
1220
|
-
if (flex !== undefined) {
|
|
1221
|
-
isThereAnyFlex = true;
|
|
1222
|
-
}
|
|
1223
|
-
if (i === cells.length - 1 && !isThereAnyFlex) {
|
|
1224
|
-
size = undefined;
|
|
1225
|
-
flex = 1;
|
|
1226
|
-
}
|
|
1227
|
-
return {
|
|
1228
|
-
style: {
|
|
1229
|
-
height: '100%',
|
|
1230
|
-
minWidth,
|
|
1231
|
-
overflow: 'visible'
|
|
1232
|
-
},
|
|
1233
|
-
html,
|
|
1234
|
-
size,
|
|
1235
|
-
flex,
|
|
1236
|
-
attrs
|
|
1237
|
-
};
|
|
1238
|
-
})
|
|
1239
|
-
};
|
|
1240
|
-
}
|
|
1241
|
-
onSwap(f, t) {
|
|
1242
|
-
debugger;
|
|
1243
|
-
}
|
|
1244
|
-
render() {
|
|
1245
|
-
let {
|
|
1246
|
-
rowGap
|
|
1247
|
-
} = this.context,
|
|
1248
|
-
{
|
|
1249
|
-
cellsType,
|
|
1250
|
-
onScroll
|
|
1251
|
-
} = this.props;
|
|
1252
|
-
let headerLayout = this.header_layout();
|
|
1253
|
-
let rowsLayout = this.rows_layout();
|
|
1254
|
-
let className = TableCLS.rows;
|
|
1255
|
-
if (cellsType === 'freezeCells') {
|
|
1256
|
-
className += ' ' + TableCLS.freezeContainer;
|
|
1257
|
-
} else if (cellsType === 'unfreezeCells') {
|
|
1258
|
-
className += ' ' + TableCLS.unfreezeContainer;
|
|
1259
|
-
}
|
|
1260
|
-
return /*#__PURE__*/_react.default.createElement(_reactVirtualDom.default, {
|
|
1261
|
-
onSwap: (f, t) => this.onSwap(f, t),
|
|
1262
|
-
layout: {
|
|
1263
|
-
className,
|
|
1264
|
-
column: [headerLayout, ...rowsLayout],
|
|
1265
|
-
scroll: 'vh',
|
|
1266
|
-
gap: rowGap,
|
|
1267
|
-
flex: 1,
|
|
1268
|
-
attrs: {
|
|
1269
|
-
onScroll: () => onScroll(),
|
|
1270
|
-
ref: this.rowsRef
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
});
|
|
1274
|
-
}
|
|
1275
|
-
header_layout() {
|
|
1276
|
-
let {
|
|
1277
|
-
rowTemplate,
|
|
1278
|
-
columnGap,
|
|
1279
|
-
showHeader
|
|
1280
|
-
} = this.context;
|
|
1281
|
-
let {
|
|
1282
|
-
columns = []
|
|
1283
|
-
} = this.props;
|
|
1284
|
-
if (rowTemplate || showHeader === false) {
|
|
1285
|
-
return false;
|
|
1286
|
-
}
|
|
1287
|
-
let isThereAnyFlex = false;
|
|
1288
|
-
return {
|
|
1289
|
-
gap: columnGap,
|
|
1290
|
-
className: TableCLS.header,
|
|
1291
|
-
row: columns.map((column, i) => {
|
|
1292
|
-
let {
|
|
1293
|
-
width,
|
|
1294
|
-
flex
|
|
1295
|
-
} = column;
|
|
1296
|
-
if (width === undefined && flex === undefined) {
|
|
1297
|
-
flex = 1;
|
|
1298
|
-
}
|
|
1299
|
-
if (flex !== undefined) {
|
|
1300
|
-
isThereAnyFlex = true;
|
|
1301
|
-
}
|
|
1302
|
-
let setFlex = false;
|
|
1303
|
-
if (i === columns.length - 1 && !isThereAnyFlex) {
|
|
1304
|
-
setFlex = true;
|
|
1305
|
-
}
|
|
1306
|
-
return this.title_layout(column, setFlex);
|
|
1307
|
-
})
|
|
1308
|
-
};
|
|
1309
|
-
}
|
|
1310
|
-
rows_layout() {
|
|
1311
|
-
let {
|
|
1312
|
-
rows_array,
|
|
1313
|
-
striped
|
|
1314
|
-
} = this.context;
|
|
1315
|
-
let index = -1;
|
|
1316
|
-
return rows_array.map((o, i) => {
|
|
1317
|
-
if (o._isGroup_) {
|
|
1318
|
-
return this.group_layout(o);
|
|
1319
|
-
}
|
|
1320
|
-
index++;
|
|
1321
|
-
return this.row_layout(o._id, index % 2 === 0 ? striped : undefined);
|
|
1322
|
-
});
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
_defineProperty(TableUnit, "contextType", TableContext);
|
|
1326
|
-
class Toolbar extends _react.Component {
|
|
1327
|
-
constructor(...args) {
|
|
1328
|
-
super(...args);
|
|
1329
|
-
_defineProperty(this, "state", {
|
|
1330
|
-
searchText: ''
|
|
1331
|
-
});
|
|
1332
|
-
}
|
|
1333
|
-
changeSearch(value, time = 1000) {
|
|
1334
|
-
clearTimeout(this.searchTimeout);
|
|
1335
|
-
this.setState({
|
|
1336
|
-
searchText: value
|
|
1337
|
-
});
|
|
1338
|
-
this.searchTimeout = setTimeout(() => this.context.SetState({
|
|
1339
|
-
searchText: value
|
|
1340
|
-
}), time);
|
|
1341
|
-
}
|
|
1342
|
-
getSearchbox() {
|
|
1343
|
-
let {
|
|
1344
|
-
translate,
|
|
1345
|
-
getSearchs
|
|
1346
|
-
} = this.context;
|
|
1347
|
-
let searchs = getSearchs();
|
|
1348
|
-
let {
|
|
1349
|
-
searchText
|
|
1350
|
-
} = this.state;
|
|
1351
|
-
if (!searchs.length) {
|
|
1352
|
-
return false;
|
|
1353
|
-
}
|
|
1354
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
1355
|
-
className: TableCLS.searchBox,
|
|
1356
|
-
key: "search"
|
|
1357
|
-
}, /*#__PURE__*/_react.default.createElement("input", {
|
|
1358
|
-
type: "text",
|
|
1359
|
-
value: searchText,
|
|
1360
|
-
placeholder: translate('Search'),
|
|
1361
|
-
onChange: e => this.changeSearch(e.target.value)
|
|
1362
|
-
}), /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
1363
|
-
path: searchText ? _js.mdiClose : _js.mdiMagnify,
|
|
1364
|
-
size: 0.7,
|
|
1365
|
-
onClick: () => {
|
|
1366
|
-
if (!searchText) {
|
|
1367
|
-
return;
|
|
1368
|
-
}
|
|
1369
|
-
this.changeSearch('', 0);
|
|
1370
|
-
}
|
|
1371
|
-
}));
|
|
1372
|
-
}
|
|
1373
|
-
getToggleButton() {
|
|
1374
|
-
let {
|
|
1375
|
-
state,
|
|
1376
|
-
translate
|
|
1377
|
-
} = this.context;
|
|
1378
|
-
let {
|
|
1379
|
-
columns,
|
|
1380
|
-
setColumn
|
|
1381
|
-
} = state;
|
|
1382
|
-
if (!columns || !columns.length) {
|
|
1383
|
-
return false;
|
|
1384
|
-
}
|
|
1385
|
-
let options = columns.filter(({
|
|
1386
|
-
toggle
|
|
1387
|
-
}) => toggle).map(column => {
|
|
1388
|
-
return {
|
|
1389
|
-
column,
|
|
1390
|
-
text: column.title,
|
|
1391
|
-
checked: column.show !== false
|
|
1392
|
-
};
|
|
1393
|
-
});
|
|
1394
|
-
if (!options.length) {
|
|
1395
|
-
return false;
|
|
1396
|
-
}
|
|
1397
|
-
return /*#__PURE__*/_react.default.createElement(_aioButton.default, {
|
|
1398
|
-
popupHeader: /*#__PURE__*/_react.default.createElement("div", {
|
|
1399
|
-
className: TableCLS.toolbarPopupHeader
|
|
1400
|
-
}, translate('Show Columns')),
|
|
1401
|
-
key: "togglebutton",
|
|
1402
|
-
caret: false,
|
|
1403
|
-
type: "select",
|
|
1404
|
-
options: options,
|
|
1405
|
-
className: TableCLS.toolbarIconButton,
|
|
1406
|
-
text: /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
1407
|
-
path: _js.mdiEye,
|
|
1408
|
-
size: 0.7
|
|
1409
|
-
}),
|
|
1410
|
-
onChange: (value, obj) => {
|
|
1411
|
-
let {
|
|
1412
|
-
state,
|
|
1413
|
-
setColumns
|
|
1414
|
-
} = this.context;
|
|
1415
|
-
let {
|
|
1416
|
-
columns
|
|
1417
|
-
} = state;
|
|
1418
|
-
let {
|
|
1419
|
-
column
|
|
1420
|
-
} = obj.option;
|
|
1421
|
-
let {
|
|
1422
|
-
show = true
|
|
1423
|
-
} = column;
|
|
1424
|
-
setColumn(column, {
|
|
1425
|
-
show: !show
|
|
1426
|
-
});
|
|
1427
|
-
state.saveColumnInStorage(column, 'show', obj.option.column.show);
|
|
1428
|
-
setColumns(columns);
|
|
1429
|
-
}
|
|
1430
|
-
});
|
|
1431
|
-
}
|
|
1432
|
-
getSortButton() {
|
|
1433
|
-
let {
|
|
1434
|
-
state,
|
|
1435
|
-
model = [],
|
|
1436
|
-
translate
|
|
1437
|
-
} = this.context;
|
|
1438
|
-
let sorts = state.Sort.get();
|
|
1439
|
-
if (!sorts.length || !model.length) {
|
|
1440
|
-
return false;
|
|
1441
|
-
}
|
|
1442
|
-
let options = sorts.map((sort, i) => {
|
|
1443
|
-
return {
|
|
1444
|
-
text: sort.title,
|
|
1445
|
-
checked: !!sort.active,
|
|
1446
|
-
after: /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
1447
|
-
path: sort.dir === 'dec' ? _js.mdiArrowDown : _js.mdiArrowUp,
|
|
1448
|
-
size: 0.8,
|
|
1449
|
-
onClick: e => {
|
|
1450
|
-
e.stopPropagation();
|
|
1451
|
-
sorts[i].dir = sort.dir === 'dec' ? 'inc' : 'dec';
|
|
1452
|
-
state.Sort.set(sorts);
|
|
1453
|
-
}
|
|
1454
|
-
})
|
|
1455
|
-
};
|
|
1456
|
-
});
|
|
1457
|
-
return /*#__PURE__*/_react.default.createElement(_aioButton.default, {
|
|
1458
|
-
popupHeader: /*#__PURE__*/_react.default.createElement("div", {
|
|
1459
|
-
className: TableCLS.toolbarPopupHeader
|
|
1460
|
-
}, translate('Sort By')),
|
|
1461
|
-
key: "sortbutton",
|
|
1462
|
-
caret: false,
|
|
1463
|
-
type: "select",
|
|
1464
|
-
options: options,
|
|
1465
|
-
className: TableCLS.toolbarIconButton,
|
|
1466
|
-
text: /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
1467
|
-
path: _js.mdiSort,
|
|
1468
|
-
size: 0.7
|
|
1469
|
-
}),
|
|
1470
|
-
onChange: (value, obj) => {
|
|
1471
|
-
sorts[obj.realIndex].active = !sorts[obj.realIndex].active;
|
|
1472
|
-
state.Sort.set(sorts);
|
|
1473
|
-
},
|
|
1474
|
-
onSwap: (from, to, swap) => state.Sort.set(swap(sorts, from, to))
|
|
1475
|
-
});
|
|
1476
|
-
}
|
|
1477
|
-
getExcelButton() {
|
|
1478
|
-
let {
|
|
1479
|
-
state,
|
|
1480
|
-
rows_array,
|
|
1481
|
-
getRowDetailById
|
|
1482
|
-
} = this.context;
|
|
1483
|
-
return /*#__PURE__*/_react.default.createElement(_aioButton.default, {
|
|
1484
|
-
key: "excelbutton",
|
|
1485
|
-
caret: false,
|
|
1486
|
-
type: "button",
|
|
1487
|
-
className: TableCLS.toolbarIconButton,
|
|
1488
|
-
text: /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
1489
|
-
path: _js.mdiFileExcel,
|
|
1490
|
-
size: 0.7
|
|
1491
|
-
}),
|
|
1492
|
-
onClick: () => state.Excel.export(rows_array.filter(({
|
|
1493
|
-
_isGroup_
|
|
1494
|
-
}) => !_isGroup_).map(({
|
|
1495
|
-
_id
|
|
1496
|
-
}) => getRowDetailById(_id)._json))
|
|
1497
|
-
});
|
|
1498
|
-
}
|
|
1499
|
-
getGroupButton() {
|
|
1500
|
-
var {
|
|
1501
|
-
model,
|
|
1502
|
-
state,
|
|
1503
|
-
groups,
|
|
1504
|
-
translate
|
|
1505
|
-
} = this.context;
|
|
1506
|
-
if (!groups.length || !model.length) {
|
|
1507
|
-
return false;
|
|
1508
|
-
}
|
|
1509
|
-
let options = groups.map(group => {
|
|
1510
|
-
return {
|
|
1511
|
-
text: group.title,
|
|
1512
|
-
checked: !!group.active
|
|
1513
|
-
};
|
|
1514
|
-
});
|
|
1515
|
-
return /*#__PURE__*/_react.default.createElement(_aioButton.default, {
|
|
1516
|
-
popupHeader: /*#__PURE__*/_react.default.createElement("div", {
|
|
1517
|
-
className: TableCLS.toolbarPopupHeader
|
|
1518
|
-
}, translate('Group By')),
|
|
1519
|
-
key: "groupbutton",
|
|
1520
|
-
caret: false,
|
|
1521
|
-
type: "select",
|
|
1522
|
-
options: options,
|
|
1523
|
-
className: TableCLS.toolbarIconButton,
|
|
1524
|
-
text: /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
1525
|
-
path: _js.mdiFileTree,
|
|
1526
|
-
size: 0.7
|
|
1527
|
-
}),
|
|
1528
|
-
onChange: (value, obj) => {
|
|
1529
|
-
groups[obj.realIndex].active = !groups[obj.realIndex].active;
|
|
1530
|
-
state.Group.set(groups);
|
|
1531
|
-
},
|
|
1532
|
-
onSwap: (from, to, swap) => state.Group.set(swap(groups, from, to))
|
|
1533
|
-
});
|
|
1534
|
-
}
|
|
1535
|
-
getToolbarItems() {
|
|
1536
|
-
var {
|
|
1537
|
-
toolbarItems = []
|
|
1538
|
-
} = this.context;
|
|
1539
|
-
return toolbarItems.map(o => {
|
|
1540
|
-
return /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({}, o, {
|
|
1541
|
-
className: TableCLS.toolbarItem + (o.className ? ' ' + o.className : '')
|
|
1542
|
-
}));
|
|
1543
|
-
});
|
|
1544
|
-
}
|
|
1545
|
-
getItems() {
|
|
1546
|
-
let {
|
|
1547
|
-
excel
|
|
1548
|
-
} = this.context;
|
|
1549
|
-
let items = [];
|
|
1550
|
-
let searchBox = this.getSearchbox();
|
|
1551
|
-
if (searchBox) {
|
|
1552
|
-
items.push(searchBox);
|
|
1553
|
-
}
|
|
1554
|
-
let toggleButton = this.getToggleButton();
|
|
1555
|
-
if (toggleButton) {
|
|
1556
|
-
items.push(toggleButton);
|
|
1557
|
-
}
|
|
1558
|
-
let sortButton = this.getSortButton();
|
|
1559
|
-
if (sortButton) {
|
|
1560
|
-
items.push(sortButton);
|
|
1561
|
-
}
|
|
1562
|
-
let groupButton = this.getGroupButton();
|
|
1563
|
-
if (groupButton) {
|
|
1564
|
-
items.push(groupButton);
|
|
1565
|
-
}
|
|
1566
|
-
if (excel) {
|
|
1567
|
-
items.push(this.getExcelButton());
|
|
1568
|
-
}
|
|
1569
|
-
let toolbarItems = this.getToolbarItems();
|
|
1570
|
-
items = items.concat(toolbarItems);
|
|
1571
|
-
return items;
|
|
1572
|
-
}
|
|
1573
|
-
render() {
|
|
1574
|
-
let items = this.getItems();
|
|
1575
|
-
if (!items.length) {
|
|
1576
|
-
return null;
|
|
1577
|
-
}
|
|
1578
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
1579
|
-
className: TableCLS.toolbar
|
|
1580
|
-
}, items);
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
_defineProperty(Toolbar, "contextType", TableContext);
|
|
1584
|
-
class Cell extends _react.Component {
|
|
1585
|
-
constructor(props) {
|
|
1586
|
-
super(props);
|
|
1587
|
-
this.dataUniqId = 'cell' + Math.random();
|
|
1588
|
-
}
|
|
1589
|
-
getContent(row, column, value) {
|
|
1590
|
-
let {
|
|
1591
|
-
rows_object,
|
|
1592
|
-
details_object,
|
|
1593
|
-
verticalTabIndex
|
|
1594
|
-
} = this.context;
|
|
1595
|
-
let {
|
|
1596
|
-
rowId,
|
|
1597
|
-
colId
|
|
1598
|
-
} = this.props;
|
|
1599
|
-
if (this.inlineEdit) {
|
|
1600
|
-
if (this.inlineEdit.type === 'text' || this.inlineEdit.type === 'number') {
|
|
1601
|
-
let props = {
|
|
1602
|
-
type: column.type,
|
|
1603
|
-
className: TableCLS.inlineEditInput,
|
|
1604
|
-
defaultValue: value,
|
|
1605
|
-
tabIndex: verticalTabIndex ? colId : 0,
|
|
1606
|
-
style: {
|
|
1607
|
-
textAlign: column.justify ? 'center' : undefined
|
|
1608
|
-
},
|
|
1609
|
-
'data-col-id': colId,
|
|
1610
|
-
'data-row-id': rowId,
|
|
1611
|
-
onBlur: e => this.onChange(e.target.value)
|
|
1612
|
-
};
|
|
1613
|
-
return /*#__PURE__*/_react.default.createElement("input", props);
|
|
1614
|
-
}
|
|
1615
|
-
if (this.inlineEdit.type === 'select') {
|
|
1616
|
-
return /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
|
|
1617
|
-
attrs: {
|
|
1618
|
-
'data-col-id': colId,
|
|
1619
|
-
'data-row-id': rowId,
|
|
1620
|
-
tabIndex: verticalTabIndex ? colId : 0
|
|
1621
|
-
}
|
|
1622
|
-
}, this.inlineEdit, {
|
|
1623
|
-
className: TableCLS.inlineEditInput,
|
|
1624
|
-
onChange: value => this.onChange(value),
|
|
1625
|
-
text: value
|
|
1626
|
-
}));
|
|
1627
|
-
}
|
|
1628
|
-
if (this.inlineEdit.type === 'checkbox') {
|
|
1629
|
-
return /*#__PURE__*/_react.default.createElement(_aioButton.default, _extends({
|
|
1630
|
-
attrs: {
|
|
1631
|
-
'data-col-id': colId,
|
|
1632
|
-
'data-row-id': rowId,
|
|
1633
|
-
tabIndex: verticalTabIndex ? colId : 0
|
|
1634
|
-
}
|
|
1635
|
-
}, this.inlineEdit, {
|
|
1636
|
-
className: TableCLS.inlineEditInput,
|
|
1637
|
-
value: value,
|
|
1638
|
-
style: {
|
|
1639
|
-
padding: 0
|
|
1640
|
-
},
|
|
1641
|
-
onChange: value => this.onChange(!value)
|
|
1642
|
-
}));
|
|
1643
|
-
}
|
|
1644
|
-
}
|
|
1645
|
-
let {
|
|
1646
|
-
templates = {}
|
|
1647
|
-
} = this.context;
|
|
1648
|
-
if (column.template && templates[column.template]) {
|
|
1649
|
-
return templates[column.template](rows_object[rowId], details_object[rowId]);
|
|
1650
|
-
} else {
|
|
1651
|
-
return value;
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
async onChange(value) {
|
|
1655
|
-
let {
|
|
1656
|
-
column,
|
|
1657
|
-
rowId
|
|
1658
|
-
} = this.props;
|
|
1659
|
-
let {
|
|
1660
|
-
rows_object,
|
|
1661
|
-
setModel
|
|
1662
|
-
} = this.context;
|
|
1663
|
-
let row = rows_object[rowId];
|
|
1664
|
-
this.setState({
|
|
1665
|
-
loading: true
|
|
1666
|
-
});
|
|
1667
|
-
if (this.inlineEdit.type === 'number' && !isNaN(+value)) {
|
|
1668
|
-
value = +value;
|
|
1669
|
-
}
|
|
1670
|
-
if (this.inlineEdit.onChange) {
|
|
1671
|
-
await this.inlineEdit.onChange(row, value);
|
|
1672
|
-
} else {
|
|
1673
|
-
setModel(this.setCellValue(row, column.field, value));
|
|
1674
|
-
}
|
|
1675
|
-
this.setState({
|
|
1676
|
-
loading: false
|
|
1677
|
-
});
|
|
1678
|
-
}
|
|
1679
|
-
setCellValue(row, field, value) {
|
|
1680
|
-
//row is used in eval
|
|
1681
|
-
let {
|
|
1682
|
-
model
|
|
1683
|
-
} = this.context;
|
|
1684
|
-
let evalText;
|
|
1685
|
-
if (typeof value === 'string') {
|
|
1686
|
-
evalText = `${field} = "${value}"`;
|
|
1687
|
-
} else {
|
|
1688
|
-
evalText = field + ' = ' + JSON.stringify(value);
|
|
1689
|
-
}
|
|
1690
|
-
eval(evalText);
|
|
1691
|
-
return model;
|
|
1692
|
-
}
|
|
1693
|
-
getInlineEdit(row, column) {
|
|
1694
|
-
let inlineEdit = typeof column.inlineEdit === 'function' ? column.inlineEdit(row) : column.inlineEdit;
|
|
1695
|
-
if (!inlineEdit) {
|
|
1696
|
-
return false;
|
|
1697
|
-
}
|
|
1698
|
-
if (inlineEdit === true) {
|
|
1699
|
-
inlineEdit = {};
|
|
1700
|
-
}
|
|
1701
|
-
let {
|
|
1702
|
-
disabled = () => false,
|
|
1703
|
-
type = column.type || 'text'
|
|
1704
|
-
} = inlineEdit;
|
|
1705
|
-
if (disabled(row)) {
|
|
1706
|
-
return false;
|
|
1707
|
-
}
|
|
1708
|
-
return {
|
|
1709
|
-
...inlineEdit,
|
|
1710
|
-
type
|
|
1711
|
-
};
|
|
1712
|
-
}
|
|
1713
|
-
render() {
|
|
1714
|
-
let {
|
|
1715
|
-
getRowById,
|
|
1716
|
-
rowHeight
|
|
1717
|
-
} = this.context;
|
|
1718
|
-
let {
|
|
1719
|
-
column,
|
|
1720
|
-
rowId,
|
|
1721
|
-
value,
|
|
1722
|
-
striped
|
|
1723
|
-
} = this.props;
|
|
1724
|
-
let row = getRowById(rowId);
|
|
1725
|
-
let attrs = {},
|
|
1726
|
-
style = {
|
|
1727
|
-
overflow: 'visible'
|
|
1728
|
-
};
|
|
1729
|
-
if (column.cellAttrs) {
|
|
1730
|
-
attrs = column.cellAttrs(row) || {};
|
|
1731
|
-
if (attrs.style) {
|
|
1732
|
-
style = attrs.style;
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
|
-
if (rowHeight) {
|
|
1736
|
-
style.height = rowHeight;
|
|
1737
|
-
}
|
|
1738
|
-
if (typeof striped === 'string') {
|
|
1739
|
-
style.background = striped;
|
|
1740
|
-
} else if (Array.isArray(striped)) {
|
|
1741
|
-
style.background = striped[0];
|
|
1742
|
-
style.color = striped[1];
|
|
1743
|
-
}
|
|
1744
|
-
style = {
|
|
1745
|
-
justifyContent: column.justify ? 'center' : undefined,
|
|
1746
|
-
...style
|
|
1747
|
-
};
|
|
1748
|
-
this.inlineEdit = this.getInlineEdit(row, column);
|
|
1749
|
-
return /*#__PURE__*/_react.default.createElement(_reactVirtualDom.default, {
|
|
1750
|
-
layout: {
|
|
1751
|
-
className: TableCLS.cell + (attrs.className ? ' ' + attrs.className : '') + (striped === true ? ' striped' : ''),
|
|
1752
|
-
attrs: {
|
|
1753
|
-
...attrs,
|
|
1754
|
-
'data-uniq-id': this.dataUniqId,
|
|
1755
|
-
style: undefined,
|
|
1756
|
-
className: undefined,
|
|
1757
|
-
onClick: attrs.onClick ? () => attrs.onClick(row) : undefined
|
|
1758
|
-
},
|
|
1759
|
-
style,
|
|
1760
|
-
row: [this.indent_layout(column.treeMode, rowId), this.toggle_layout(), this.before_layout(row, column), this.content_layout(row, column, value), this.after_layout(row, column)]
|
|
1761
|
-
}
|
|
1762
|
-
});
|
|
1763
|
-
}
|
|
1764
|
-
indent_layout(treeMode, rowId) {
|
|
1765
|
-
if (!treeMode) {
|
|
1766
|
-
return false;
|
|
1767
|
-
}
|
|
1768
|
-
return this.context.indent_layout(rowId);
|
|
1769
|
-
}
|
|
1770
|
-
toggle_layout() {
|
|
1771
|
-
let {
|
|
1772
|
-
column,
|
|
1773
|
-
rowId
|
|
1774
|
-
} = this.props;
|
|
1775
|
-
if (!column.treeMode) {
|
|
1776
|
-
return false;
|
|
1777
|
-
}
|
|
1778
|
-
let {
|
|
1779
|
-
toggle_layout
|
|
1780
|
-
} = this.context;
|
|
1781
|
-
return toggle_layout(rowId);
|
|
1782
|
-
}
|
|
1783
|
-
before_layout(row, column) {
|
|
1784
|
-
if (!column.before) {
|
|
1785
|
-
return false;
|
|
1786
|
-
}
|
|
1787
|
-
let {
|
|
1788
|
-
state
|
|
1789
|
-
} = this.context;
|
|
1790
|
-
let html = state.getValueByField(row, undefined, column.before);
|
|
1791
|
-
return {
|
|
1792
|
-
row: [{
|
|
1793
|
-
className: TableCLS.cellBefore,
|
|
1794
|
-
html
|
|
1795
|
-
}, {
|
|
1796
|
-
size: 6
|
|
1797
|
-
}]
|
|
1798
|
-
};
|
|
1799
|
-
}
|
|
1800
|
-
content_layout(row, column, value) {
|
|
1801
|
-
let {
|
|
1802
|
-
state
|
|
1803
|
-
} = this.context;
|
|
1804
|
-
let subtext = state.getValueByField(row, undefined, column.subtext);
|
|
1805
|
-
if (subtext) {
|
|
1806
|
-
return {
|
|
1807
|
-
className: TableCLS.cellContent,
|
|
1808
|
-
style: {
|
|
1809
|
-
height: '100%'
|
|
1810
|
-
},
|
|
1811
|
-
align: 'v',
|
|
1812
|
-
flex: 1,
|
|
1813
|
-
column: [{
|
|
1814
|
-
html: this.getContent(row, column, value),
|
|
1815
|
-
align: column.justify ? 'vh' : 'v',
|
|
1816
|
-
style: {
|
|
1817
|
-
overflow: 'visible'
|
|
1818
|
-
}
|
|
1819
|
-
}, {
|
|
1820
|
-
size: 3
|
|
1821
|
-
}, {
|
|
1822
|
-
html: subtext,
|
|
1823
|
-
className: TableCLS.cellSubtext,
|
|
1824
|
-
align: column.justify ? 'vh' : 'v'
|
|
1825
|
-
}]
|
|
1826
|
-
};
|
|
1827
|
-
} else {
|
|
1828
|
-
return {
|
|
1829
|
-
className: TableCLS.cellContent,
|
|
1830
|
-
align: column.justify ? 'vh' : 'v',
|
|
1831
|
-
flex: 1,
|
|
1832
|
-
html: this.getContent(row, column, value),
|
|
1833
|
-
style: {
|
|
1834
|
-
height: '100%'
|
|
1835
|
-
}
|
|
1836
|
-
};
|
|
1837
|
-
}
|
|
1838
|
-
}
|
|
1839
|
-
after_layout(row, column) {
|
|
1840
|
-
if (!column.after) {
|
|
1841
|
-
return false;
|
|
1842
|
-
}
|
|
1843
|
-
let {
|
|
1844
|
-
state
|
|
1845
|
-
} = this.context;
|
|
1846
|
-
let html = state.getValueByField(row, undefined, column.after);
|
|
1847
|
-
return {
|
|
1848
|
-
row: [{
|
|
1849
|
-
className: TableCLS.cellAfter,
|
|
1850
|
-
html
|
|
1851
|
-
}]
|
|
1852
|
-
};
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
_defineProperty(Cell, "contextType", TableContext);
|
|
1856
|
-
function FilterResult(items = [], booleanType = 'or', value, reverse) {
|
|
1857
|
-
let fn = {
|
|
1858
|
-
and() {
|
|
1859
|
-
if (value === undefined) {
|
|
1860
|
-
return false;
|
|
1861
|
-
}
|
|
1862
|
-
for (let i = 0; i < items.length; i++) {
|
|
1863
|
-
let {
|
|
1864
|
-
operator: o,
|
|
1865
|
-
value: v,
|
|
1866
|
-
type
|
|
1867
|
-
} = items[i];
|
|
1868
|
-
if (v === '' || v === undefined) {
|
|
1869
|
-
continue;
|
|
1870
|
-
}
|
|
1871
|
-
let a, b;
|
|
1872
|
-
if (reverse) {
|
|
1873
|
-
a = v;
|
|
1874
|
-
b = value;
|
|
1875
|
-
} else {
|
|
1876
|
-
a = value;
|
|
1877
|
-
b = v;
|
|
1878
|
-
}
|
|
1879
|
-
if (o === 'contain') {
|
|
1880
|
-
if (!this.isContain(a, b)) {
|
|
1881
|
-
return false;
|
|
1882
|
-
}
|
|
1883
|
-
continue;
|
|
1884
|
-
}
|
|
1885
|
-
if (o === 'notContain') {
|
|
1886
|
-
if (this.isContain(a, b)) {
|
|
1887
|
-
return false;
|
|
1888
|
-
}
|
|
1889
|
-
continue;
|
|
1890
|
-
}
|
|
1891
|
-
if (o === 'equal') {
|
|
1892
|
-
if (!this.isEqual(a, b)) {
|
|
1893
|
-
return false;
|
|
1894
|
-
}
|
|
1895
|
-
continue;
|
|
1896
|
-
}
|
|
1897
|
-
if (o === 'notEqual') {
|
|
1898
|
-
if (this.isEqual(a, b)) {
|
|
1899
|
-
return false;
|
|
1900
|
-
}
|
|
1901
|
-
continue;
|
|
1902
|
-
}
|
|
1903
|
-
if (o === 'greater') {
|
|
1904
|
-
if (!this.isGreater(a, b, type)) {
|
|
1905
|
-
return false;
|
|
1906
|
-
}
|
|
1907
|
-
continue;
|
|
1908
|
-
}
|
|
1909
|
-
if (o === 'less') {
|
|
1910
|
-
if (!this.isLess(a, b, type)) {
|
|
1911
|
-
return false;
|
|
1912
|
-
}
|
|
1913
|
-
continue;
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
return true;
|
|
1917
|
-
},
|
|
1918
|
-
or() {
|
|
1919
|
-
if (value === undefined) {
|
|
1920
|
-
return false;
|
|
1921
|
-
}
|
|
1922
|
-
for (let i = 0; i < items.length; i++) {
|
|
1923
|
-
let {
|
|
1924
|
-
operator: o,
|
|
1925
|
-
value: v,
|
|
1926
|
-
type
|
|
1927
|
-
} = items[i];
|
|
1928
|
-
if (v === '' || v === undefined) {
|
|
1929
|
-
return true;
|
|
1930
|
-
}
|
|
1931
|
-
let a, b;
|
|
1932
|
-
if (reverse) {
|
|
1933
|
-
a = v;
|
|
1934
|
-
b = value;
|
|
1935
|
-
} else {
|
|
1936
|
-
a = value;
|
|
1937
|
-
b = v;
|
|
1938
|
-
}
|
|
1939
|
-
if (o === 'contain') {
|
|
1940
|
-
if (this.isContain(a, b)) {
|
|
1941
|
-
return true;
|
|
1942
|
-
}
|
|
1943
|
-
continue;
|
|
1944
|
-
}
|
|
1945
|
-
if (o === 'notContain') {
|
|
1946
|
-
if (!this.isContain(a, b)) {
|
|
1947
|
-
return true;
|
|
1948
|
-
}
|
|
1949
|
-
continue;
|
|
1950
|
-
}
|
|
1951
|
-
if (o === 'equal') {
|
|
1952
|
-
if (this.isEqual(a, b)) {
|
|
1953
|
-
return true;
|
|
1954
|
-
}
|
|
1955
|
-
continue;
|
|
1956
|
-
}
|
|
1957
|
-
if (o === 'notEqual') {
|
|
1958
|
-
if (!this.isEqual(a, b)) {
|
|
1959
|
-
return true;
|
|
1960
|
-
}
|
|
1961
|
-
continue;
|
|
1962
|
-
}
|
|
1963
|
-
if (o === 'greater') {
|
|
1964
|
-
if (this.isGreater(a, b, type)) {
|
|
1965
|
-
return true;
|
|
1966
|
-
}
|
|
1967
|
-
continue;
|
|
1968
|
-
}
|
|
1969
|
-
if (o === 'less') {
|
|
1970
|
-
if (this.isLess(a, b, type)) {
|
|
1971
|
-
return true;
|
|
1972
|
-
}
|
|
1973
|
-
continue;
|
|
1974
|
-
}
|
|
1975
|
-
}
|
|
1976
|
-
return false;
|
|
1977
|
-
},
|
|
1978
|
-
isContain(text, subtext) {
|
|
1979
|
-
return text.toString().toLowerCase().indexOf(subtext.toString().toLowerCase()) !== -1;
|
|
1980
|
-
},
|
|
1981
|
-
isEqual(a, b) {
|
|
1982
|
-
return a.toString().toLowerCase() === b.toString().toLowerCase();
|
|
1983
|
-
},
|
|
1984
|
-
isGreater(a, b, type) {
|
|
1985
|
-
if (type === 'date') {
|
|
1986
|
-
return this.getDateNumber(a) > this.getDateNumber(b);
|
|
1987
|
-
}
|
|
1988
|
-
return parseFloat(a) > parseFloat(b);
|
|
1989
|
-
},
|
|
1990
|
-
getDateNumber(value) {
|
|
1991
|
-
let splitter;
|
|
1992
|
-
for (let i = 0; i < value.length; i++) {
|
|
1993
|
-
if (isNaN(parseInt(value[i]))) {
|
|
1994
|
-
splitter = value[i];
|
|
1995
|
-
break;
|
|
1996
|
-
}
|
|
1997
|
-
}
|
|
1998
|
-
let [year, month = '01', day = '01'] = value.split(splitter);
|
|
1999
|
-
let list = [year, month, day];
|
|
2000
|
-
return parseInt(list.map(o => o.length === 1 ? '0' + o : o).join(''));
|
|
2001
|
-
},
|
|
2002
|
-
isLess(a, b, type) {
|
|
2003
|
-
if (type === 'date') {
|
|
2004
|
-
return this.getDateNumber(a) < this.getDateNumber(b);
|
|
2005
|
-
}
|
|
2006
|
-
return parseFloat(a) < parseFloat(b);
|
|
2007
|
-
}
|
|
2008
|
-
};
|
|
2009
|
-
if (items.length) {
|
|
2010
|
-
return fn[booleanType]();
|
|
2011
|
-
}
|
|
2012
|
-
return true;
|
|
2013
|
-
}
|
|
2014
|
-
class AIOTableFilterPopup extends _react.Component {
|
|
2015
|
-
title_layout() {
|
|
2016
|
-
let {
|
|
2017
|
-
title
|
|
2018
|
-
} = this.props;
|
|
2019
|
-
return {
|
|
2020
|
-
html: title,
|
|
2021
|
-
style: {
|
|
2022
|
-
padding: '0 6px'
|
|
2023
|
-
}
|
|
2024
|
-
};
|
|
2025
|
-
}
|
|
2026
|
-
items_layout() {
|
|
2027
|
-
let {
|
|
2028
|
-
items
|
|
2029
|
-
} = this.props;
|
|
2030
|
-
return {
|
|
2031
|
-
column: items.map((item, i) => {
|
|
2032
|
-
return {
|
|
2033
|
-
column: [this.item_layout(item, i), this.boolean_layout(i)]
|
|
2034
|
-
};
|
|
2035
|
-
})
|
|
2036
|
-
};
|
|
2037
|
-
}
|
|
2038
|
-
item_layout(item, itemIndex) {
|
|
2039
|
-
let {
|
|
2040
|
-
type,
|
|
2041
|
-
items,
|
|
2042
|
-
onChange,
|
|
2043
|
-
translate = str => str,
|
|
2044
|
-
add,
|
|
2045
|
-
operators,
|
|
2046
|
-
valueOptions
|
|
2047
|
-
} = this.props;
|
|
2048
|
-
return {
|
|
2049
|
-
html: /*#__PURE__*/_react.default.createElement(AIOfilterItem, {
|
|
2050
|
-
operator: item.operator,
|
|
2051
|
-
value: item.value,
|
|
2052
|
-
type: type,
|
|
2053
|
-
translate: translate,
|
|
2054
|
-
operators: operators,
|
|
2055
|
-
operatorOptions: this.operatorOptions,
|
|
2056
|
-
valueOptions: valueOptions,
|
|
2057
|
-
add: add,
|
|
2058
|
-
onChange: (key, value) => {
|
|
2059
|
-
onChange(items.map((o, i) => {
|
|
2060
|
-
if (itemIndex === i) {
|
|
2061
|
-
return {
|
|
2062
|
-
...o,
|
|
2063
|
-
[key]: value
|
|
2064
|
-
};
|
|
2065
|
-
}
|
|
2066
|
-
return o;
|
|
2067
|
-
}));
|
|
2068
|
-
},
|
|
2069
|
-
onRemove: add === false ? undefined : () => onChange(items.filter((o, i) => i !== itemIndex))
|
|
2070
|
-
})
|
|
2071
|
-
};
|
|
2072
|
-
}
|
|
2073
|
-
getOperatorOptions() {
|
|
2074
|
-
let {
|
|
2075
|
-
translate,
|
|
2076
|
-
type,
|
|
2077
|
-
operators = ['contain', 'notContain', 'equal', 'notEqual', 'greater', 'less']
|
|
2078
|
-
} = this.props;
|
|
2079
|
-
return [{
|
|
2080
|
-
text: translate('Contain'),
|
|
2081
|
-
value: 'contain',
|
|
2082
|
-
show: type === 'text' && operators.indexOf('contain') !== -1
|
|
2083
|
-
}, {
|
|
2084
|
-
text: translate('Not Contain'),
|
|
2085
|
-
value: 'notContain',
|
|
2086
|
-
show: type === 'text' && operators.indexOf('notContain') !== -1
|
|
2087
|
-
}, {
|
|
2088
|
-
text: translate('Equal'),
|
|
2089
|
-
value: 'equal',
|
|
2090
|
-
show: operators.indexOf('equal') !== -1
|
|
2091
|
-
}, {
|
|
2092
|
-
text: translate('Not Equal'),
|
|
2093
|
-
value: 'notEqual',
|
|
2094
|
-
show: operators.indexOf('notEqual') !== -1
|
|
2095
|
-
}, {
|
|
2096
|
-
text: translate('Greater Than'),
|
|
2097
|
-
value: 'greater',
|
|
2098
|
-
show: (type === 'date' || type === 'number') && operators.indexOf('greater') !== -1
|
|
2099
|
-
}, {
|
|
2100
|
-
text: translate('Less Than'),
|
|
2101
|
-
value: 'less',
|
|
2102
|
-
show: (type === 'date' || type === 'number') && operators.indexOf('less') !== -1
|
|
2103
|
-
}];
|
|
2104
|
-
}
|
|
2105
|
-
boolean_layout(index) {
|
|
2106
|
-
let {
|
|
2107
|
-
items,
|
|
2108
|
-
translate = text => text,
|
|
2109
|
-
booleanType,
|
|
2110
|
-
onChangeBooleanType
|
|
2111
|
-
} = this.props;
|
|
2112
|
-
if (index >= items.length - 1) {
|
|
2113
|
-
return false;
|
|
2114
|
-
}
|
|
2115
|
-
return {
|
|
2116
|
-
html: translate(booleanType),
|
|
2117
|
-
attrs: {
|
|
2118
|
-
onClick: () => onChangeBooleanType(booleanType === 'or' ? 'and' : 'or')
|
|
2119
|
-
},
|
|
2120
|
-
align: 'vh'
|
|
2121
|
-
};
|
|
2122
|
-
}
|
|
2123
|
-
add_layout() {
|
|
2124
|
-
var {
|
|
2125
|
-
type,
|
|
2126
|
-
items,
|
|
2127
|
-
onChange,
|
|
2128
|
-
translate = str => str,
|
|
2129
|
-
add
|
|
2130
|
-
} = this.props;
|
|
2131
|
-
if (add === false) {
|
|
2132
|
-
return false;
|
|
2133
|
-
}
|
|
2134
|
-
return {
|
|
2135
|
-
html: /*#__PURE__*/_react.default.createElement("button", {
|
|
2136
|
-
className: TableCLS.addFilter,
|
|
2137
|
-
onClick: () => onChange(items.concat({
|
|
2138
|
-
operator: this.operatorOptions[0].value,
|
|
2139
|
-
value: '',
|
|
2140
|
-
type
|
|
2141
|
-
}))
|
|
2142
|
-
}, translate('Add'))
|
|
2143
|
-
};
|
|
2144
|
-
}
|
|
2145
|
-
render() {
|
|
2146
|
-
this.operatorOptions = this.getOperatorOptions();
|
|
2147
|
-
return /*#__PURE__*/_react.default.createElement(_reactVirtualDom.default, {
|
|
2148
|
-
layout: {
|
|
2149
|
-
className: TableCLS.filterPopup,
|
|
2150
|
-
style: {
|
|
2151
|
-
minWidth: 250
|
|
2152
|
-
},
|
|
2153
|
-
column: [this.title_layout(), this.items_layout(), this.add_layout()]
|
|
2154
|
-
}
|
|
2155
|
-
});
|
|
2156
|
-
}
|
|
2157
|
-
}
|
|
2158
|
-
class AIOfilterItem extends _react.Component {
|
|
2159
|
-
constructor(props) {
|
|
2160
|
-
super(props);
|
|
2161
|
-
let {
|
|
2162
|
-
value
|
|
2163
|
-
} = this.props;
|
|
2164
|
-
this.state = {
|
|
2165
|
-
value,
|
|
2166
|
-
prevValue: value
|
|
2167
|
-
};
|
|
2168
|
-
}
|
|
2169
|
-
operator_layout() {
|
|
2170
|
-
let {
|
|
2171
|
-
onChange,
|
|
2172
|
-
operator,
|
|
2173
|
-
operatorOptions,
|
|
2174
|
-
add,
|
|
2175
|
-
title
|
|
2176
|
-
} = this.props;
|
|
2177
|
-
if (add === false) {
|
|
2178
|
-
return false;
|
|
2179
|
-
}
|
|
2180
|
-
if (operatorOptions.filter(({
|
|
2181
|
-
show
|
|
2182
|
-
}) => show !== false).length === 1) {
|
|
2183
|
-
return {
|
|
2184
|
-
size: 90,
|
|
2185
|
-
html: /*#__PURE__*/_react.default.createElement(_aioButton.default, {
|
|
2186
|
-
style: {
|
|
2187
|
-
width: '100%'
|
|
2188
|
-
},
|
|
2189
|
-
type: "button",
|
|
2190
|
-
className: TableCLS.filterOperator,
|
|
2191
|
-
text: operator
|
|
2192
|
-
})
|
|
2193
|
-
};
|
|
2194
|
-
}
|
|
2195
|
-
return {
|
|
2196
|
-
size: 90,
|
|
2197
|
-
html: /*#__PURE__*/_react.default.createElement(_aioButton.default, {
|
|
2198
|
-
style: {
|
|
2199
|
-
width: '100%'
|
|
2200
|
-
},
|
|
2201
|
-
type: "select",
|
|
2202
|
-
className: TableCLS.filterOperator,
|
|
2203
|
-
value: operator,
|
|
2204
|
-
options: operatorOptions,
|
|
2205
|
-
onChange: value => onChange('operator', value)
|
|
2206
|
-
})
|
|
2207
|
-
};
|
|
2208
|
-
}
|
|
2209
|
-
value_layout() {
|
|
2210
|
-
let {
|
|
2211
|
-
type,
|
|
2212
|
-
onChange,
|
|
2213
|
-
valueOptions
|
|
2214
|
-
} = this.props;
|
|
2215
|
-
let {
|
|
2216
|
-
value
|
|
2217
|
-
} = this.state;
|
|
2218
|
-
if (valueOptions) {
|
|
2219
|
-
return {
|
|
2220
|
-
flex: 1,
|
|
2221
|
-
html: /*#__PURE__*/_react.default.createElement("select", {
|
|
2222
|
-
className: TableCLS.filterValue,
|
|
2223
|
-
type: type === 'number' ? 'number' : 'text',
|
|
2224
|
-
value: value,
|
|
2225
|
-
onChange: e => {
|
|
2226
|
-
let value = e.target.value;
|
|
2227
|
-
clearTimeout(this.timeout);
|
|
2228
|
-
this.setState({
|
|
2229
|
-
value
|
|
2230
|
-
});
|
|
2231
|
-
onChange('value', value);
|
|
2232
|
-
}
|
|
2233
|
-
}, valueOptions.map(({
|
|
2234
|
-
value,
|
|
2235
|
-
text
|
|
2236
|
-
}) => {
|
|
2237
|
-
return /*#__PURE__*/_react.default.createElement("option", {
|
|
2238
|
-
value: value
|
|
2239
|
-
}, text);
|
|
2240
|
-
}))
|
|
2241
|
-
};
|
|
2242
|
-
}
|
|
2243
|
-
return {
|
|
2244
|
-
flex: 1,
|
|
2245
|
-
html: /*#__PURE__*/_react.default.createElement("input", {
|
|
2246
|
-
className: TableCLS.filterValue,
|
|
2247
|
-
type: type === 'number' ? 'number' : 'text',
|
|
2248
|
-
value: value,
|
|
2249
|
-
onChange: e => {
|
|
2250
|
-
let value = e.target.value;
|
|
2251
|
-
clearTimeout(this.timeout);
|
|
2252
|
-
this.setState({
|
|
2253
|
-
value
|
|
2254
|
-
});
|
|
2255
|
-
this.timeout = setTimeout(() => onChange('value', value), 1000);
|
|
2256
|
-
}
|
|
2257
|
-
})
|
|
2258
|
-
};
|
|
2259
|
-
}
|
|
2260
|
-
remove_layout() {
|
|
2261
|
-
let {
|
|
2262
|
-
onRemove
|
|
2263
|
-
} = this.props;
|
|
2264
|
-
if (!onRemove) {
|
|
2265
|
-
return false;
|
|
2266
|
-
}
|
|
2267
|
-
return {
|
|
2268
|
-
size: 24,
|
|
2269
|
-
html: /*#__PURE__*/_react.default.createElement(_react2.Icon, {
|
|
2270
|
-
path: _js.mdiClose,
|
|
2271
|
-
size: 0.6,
|
|
2272
|
-
onClick: () => onRemove()
|
|
2273
|
-
}),
|
|
2274
|
-
align: 'vh',
|
|
2275
|
-
className: TableCLS.filterRemove
|
|
2276
|
-
};
|
|
2277
|
-
}
|
|
2278
|
-
render() {
|
|
2279
|
-
if (this.state.prevValue !== this.props.value) {
|
|
2280
|
-
setTimeout(() => this.setState({
|
|
2281
|
-
value: this.props.value,
|
|
2282
|
-
prevValue: this.props.value
|
|
2283
|
-
}), 0);
|
|
2284
|
-
}
|
|
2285
|
-
return /*#__PURE__*/_react.default.createElement(_reactVirtualDom.default, {
|
|
2286
|
-
layout: {
|
|
2287
|
-
className: TableCLS.filterItem,
|
|
2288
|
-
gap: 3,
|
|
2289
|
-
row: [this.operator_layout(), this.value_layout(), this.remove_layout()]
|
|
2290
|
-
}
|
|
2291
|
-
});
|
|
2292
|
-
}
|
|
2293
|
-
}
|
|
2294
|
-
function Sort(getProps, getState, setColumns) {
|
|
2295
|
-
let o = {
|
|
2296
|
-
get() {
|
|
2297
|
-
let {
|
|
2298
|
-
columns = [],
|
|
2299
|
-
setColumn
|
|
2300
|
-
} = getState();
|
|
2301
|
-
let sorts = [];
|
|
2302
|
-
for (let i = 0; i < columns.length; i++) {
|
|
2303
|
-
if (!columns[i].sort) {
|
|
2304
|
-
continue;
|
|
2305
|
-
}
|
|
2306
|
-
if (typeof columns[i].sort !== 'object') {
|
|
2307
|
-
let column = columns[i];
|
|
2308
|
-
setColumn(column, {
|
|
2309
|
-
sort: {}
|
|
2310
|
-
});
|
|
2311
|
-
}
|
|
2312
|
-
let {
|
|
2313
|
-
sort,
|
|
2314
|
-
type = 'text',
|
|
2315
|
-
field,
|
|
2316
|
-
dataColumnId,
|
|
2317
|
-
title
|
|
2318
|
-
} = columns[i];
|
|
2319
|
-
let {
|
|
2320
|
-
dir = 'inc',
|
|
2321
|
-
order,
|
|
2322
|
-
active = true,
|
|
2323
|
-
toggle = true
|
|
2324
|
-
} = sort;
|
|
2325
|
-
if (order === undefined) {
|
|
2326
|
-
let newOrder = 0;
|
|
2327
|
-
let orders = columns.filter(({
|
|
2328
|
-
sort
|
|
2329
|
-
}) => sort && sort.order !== undefined).map(({
|
|
2330
|
-
sort
|
|
2331
|
-
}) => sort.order);
|
|
2332
|
-
while (orders.indexOf(newOrder) !== -1) {
|
|
2333
|
-
newOrder++;
|
|
2334
|
-
}
|
|
2335
|
-
sort.order = newOrder;
|
|
2336
|
-
}
|
|
2337
|
-
sorts.push({
|
|
2338
|
-
dir,
|
|
2339
|
-
order: sort.order,
|
|
2340
|
-
type,
|
|
2341
|
-
field,
|
|
2342
|
-
active,
|
|
2343
|
-
toggle,
|
|
2344
|
-
dataColumnId,
|
|
2345
|
-
title
|
|
2346
|
-
});
|
|
2347
|
-
}
|
|
2348
|
-
sorts = sorts.sort(({
|
|
2349
|
-
order: a
|
|
2350
|
-
}, {
|
|
2351
|
-
order: b
|
|
2352
|
-
}) => a - b);
|
|
2353
|
-
return sorts;
|
|
2354
|
-
},
|
|
2355
|
-
sort(model, sorts) {
|
|
2356
|
-
let {
|
|
2357
|
-
getValueByField
|
|
2358
|
-
} = getState();
|
|
2359
|
-
return model.sort((a, b) => {
|
|
2360
|
-
for (let i = 0; i < sorts.length; i++) {
|
|
2361
|
-
let {
|
|
2362
|
-
field,
|
|
2363
|
-
dir,
|
|
2364
|
-
active
|
|
2365
|
-
} = sorts[i];
|
|
2366
|
-
if (!active) {
|
|
2367
|
-
continue;
|
|
2368
|
-
}
|
|
2369
|
-
let aValue = getValueByField(a, undefined, field),
|
|
2370
|
-
bValue = getValueByField(b, undefined, field);
|
|
2371
|
-
if (aValue < bValue) {
|
|
2372
|
-
return -1 * (dir === 'dec' ? -1 : 1);
|
|
2373
|
-
}
|
|
2374
|
-
if (aValue > bValue) {
|
|
2375
|
-
return 1 * (dir === 'dec' ? -1 : 1);
|
|
2376
|
-
}
|
|
2377
|
-
if (i === sorts.length - 1) {
|
|
2378
|
-
return 0;
|
|
2379
|
-
}
|
|
2380
|
-
}
|
|
2381
|
-
return 0;
|
|
2382
|
-
});
|
|
2383
|
-
},
|
|
2384
|
-
updateColumns(sorts) {
|
|
2385
|
-
let {
|
|
2386
|
-
columns,
|
|
2387
|
-
saveColumnInStorage
|
|
2388
|
-
} = getState();
|
|
2389
|
-
for (let i = 0; i < sorts.length; i++) {
|
|
2390
|
-
let sort = sorts[i];
|
|
2391
|
-
let {
|
|
2392
|
-
dir,
|
|
2393
|
-
active,
|
|
2394
|
-
dataColumnId
|
|
2395
|
-
} = sort;
|
|
2396
|
-
let column = columns.filter(c => c.dataColumnId === dataColumnId)[0];
|
|
2397
|
-
column.sort = {
|
|
2398
|
-
...column.sort,
|
|
2399
|
-
dir,
|
|
2400
|
-
active,
|
|
2401
|
-
order: i
|
|
2402
|
-
};
|
|
2403
|
-
saveColumnInStorage(column, 'sort', column.sort);
|
|
2404
|
-
}
|
|
2405
|
-
setColumns(columns);
|
|
2406
|
-
},
|
|
2407
|
-
async set(sorts) {
|
|
2408
|
-
sorts = sorts || this.get();
|
|
2409
|
-
if (!sorts.length) {
|
|
2410
|
-
return;
|
|
2411
|
-
}
|
|
2412
|
-
let {
|
|
2413
|
-
model,
|
|
2414
|
-
onChangeSorts,
|
|
2415
|
-
setModel
|
|
2416
|
-
} = getProps();
|
|
2417
|
-
if (onChangeSorts) {
|
|
2418
|
-
let res = await onChangeSorts(sorts, this.sort(model, sorts));
|
|
2419
|
-
if (res !== false) {
|
|
2420
|
-
this.updateColumns(sorts);
|
|
2421
|
-
}
|
|
2422
|
-
} else if (setModel) {
|
|
2423
|
-
setModel(this.sort(model, sorts));
|
|
2424
|
-
this.updateColumns(sorts);
|
|
2425
|
-
} else {
|
|
2426
|
-
console.error('AIOTable Error => you set sort in columns but missing setModel or onChangeSort props.');
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
|
-
};
|
|
2430
|
-
return {
|
|
2431
|
-
set: o.set.bind(o),
|
|
2432
|
-
get: o.get.bind(o)
|
|
2433
|
-
};
|
|
2434
|
-
}
|
|
2435
|
-
function Group(getProps, getState, setColumns) {
|
|
2436
|
-
let o = {
|
|
2437
|
-
getGroupModel(model, groups) {
|
|
2438
|
-
let {
|
|
2439
|
-
getValueByField
|
|
2440
|
-
} = getState();
|
|
2441
|
-
let newModel = {};
|
|
2442
|
-
for (let i = 0; i < model.length; i++) {
|
|
2443
|
-
let row = model[i],
|
|
2444
|
-
obj = newModel,
|
|
2445
|
-
values = groups.map(group => getValueByField(row, undefined, group.field));
|
|
2446
|
-
//let show = row._detail._show
|
|
2447
|
-
for (let j = 0; j < values.length; j++) {
|
|
2448
|
-
let value = values[j];
|
|
2449
|
-
if (j === values.length - 1) {
|
|
2450
|
-
obj[value] = obj[value] || [];
|
|
2451
|
-
obj[value].push(row);
|
|
2452
|
-
} else {
|
|
2453
|
-
obj[value] = obj[value] || {};
|
|
2454
|
-
obj = obj[value];
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
}
|
|
2458
|
-
return newModel;
|
|
2459
|
-
},
|
|
2460
|
-
getGroupRows(model) {
|
|
2461
|
-
var {
|
|
2462
|
-
groupsOpen
|
|
2463
|
-
} = getState();
|
|
2464
|
-
function msf(obj, level, parents) {
|
|
2465
|
-
if (Array.isArray(obj)) {
|
|
2466
|
-
groupedRows = groupedRows.concat(obj);
|
|
2467
|
-
} else {
|
|
2468
|
-
for (var prop in obj) {
|
|
2469
|
-
let newParents = parents.concat(prop),
|
|
2470
|
-
id = newParents.toString();
|
|
2471
|
-
groupsOpen[id] = groupsOpen[id] === undefined ? true : groupsOpen[id];
|
|
2472
|
-
groupedRows.push({
|
|
2473
|
-
_isGroup_: true,
|
|
2474
|
-
value: prop,
|
|
2475
|
-
id,
|
|
2476
|
-
groupLevel: level,
|
|
2477
|
-
groupOpen: groupsOpen[id]
|
|
2478
|
-
});
|
|
2479
|
-
if (groupsOpen[id]) {
|
|
2480
|
-
msf(obj[prop], level + 1, newParents);
|
|
2481
|
-
}
|
|
2482
|
-
}
|
|
2483
|
-
}
|
|
2484
|
-
}
|
|
2485
|
-
var groupedRows = [],
|
|
2486
|
-
level = 0;
|
|
2487
|
-
msf(model, level, []);
|
|
2488
|
-
return groupedRows;
|
|
2489
|
-
},
|
|
2490
|
-
groupBy(model, groups = []) {
|
|
2491
|
-
if (!groups.length) {
|
|
2492
|
-
return model;
|
|
2493
|
-
}
|
|
2494
|
-
const groupModel = this.getGroupModel(model, groups);
|
|
2495
|
-
return this.getGroupRows(groupModel);
|
|
2496
|
-
},
|
|
2497
|
-
updateColumns(groups) {
|
|
2498
|
-
let {
|
|
2499
|
-
columns = [],
|
|
2500
|
-
saveColumnInStorage
|
|
2501
|
-
} = getState();
|
|
2502
|
-
for (let i = 0; i < groups.length; i++) {
|
|
2503
|
-
let group = groups[i];
|
|
2504
|
-
let {
|
|
2505
|
-
active,
|
|
2506
|
-
dataColumnId
|
|
2507
|
-
} = group;
|
|
2508
|
-
let column = columns.filter(c => c.dataColumnId === dataColumnId)[0];
|
|
2509
|
-
column.group = {
|
|
2510
|
-
...column.group,
|
|
2511
|
-
active,
|
|
2512
|
-
order: i
|
|
2513
|
-
};
|
|
2514
|
-
saveColumnInStorage(column, 'group', column.group);
|
|
2515
|
-
}
|
|
2516
|
-
setColumns(columns);
|
|
2517
|
-
},
|
|
2518
|
-
get() {
|
|
2519
|
-
let {
|
|
2520
|
-
columns = []
|
|
2521
|
-
} = getState();
|
|
2522
|
-
let groups = [];
|
|
2523
|
-
for (let i = 0; i < columns.length; i++) {
|
|
2524
|
-
if (!columns[i].group) {
|
|
2525
|
-
continue;
|
|
2526
|
-
}
|
|
2527
|
-
if (typeof columns[i].group !== 'object') {
|
|
2528
|
-
columns[i].group = {};
|
|
2529
|
-
}
|
|
2530
|
-
let {
|
|
2531
|
-
group,
|
|
2532
|
-
type = 'text',
|
|
2533
|
-
field,
|
|
2534
|
-
dataColumnId,
|
|
2535
|
-
title
|
|
2536
|
-
} = columns[i];
|
|
2537
|
-
let {
|
|
2538
|
-
order,
|
|
2539
|
-
active = true
|
|
2540
|
-
} = group;
|
|
2541
|
-
if (order === undefined) {
|
|
2542
|
-
let newOrder = 0;
|
|
2543
|
-
let orders = columns.filter(({
|
|
2544
|
-
group
|
|
2545
|
-
}) => group && group.order !== undefined).map(({
|
|
2546
|
-
group
|
|
2547
|
-
}) => group.order);
|
|
2548
|
-
while (orders.indexOf(newOrder) !== -1) {
|
|
2549
|
-
newOrder++;
|
|
2550
|
-
}
|
|
2551
|
-
group.order = newOrder;
|
|
2552
|
-
}
|
|
2553
|
-
groups.push({
|
|
2554
|
-
order: group.order,
|
|
2555
|
-
type,
|
|
2556
|
-
field,
|
|
2557
|
-
active,
|
|
2558
|
-
dataColumnId,
|
|
2559
|
-
title
|
|
2560
|
-
});
|
|
2561
|
-
}
|
|
2562
|
-
groups = groups.sort(({
|
|
2563
|
-
order: a
|
|
2564
|
-
}, {
|
|
2565
|
-
order: b
|
|
2566
|
-
}) => a - b);
|
|
2567
|
-
return groups;
|
|
2568
|
-
},
|
|
2569
|
-
set(groups) {
|
|
2570
|
-
this.updateColumns(groups);
|
|
2571
|
-
}
|
|
2572
|
-
};
|
|
2573
|
-
return {
|
|
2574
|
-
get: o.get.bind(o),
|
|
2575
|
-
set: o.set.bind(o),
|
|
2576
|
-
groupBy: o.groupBy.bind(o)
|
|
2577
|
-
};
|
|
2578
|
-
}
|
|
2579
|
-
function Excel(getProps) {
|
|
2580
|
-
let o = {
|
|
2581
|
-
fixPersianAndArabicNumbers(str) {
|
|
2582
|
-
if (typeof srt !== 'string') {
|
|
2583
|
-
return str;
|
|
2584
|
-
}
|
|
2585
|
-
var persianNumbers = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g],
|
|
2586
|
-
arabicNumbers = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g];
|
|
2587
|
-
for (var i = 0; i < 10; i++) {
|
|
2588
|
-
str = str.replace(persianNumbers[i], i).replace(arabicNumbers[i], i);
|
|
2589
|
-
}
|
|
2590
|
-
return str;
|
|
2591
|
-
},
|
|
2592
|
-
getJSON(rows) {
|
|
2593
|
-
let result = [];
|
|
2594
|
-
for (let i = 0; i < rows.length; i++) {
|
|
2595
|
-
let json = rows[i],
|
|
2596
|
-
fixedJson = {};
|
|
2597
|
-
for (let prop in json) {
|
|
2598
|
-
fixedJson[prop] = this.fixPersianAndArabicNumbers(json[prop]);
|
|
2599
|
-
}
|
|
2600
|
-
result.push(fixedJson);
|
|
2601
|
-
}
|
|
2602
|
-
return result;
|
|
2603
|
-
},
|
|
2604
|
-
export(rows) {
|
|
2605
|
-
let {
|
|
2606
|
-
translate
|
|
2607
|
-
} = getProps();
|
|
2608
|
-
let name = window.prompt(translate('Inter Excel File Name'));
|
|
2609
|
-
if (!name || name === null || !name.length) return;
|
|
2610
|
-
var data = this.getJSON(rows);
|
|
2611
|
-
var arrData = typeof data != "object" ? JSON.parse(data) : data;
|
|
2612
|
-
var CSV = "";
|
|
2613
|
-
// CSV += 'title';
|
|
2614
|
-
CSV += '\r\n\n';
|
|
2615
|
-
if (true) {
|
|
2616
|
-
let row = "";
|
|
2617
|
-
for (let index in arrData[0]) {
|
|
2618
|
-
row += index + ",";
|
|
2619
|
-
}
|
|
2620
|
-
row = row.slice(0, -1);
|
|
2621
|
-
CSV += row + "\r\n";
|
|
2622
|
-
}
|
|
2623
|
-
for (var i = 0; i < arrData.length; i++) {
|
|
2624
|
-
let row = "";
|
|
2625
|
-
for (let index in arrData[i]) {
|
|
2626
|
-
row += '"' + arrData[i][index] + '",';
|
|
2627
|
-
}
|
|
2628
|
-
row.slice(0, row.length - 1);
|
|
2629
|
-
CSV += row + "\r\n";
|
|
2630
|
-
}
|
|
2631
|
-
if (CSV === "") {
|
|
2632
|
-
alert("Invalid data");
|
|
2633
|
-
return;
|
|
2634
|
-
}
|
|
2635
|
-
var fileName = name.replace(/ /g, "_");
|
|
2636
|
-
var universalBOM = "\uFEFF";
|
|
2637
|
-
var uri = "data:text/csv;charset=utf-8," + encodeURIComponent(universalBOM + CSV);
|
|
2638
|
-
var link = document.createElement("a");
|
|
2639
|
-
link.href = uri;
|
|
2640
|
-
link.style = "visibility:hidden";
|
|
2641
|
-
link.download = fileName + ".csv";
|
|
2642
|
-
document.body.appendChild(link);
|
|
2643
|
-
link.click();
|
|
2644
|
-
document.body.removeChild(link);
|
|
2645
|
-
}
|
|
2646
|
-
};
|
|
2647
|
-
return {
|
|
2648
|
-
export: o.export.bind(o)
|
|
2649
|
-
};
|
|
2650
|
-
}
|
|
2651
|
-
let functions = {
|
|
2652
|
-
async onScroll(index) {
|
|
2653
|
-
let {
|
|
2654
|
-
lazyLoad = {}
|
|
2655
|
-
} = this.props;
|
|
2656
|
-
let {
|
|
2657
|
-
onScrollEnd
|
|
2658
|
-
} = lazyLoad;
|
|
2659
|
-
if (onScrollEnd) {
|
|
2660
|
-
// if(index === undefined || index === 0){
|
|
2661
|
-
// let table = $(this.dom.current).find('.' + TableCLS.rows);
|
|
2662
|
-
// let scrollTop = table.scrollTop();
|
|
2663
|
-
// let scrollHeight = table[0].scrollHeight;
|
|
2664
|
-
// let height = table.height();
|
|
2665
|
-
// if(scrollTop + height === scrollHeight){
|
|
2666
|
-
// let {startIndex} = getState();
|
|
2667
|
-
// let {lazyLength,totalLength} = lazyLoad;
|
|
2668
|
-
// let from = startIndex + lazyLength;
|
|
2669
|
-
// if(from > totalLength){return;}
|
|
2670
|
-
// let to = from + lazyLength;
|
|
2671
|
-
// if(to > totalLength){to = totalLength;}
|
|
2672
|
-
// let a = $(dom.current).find('.aio-table-main-loading')
|
|
2673
|
-
// a.css({display:'flex'})
|
|
2674
|
-
// let res = await onScrollEnd(from,to);
|
|
2675
|
-
// a.css({display:'none'})
|
|
2676
|
-
// if(res !== false){
|
|
2677
|
-
// setState({startIndex:from})
|
|
2678
|
-
// }
|
|
2679
|
-
// }
|
|
2680
|
-
// }
|
|
2681
|
-
}
|
|
2682
|
-
if (index === undefined) {
|
|
2683
|
-
return;
|
|
2684
|
-
}
|
|
2685
|
-
if (!this['scroll' + index]) {
|
|
2686
|
-
let otherIndex = Number(!index);
|
|
2687
|
-
this['scroll' + otherIndex] = true;
|
|
2688
|
-
let c = (0, _jquery.default)(this.dom.current);
|
|
2689
|
-
var units = [c.find('.' + TableCLS.freezeContainer), c.find('.' + TableCLS.unfreezeContainer)];
|
|
2690
|
-
var scrollTop = units[index].scrollTop();
|
|
2691
|
-
units[otherIndex].scrollTop(scrollTop);
|
|
2692
|
-
}
|
|
2693
|
-
this['scroll' + index] = false;
|
|
2694
|
-
},
|
|
2695
|
-
getValueByField(row, column, field) {
|
|
2696
|
-
try {
|
|
2697
|
-
if (field === undefined) {
|
|
2698
|
-
field = column.field;
|
|
2699
|
-
}
|
|
2700
|
-
let type = typeof field;
|
|
2701
|
-
if (type === 'function') {
|
|
2702
|
-
return field(row, column);
|
|
2703
|
-
}
|
|
2704
|
-
if (type === 'string') {
|
|
2705
|
-
if (field.indexOf('.') !== -1 && (field.indexOf('row') !== -1 || field.indexOf('column') !== -1 || field.indexOf('props') !== -1)) {
|
|
2706
|
-
let result;
|
|
2707
|
-
eval('result = ' + field);
|
|
2708
|
-
return result;
|
|
2709
|
-
}
|
|
2710
|
-
return field;
|
|
2711
|
-
}
|
|
2712
|
-
return field;
|
|
2713
|
-
} catch {
|
|
2714
|
-
return;
|
|
2715
|
-
}
|
|
2716
|
-
},
|
|
2717
|
-
getSearchs() {
|
|
2718
|
-
let {
|
|
2719
|
-
columns = []
|
|
2720
|
-
} = this.state;
|
|
2721
|
-
let searchs = [];
|
|
2722
|
-
for (let i = 0; i < columns.length; i++) {
|
|
2723
|
-
let {
|
|
2724
|
-
show = true,
|
|
2725
|
-
search,
|
|
2726
|
-
field
|
|
2727
|
-
} = columns[i];
|
|
2728
|
-
if (!show || !search) {
|
|
2729
|
-
continue;
|
|
2730
|
-
}
|
|
2731
|
-
searchs.push(field);
|
|
2732
|
-
}
|
|
2733
|
-
return searchs;
|
|
2734
|
-
},
|
|
2735
|
-
getFilterResult(row, detail) {
|
|
2736
|
-
let {
|
|
2737
|
-
searchText,
|
|
2738
|
-
getValueByField
|
|
2739
|
-
} = this.state;
|
|
2740
|
-
let searchs = this.getSearchs();
|
|
2741
|
-
if (searchText && searchs.length) {
|
|
2742
|
-
let items = searchs.map(field => {
|
|
2743
|
-
return {
|
|
2744
|
-
operator: 'contain',
|
|
2745
|
-
value: getValueByField(row, undefined, field).toString()
|
|
2746
|
-
};
|
|
2747
|
-
});
|
|
2748
|
-
if (FilterResult(items, 'or', searchText, true) === false) {
|
|
2749
|
-
return false;
|
|
2750
|
-
}
|
|
2751
|
-
}
|
|
2752
|
-
let {
|
|
2753
|
-
columns = []
|
|
2754
|
-
} = this.state;
|
|
2755
|
-
for (let i = 0; i < columns.length; i++) {
|
|
2756
|
-
let column = columns[i];
|
|
2757
|
-
let {
|
|
2758
|
-
filter,
|
|
2759
|
-
dataColumnId
|
|
2760
|
-
} = column;
|
|
2761
|
-
if (!filter) {
|
|
2762
|
-
continue;
|
|
2763
|
-
}
|
|
2764
|
-
if (filter === true) {
|
|
2765
|
-
filter = {};
|
|
2766
|
-
column.filter = {};
|
|
2767
|
-
}
|
|
2768
|
-
let {
|
|
2769
|
-
items = [],
|
|
2770
|
-
booleanType = 'or'
|
|
2771
|
-
} = filter;
|
|
2772
|
-
if (!items.length) {
|
|
2773
|
-
continue;
|
|
2774
|
-
}
|
|
2775
|
-
let value = detail._values[dataColumnId];
|
|
2776
|
-
if (FilterResult(items, booleanType, value) === false) {
|
|
2777
|
-
return false;
|
|
2778
|
-
}
|
|
2779
|
-
}
|
|
2780
|
-
return true;
|
|
2781
|
-
},
|
|
2782
|
-
isRowOpen(id) {
|
|
2783
|
-
if (!this.props.rowChilds) {
|
|
2784
|
-
return true;
|
|
2785
|
-
}
|
|
2786
|
-
let {
|
|
2787
|
-
_parentIds
|
|
2788
|
-
} = this.getRowDetailById(id);
|
|
2789
|
-
for (let i = 0; i < _parentIds.length; i++) {
|
|
2790
|
-
let parentId = _parentIds[i];
|
|
2791
|
-
if (this.getRowDetailById(parentId)._open === false) {
|
|
2792
|
-
return false;
|
|
2793
|
-
}
|
|
2794
|
-
}
|
|
2795
|
-
return true;
|
|
2796
|
-
},
|
|
2797
|
-
///ok
|
|
2798
|
-
getClient(e) {
|
|
2799
|
-
return this.context.touch ? [e.changedTouches[0].clientX, e.changedTouches[0].clientY] : [e.clientX, e.clientY];
|
|
2800
|
-
},
|
|
2801
|
-
///ok
|
|
2802
|
-
resizeDown(e, column, type) {
|
|
2803
|
-
e.stopPropagation();
|
|
2804
|
-
this.downOnResizeHandle = true;
|
|
2805
|
-
let {
|
|
2806
|
-
state
|
|
2807
|
-
} = this.context;
|
|
2808
|
-
let {
|
|
2809
|
-
touch
|
|
2810
|
-
} = state;
|
|
2811
|
-
this.resized = false;
|
|
2812
|
-
(0, _jquery.default)(window).bind(touch ? 'touchmove' : 'mousemove', _jquery.default.proxy(this.resizeMove, this));
|
|
2813
|
-
(0, _jquery.default)(window).bind(touch ? 'touchend' : 'mouseup', _jquery.default.proxy(this.resizeUp, this));
|
|
2814
|
-
this.resizeDetails = {
|
|
2815
|
-
client: this.getClient(e),
|
|
2816
|
-
width: column.width,
|
|
2817
|
-
column,
|
|
2818
|
-
type
|
|
2819
|
-
};
|
|
2820
|
-
},
|
|
2821
|
-
///ok
|
|
2822
|
-
resizeMove(e) {
|
|
2823
|
-
this.resized = true;
|
|
2824
|
-
var {
|
|
2825
|
-
rtl
|
|
2826
|
-
} = this.props;
|
|
2827
|
-
var Client = this.getClient(e);
|
|
2828
|
-
var {
|
|
2829
|
-
client,
|
|
2830
|
-
width,
|
|
2831
|
-
column,
|
|
2832
|
-
type
|
|
2833
|
-
} = this.resizeDetails;
|
|
2834
|
-
var offset = (Client[0] - client[0]) * (type === 'start' ? -1 : 1);
|
|
2835
|
-
let newWidth = width + offset * (rtl ? -1 : 1);
|
|
2836
|
-
if (newWidth < parseInt(column.minWidth || 36)) {
|
|
2837
|
-
newWidth = parseInt(column.minWidth || 36);
|
|
2838
|
-
}
|
|
2839
|
-
this.resizeDetails.newWidth = newWidth;
|
|
2840
|
-
if (newWidth % 10 !== 0) {
|
|
2841
|
-
return;
|
|
2842
|
-
}
|
|
2843
|
-
(0, _jquery.default)(`[data-column-id='${column.dataColumnId}']`).css({
|
|
2844
|
-
width: newWidth
|
|
2845
|
-
});
|
|
2846
|
-
},
|
|
2847
|
-
///ok
|
|
2848
|
-
resizeUp() {
|
|
2849
|
-
this.downOnResizeHandle = false;
|
|
2850
|
-
let {
|
|
2851
|
-
state,
|
|
2852
|
-
setColumns
|
|
2853
|
-
} = this.context;
|
|
2854
|
-
let {
|
|
2855
|
-
touch
|
|
2856
|
-
} = state;
|
|
2857
|
-
(0, _jquery.default)(window).unbind(touch ? 'touchmove' : 'mousemove', this.resizeMove);
|
|
2858
|
-
(0, _jquery.default)(window).unbind(touch ? 'touchend' : 'mouseup', this.resizeUp);
|
|
2859
|
-
if (!this.resized) {
|
|
2860
|
-
return;
|
|
2861
|
-
}
|
|
2862
|
-
let {
|
|
2863
|
-
columns
|
|
2864
|
-
} = state;
|
|
2865
|
-
let {
|
|
2866
|
-
newWidth,
|
|
2867
|
-
column
|
|
2868
|
-
} = this.resizeDetails;
|
|
2869
|
-
column.width = newWidth;
|
|
2870
|
-
state.saveColumnInStorage(column, 'width', newWidth);
|
|
2871
|
-
setColumns(columns);
|
|
2872
|
-
}
|
|
2873
|
-
};
|
|
2874
|
-
function convertFlatModel({
|
|
2875
|
-
model,
|
|
2876
|
-
childsField,
|
|
2877
|
-
getId,
|
|
2878
|
-
getParentId
|
|
2879
|
-
}) {
|
|
2880
|
-
var convertModelRecursive = (array, parentId, parentObject) => {
|
|
2881
|
-
for (let i = 0; i < array.length; i++) {
|
|
2882
|
-
let row = array[i];
|
|
2883
|
-
let rowParentId = getParentId(row);
|
|
2884
|
-
if (rowParentId !== parentId) {
|
|
2885
|
-
continue;
|
|
2886
|
-
}
|
|
2887
|
-
let rowId = getId(row);
|
|
2888
|
-
row[childsField] = [];
|
|
2889
|
-
parentObject.push(row);
|
|
2890
|
-
array.splice(i, 1);
|
|
2891
|
-
i--;
|
|
2892
|
-
convertModelRecursive([...array], rowId, row[childsField]);
|
|
2893
|
-
}
|
|
2894
|
-
};
|
|
2895
|
-
var result = [];
|
|
2896
|
-
convertModelRecursive([...model], undefined, result);
|
|
2897
|
-
return result;
|
|
2898
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
|
+
import { createContext, createRef, Fragment, useContext, useEffect, useRef, useState } from "react";
|
|
12
|
+
import AIOInput from "aio-input";
|
|
13
|
+
import * as UT from 'aio-utils';
|
|
14
|
+
import usePopup from "aio-popup";
|
|
15
|
+
import AIODate from "aio-date";
|
|
16
|
+
import { Filterbar, usePaging, useSort } from "aio-component-utils";
|
|
17
|
+
import "./index.css";
|
|
18
|
+
const Context = createContext({});
|
|
19
|
+
const Provider = (p) => _jsx(Context.Provider, { value: p.value, children: p.children });
|
|
20
|
+
const useProvider = () => useContext(Context);
|
|
21
|
+
const AIOTable = (props) => {
|
|
22
|
+
const popup = usePopup();
|
|
23
|
+
let [dom] = useState(createRef());
|
|
24
|
+
let [searchValue, setSearchValue] = useState('');
|
|
25
|
+
const [columns, setColumns] = useState([]);
|
|
26
|
+
const [searchColumns, setSearchColumns] = useState([]);
|
|
27
|
+
const [excelColumns, setExcelColumns] = useState([]);
|
|
28
|
+
const [filterColumns, setFilterColumns] = useState([]);
|
|
29
|
+
const filterColumnsRef = useRef(filterColumns);
|
|
30
|
+
filterColumnsRef.current = filterColumns;
|
|
31
|
+
const rowsIndexDicRef = useRef({});
|
|
32
|
+
const setRowsIndexDic = (rowsIndexDic) => rowsIndexDicRef.current = rowsIndexDic;
|
|
33
|
+
const getRowsIndexDic = () => rowsIndexDicRef.current;
|
|
34
|
+
const propsRef = useRef(props);
|
|
35
|
+
propsRef.current = props;
|
|
36
|
+
const pagingHook = usePaging({ rows: props.value, paging: props.paging, onChange: props.onChangePaging });
|
|
37
|
+
const tableHook = useTable(() => propsRef.current, () => pagingHook.paging);
|
|
38
|
+
const getIconRef = useRef(new UT.GetSvg());
|
|
39
|
+
const getIcon = getIconRef.current.getIcon;
|
|
40
|
+
const DragColumns = UT.useDrag((dragIndex, dropIndex, reOrder) => setColumns(reOrder(columns, dragIndex, dropIndex)));
|
|
41
|
+
const getGetValue = (sort, column) => {
|
|
42
|
+
if (sort.getValue) {
|
|
43
|
+
return sort.getValue;
|
|
44
|
+
}
|
|
45
|
+
return (row) => {
|
|
46
|
+
const isDate = ['month', 'day', 'hour', 'minute'].indexOf(column.type || 'text') !== -1;
|
|
47
|
+
const cellValue = tableHook.getCellValue({ row, rowIndex: 0, isFirst: false, isLast: false, column, change: () => { }, isDate }, column.value);
|
|
48
|
+
if (isDate) {
|
|
49
|
+
const DATE = new AIODate();
|
|
50
|
+
try {
|
|
51
|
+
return DATE.getTime(cellValue);
|
|
52
|
+
}
|
|
53
|
+
catch (_a) {
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return cellValue;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const getSorts = (columns) => {
|
|
61
|
+
let sorts = [];
|
|
62
|
+
for (let i = 0; i < columns.length; i++) {
|
|
63
|
+
const column = columns[i];
|
|
64
|
+
const { _id } = column;
|
|
65
|
+
const sort = column.sort === true ? { sortId: _id } : column.sort;
|
|
66
|
+
if (!sort) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
let { active = false, dir = 'dec', sortId } = sort;
|
|
70
|
+
let sortItem = { dir, title: sort.title || column.title, sortId, active, getValue: getGetValue(sort, column) };
|
|
71
|
+
sorts.push(sortItem);
|
|
72
|
+
}
|
|
73
|
+
return sorts;
|
|
74
|
+
};
|
|
75
|
+
const sortHook = useSort({
|
|
76
|
+
sorts: [],
|
|
77
|
+
rows: propsRef.current.value,
|
|
78
|
+
onChangeRows: props.onChange,
|
|
79
|
+
onChangeSort: props.onChangeSort,
|
|
80
|
+
});
|
|
81
|
+
const isDate = (column) => ['month', 'day', 'hour', 'minute'].indexOf(column.type || 'text') !== -1;
|
|
82
|
+
function getColumns() {
|
|
83
|
+
let { columns = [] } = props;
|
|
84
|
+
let searchColumns = [], excelColumns = [], filterColumns = [];
|
|
85
|
+
let updatedColumns = columns.map((o) => {
|
|
86
|
+
let { id = 'aitc' + Math.round(Math.random() * 1000000), filterId, search, excel } = o;
|
|
87
|
+
let column = Object.assign(Object.assign({}, o), { _id: id });
|
|
88
|
+
if (search) {
|
|
89
|
+
searchColumns.push(column);
|
|
90
|
+
}
|
|
91
|
+
if (excel) {
|
|
92
|
+
excelColumns.push(column);
|
|
93
|
+
}
|
|
94
|
+
if (filterId) {
|
|
95
|
+
filterColumns.push(column);
|
|
96
|
+
}
|
|
97
|
+
return column;
|
|
98
|
+
});
|
|
99
|
+
setColumns(updatedColumns);
|
|
100
|
+
setSearchColumns(searchColumns);
|
|
101
|
+
setExcelColumns(excelColumns);
|
|
102
|
+
setFilterColumns(filterColumns);
|
|
103
|
+
return updatedColumns;
|
|
104
|
+
}
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
const columns = getColumns();
|
|
107
|
+
sortHook.setSorts(getSorts(columns));
|
|
108
|
+
}, []);
|
|
109
|
+
function getTimeText(column, value) {
|
|
110
|
+
if (!value || value === null) {
|
|
111
|
+
return '';
|
|
112
|
+
}
|
|
113
|
+
const t = column.type;
|
|
114
|
+
const DATE = new AIODate();
|
|
115
|
+
let pattern = '{year}/{month}';
|
|
116
|
+
if (t !== 'month') {
|
|
117
|
+
pattern += '/{day}';
|
|
118
|
+
if (t !== 'day') {
|
|
119
|
+
pattern += ' {hour}';
|
|
120
|
+
if (t === 'minute') {
|
|
121
|
+
pattern += ' : {minute}';
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
pattern += ' : 00';
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return DATE.getDateByPattern(value, pattern);
|
|
129
|
+
}
|
|
130
|
+
function add() {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
if (!props.onAdd) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const res = yield props.onAdd();
|
|
136
|
+
if (res && props.onChange) {
|
|
137
|
+
props.onChange([res, ...props.value]);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function remove(row, index) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
if (!props.onRemove) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const res = yield props.onRemove({ row, rowIndex: index });
|
|
147
|
+
if (res === true && props.onChange) {
|
|
148
|
+
props.onChange(props.value.filter((o) => o._id !== row._id));
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function exportToExcel() {
|
|
153
|
+
let list = [];
|
|
154
|
+
if (typeof props.excel === 'function') {
|
|
155
|
+
list = props.excel(props.value);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
for (let rowIndex = 0; rowIndex < props.value.length; rowIndex++) {
|
|
159
|
+
const isFirst = rowIndex === 0;
|
|
160
|
+
const isLast = rowIndex === props.value.length - 1;
|
|
161
|
+
let row = props.value[rowIndex], json = {};
|
|
162
|
+
for (let j = 0; j < excelColumns.length; j++) {
|
|
163
|
+
const column = excelColumns[j], { excel } = column;
|
|
164
|
+
let key = '';
|
|
165
|
+
if (excel === true) {
|
|
166
|
+
if (typeof column.title === 'string') {
|
|
167
|
+
key = column.title;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
key = 'untitle';
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else if (typeof excel === 'string') {
|
|
174
|
+
key = excel;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
const cellDetail = { row, rowIndex, isFirst, isLast, column, change: () => { }, isDate: isDate(column) };
|
|
180
|
+
json[key] = tableHook.getCellValue(cellDetail, column.value, '');
|
|
181
|
+
}
|
|
182
|
+
list.push(json);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
UT.ExportToExcel(list, { promptText: typeof props.excel === 'string' ? props.excel : 'Inter Excel File Name' });
|
|
186
|
+
}
|
|
187
|
+
function getSearchedRows(rows) {
|
|
188
|
+
if (props.onSearch !== true) {
|
|
189
|
+
return rows;
|
|
190
|
+
}
|
|
191
|
+
if (!searchColumns.length || !searchValue) {
|
|
192
|
+
return rows;
|
|
193
|
+
}
|
|
194
|
+
const rowsIndexDic = getRowsIndexDic();
|
|
195
|
+
return UT.Search(rows, searchValue, (row) => {
|
|
196
|
+
const { isFirst, isLast, rowIndex } = rowsIndexDic[(row)._id];
|
|
197
|
+
let str = '';
|
|
198
|
+
for (let i = 0; i < searchColumns.length; i++) {
|
|
199
|
+
let column = searchColumns[i];
|
|
200
|
+
const cellDetail = { row, rowIndex, isFirst, isLast, column, change: () => { }, isDate: isDate(column) };
|
|
201
|
+
let cellValue = tableHook.getCellValue(cellDetail, column.value, '');
|
|
202
|
+
if (cellValue) {
|
|
203
|
+
str += cellValue + ' ';
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return str;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function getRows() {
|
|
210
|
+
const rows = props.value;
|
|
211
|
+
const rowsIndexDic = {};
|
|
212
|
+
for (let i = 0; i < props.value.length; i++) {
|
|
213
|
+
rowsIndexDic[props.value[i]._id] = { rowIndex: i, isFirst: i === 0, isLast: i === rows.length - 1 };
|
|
214
|
+
}
|
|
215
|
+
setRowsIndexDic(rowsIndexDic);
|
|
216
|
+
let searchedRows = getSearchedRows(rows);
|
|
217
|
+
let sortedRows = sortHook.getSortedRows(searchedRows);
|
|
218
|
+
let pagedRows = pagingHook.getPagedRows(sortedRows);
|
|
219
|
+
return { rows: props.value, searchedRows, sortedRows, pagedRows };
|
|
220
|
+
}
|
|
221
|
+
function search(searchValue) {
|
|
222
|
+
if (props.onSearch === true) {
|
|
223
|
+
setSearchValue(searchValue);
|
|
224
|
+
}
|
|
225
|
+
else if (typeof props.onSearch === 'function') {
|
|
226
|
+
props.onSearch(searchValue);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const changeCell = (cellDetail, cellNewValue) => {
|
|
230
|
+
if (!props.onChange) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const { column } = cellDetail;
|
|
234
|
+
if (typeof column.value !== 'string' || column.value.indexOf('row.') !== 0) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
let row = JSON.parse(JSON.stringify(cellDetail.row));
|
|
238
|
+
const rowId = row._id;
|
|
239
|
+
eval(`${column.value} = cellNewValue`);
|
|
240
|
+
props.onChange(props.value.map((o) => o._id !== rowId ? o : row));
|
|
241
|
+
};
|
|
242
|
+
let ROWS = getRows();
|
|
243
|
+
const { gap = [0, 1] } = props;
|
|
244
|
+
let attrs = UT.AddToAttrs(props.attrs, { className: ['aio-table', props.className], style: Object.assign({ gap: gap[1] }, props.style), attrs: { ref: dom } });
|
|
245
|
+
const context = {
|
|
246
|
+
rootProps: props, getTimeText, isDate, columns, excelColumns, filterColumns, changeCell, tableHook, sortHook, ROWS,
|
|
247
|
+
getRowsIndexDic, add, remove, search, exportToExcel, DragColumns, getIcon, popup,
|
|
248
|
+
};
|
|
249
|
+
return (_jsxs(Provider, { value: context, children: [_jsxs("div", Object.assign({}, attrs, { children: [_jsx(TableToolbar, {}), !!props.filter &&
|
|
250
|
+
_jsx(Filterbar, { columns: filterColumns, filter: props.filter, columnOption: { text: (column) => column.title, id: (column) => column.filterId, type: (column) => column.type || 'text' } }), _jsxs("div", { className: 'aio-table-unit aio-table-scroll', style: { gap: gap[1] }, children: [_jsx(TableHeader, {}), _jsx(TableRows, {})] }), pagingHook.render()] })), popup.render()] }));
|
|
251
|
+
};
|
|
252
|
+
export default AIOTable;
|
|
253
|
+
const TableRows = () => {
|
|
254
|
+
let { ROWS, rootProps } = useProvider();
|
|
255
|
+
let { rowOption = {}, rowsTemplate, placeholder = 'there is not any items' } = rootProps;
|
|
256
|
+
const { before: rowBefore = () => null, after: rowAfter = () => null, template: rowTemplate, } = rowOption;
|
|
257
|
+
let rows = ROWS.pagedRows || [];
|
|
258
|
+
let content;
|
|
259
|
+
if (rowsTemplate) {
|
|
260
|
+
content = rowsTemplate(rows);
|
|
261
|
+
}
|
|
262
|
+
else if (rows.length) {
|
|
263
|
+
content = rows.map((o, i) => {
|
|
264
|
+
let { id = 'ailr' + Math.round(Math.random() * 10000000) } = o;
|
|
265
|
+
o._id = o._id === undefined ? id : o._id;
|
|
266
|
+
const rowDetail = {
|
|
267
|
+
row: o, rowIndex: i,
|
|
268
|
+
isFirst: i === 0,
|
|
269
|
+
isLast: i === rows.length - 1
|
|
270
|
+
};
|
|
271
|
+
let Row;
|
|
272
|
+
if (rowTemplate) {
|
|
273
|
+
Row = rowTemplate(rowDetail);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
Row = _jsx(TableRow, { rowDetail: rowDetail }, o._id);
|
|
277
|
+
}
|
|
278
|
+
return (_jsxs(Fragment, { children: [rowBefore(rowDetail), Row, rowAfter(rowDetail)] }, o._id));
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
else if (placeholder) {
|
|
282
|
+
content = _jsx("div", { style: { width: '100%', textAlign: 'center', padding: 12, boxSizing: 'border-box' }, children: placeholder });
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
const { gap = [0, 1] } = rootProps;
|
|
288
|
+
return _jsx("div", { className: 'aio-table-rows', style: { gap: gap[1] }, children: content });
|
|
289
|
+
};
|
|
290
|
+
const TableToolbar = () => {
|
|
291
|
+
let { add, exportToExcel, search, rootProps, excelColumns, getIcon, sortHook } = useProvider();
|
|
292
|
+
let { toolbarAttrs, toolbar, onAdd, onSearch, value } = rootProps;
|
|
293
|
+
toolbarAttrs = UT.AddToAttrs(toolbarAttrs, { className: 'aio-table-toolbar' });
|
|
294
|
+
if (!onAdd && !toolbar && !onSearch && !sortHook.sorts.length && !excelColumns.length) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
function getAddText() {
|
|
298
|
+
let { addText } = rootProps;
|
|
299
|
+
if (!rootProps.addText) {
|
|
300
|
+
return getIcon('mdiPlusThick', 0.8);
|
|
301
|
+
}
|
|
302
|
+
return typeof addText === 'function' ? addText(value) : addText;
|
|
303
|
+
}
|
|
304
|
+
return (_jsxs("div", Object.assign({}, toolbarAttrs, { children: [toolbar && _jsx("div", { className: 'aio-table-toolbar-content', children: typeof toolbar === 'function' ? toolbar() : toolbar }), _jsx("div", { className: 'aio-table-search', children: !!onSearch && _jsx(AIOInput, { type: 'text', onChange: (value) => search(value), after: getIcon('mdiMagnify', 0.7) }) }), sortHook.renderSortButton(), !!excelColumns.length && _jsx("div", { className: 'aio-table-toolbar-button', onClick: () => exportToExcel(), children: getIcon('mdiFileExcel', 0.8) }), !!onAdd && _jsx("div", { className: 'aio-table-toolbar-button', onClick: () => add(), children: getAddText() })] })));
|
|
305
|
+
};
|
|
306
|
+
const TableHeader = () => {
|
|
307
|
+
let { rootProps, columns } = useProvider();
|
|
308
|
+
let { headerAttrs, onRemove, gap = [0, 1] } = rootProps;
|
|
309
|
+
headerAttrs = UT.AddToAttrs(headerAttrs, { className: 'aio-table-header', style: { gap: gap[0] } });
|
|
310
|
+
let Titles = columns.map((o, i) => _jsx(TableTitle, { column: o, isLast: i === columns.length - 1, colIndex: i }, o._id));
|
|
311
|
+
let RemoveTitle = !onRemove ? null : _jsx("div", { className: 'aio-table-remove-title' });
|
|
312
|
+
return _jsxs("div", Object.assign({}, headerAttrs, { children: [Titles, RemoveTitle] }));
|
|
313
|
+
};
|
|
314
|
+
const TableTitle = (p) => {
|
|
315
|
+
const { column, isLast, colIndex } = p;
|
|
316
|
+
let { tableHook, DragColumns } = useProvider();
|
|
317
|
+
const attrs = Object.assign(Object.assign(Object.assign({}, tableHook.getTitleAttrs(column)), DragColumns.getDragAttrs(colIndex)), DragColumns.getDropAttrs(colIndex));
|
|
318
|
+
return _jsx("div", Object.assign({}, attrs, { children: attrs.title }));
|
|
319
|
+
};
|
|
320
|
+
const TableRow = (props) => {
|
|
321
|
+
const { rowDetail } = props;
|
|
322
|
+
const { row, rowIndex } = rowDetail;
|
|
323
|
+
const rowId = row._id;
|
|
324
|
+
let { remove, rootProps, columns, tableHook, getIcon, isDate } = useProvider();
|
|
325
|
+
function getCells() {
|
|
326
|
+
return columns.map((column, i) => {
|
|
327
|
+
const key = rowId + ' ' + column._id;
|
|
328
|
+
const cellDetail = Object.assign(Object.assign({}, rowDetail), { column, change: (cellNewValue) => {
|
|
329
|
+
if (!rootProps.onChange) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (typeof column.value !== 'string' || column.value.indexOf('row.') !== 0) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
let row = JSON.parse(JSON.stringify(cellDetail.row));
|
|
336
|
+
eval(`${column.value} = cellNewValue`);
|
|
337
|
+
rootProps.onChange(rootProps.value.map((o) => o._id !== rowId ? o : row));
|
|
338
|
+
}, isDate: isDate(column) });
|
|
339
|
+
const cellValue = tableHook.getCellValue(cellDetail, column.value);
|
|
340
|
+
return (_jsx(TableCell, { cellDetail: cellDetail, cellValue: cellValue }, key));
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
let { onRemove } = rootProps;
|
|
344
|
+
return (_jsx(_Fragment, { children: _jsxs("div", Object.assign({}, tableHook.getRowAttrs(props.rowDetail), { children: [getCells(), onRemove ? _jsx("button", { className: 'aio-table-remove', onClick: () => remove(row, rowIndex), children: getIcon('mdiClose', 0.8) }) : null] }), rowId) }));
|
|
345
|
+
};
|
|
346
|
+
const TableCell = (props) => {
|
|
347
|
+
const { cellDetail, cellValue } = props;
|
|
348
|
+
const { row, column, isLast } = cellDetail;
|
|
349
|
+
const { tableHook, getTimeText } = useProvider();
|
|
350
|
+
const { template, before, after, subtext } = column;
|
|
351
|
+
const rowId = row._id;
|
|
352
|
+
const colId = column._id;
|
|
353
|
+
const isTime = ['month', 'day', 'hour', 'minute'].indexOf(column.type || 'text') !== -1;
|
|
354
|
+
const templateValue = isTime ? getTimeText(cellValue) : tableHook.getCellValue(cellDetail, template);
|
|
355
|
+
const beforeValue = tableHook.getCellValue(cellDetail, before, undefined);
|
|
356
|
+
const afterValue = tableHook.getCellValue(cellDetail, after, undefined);
|
|
357
|
+
const subtextValue = tableHook.getCellValue(cellDetail, subtext, undefined);
|
|
358
|
+
return (_jsx(Fragment, { children: _jsxs("div", Object.assign({}, tableHook.getCellAttrs(props.cellDetail, props.cellValue), { children: [beforeValue !== undefined && _jsx("div", { className: "aio-table-cell-before", children: beforeValue }), _jsxs("div", { className: `aio-table-cell-value${subtext !== undefined ? ' has-subtext' : ''}`, "data-subtext": subtextValue, children: [templateValue !== undefined && templateValue, templateValue === undefined && cellValue] }), afterValue !== undefined && _jsx("div", { className: "aio-table-cell-after", children: afterValue })] })) }, rowId + ' ' + colId));
|
|
359
|
+
};
|
|
360
|
+
const useTable = (getProps, getPaging) => {
|
|
361
|
+
const DragRows = UT.useDrag((dragData, dropData, reOrder) => {
|
|
362
|
+
const { onSwap, onChange } = getProps();
|
|
363
|
+
const { dragIndex } = dragData;
|
|
364
|
+
const { dropIndex, rows } = dropData;
|
|
365
|
+
const newRows = reOrder(rows, dragIndex, dropIndex);
|
|
366
|
+
const from = rows[dragIndex];
|
|
367
|
+
const to = rows[dropIndex];
|
|
368
|
+
if (typeof onSwap === 'function') {
|
|
369
|
+
onSwap(newRows, from, to);
|
|
370
|
+
}
|
|
371
|
+
else if (onChange) {
|
|
372
|
+
onChange(newRows);
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
const getCellValue = (cellDetail, cellValue, def) => {
|
|
376
|
+
const { getValue = {} } = getProps();
|
|
377
|
+
const paging = getPaging();
|
|
378
|
+
if (paging) {
|
|
379
|
+
let { number, size } = paging;
|
|
380
|
+
cellDetail = Object.assign(Object.assign({}, cellDetail), { rowIndex: cellDetail.rowIndex + ((number - 1) * size) });
|
|
381
|
+
}
|
|
382
|
+
let type = typeof cellValue;
|
|
383
|
+
if (type === 'string') {
|
|
384
|
+
const { row } = cellDetail;
|
|
385
|
+
let result = cellValue;
|
|
386
|
+
if (getValue[cellValue]) {
|
|
387
|
+
result = getValue[cellValue](cellDetail);
|
|
388
|
+
}
|
|
389
|
+
else if (cellValue.indexOf('row.') !== -1) {
|
|
390
|
+
try {
|
|
391
|
+
eval(`result = ${cellValue}`);
|
|
392
|
+
}
|
|
393
|
+
catch (_a) {
|
|
394
|
+
result = '';
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return result === undefined ? def : result;
|
|
398
|
+
}
|
|
399
|
+
if (type === 'undefined') {
|
|
400
|
+
return def;
|
|
401
|
+
}
|
|
402
|
+
if (type === 'function') {
|
|
403
|
+
return cellValue(cellDetail);
|
|
404
|
+
}
|
|
405
|
+
return cellValue === undefined ? def : cellValue;
|
|
406
|
+
};
|
|
407
|
+
const getColValue = (column, field, def) => {
|
|
408
|
+
const colValue = column[field];
|
|
409
|
+
let type = typeof colValue;
|
|
410
|
+
let result;
|
|
411
|
+
if (type === 'function') {
|
|
412
|
+
result = colValue(column);
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
result = colValue;
|
|
416
|
+
}
|
|
417
|
+
return result === undefined ? def : result;
|
|
418
|
+
};
|
|
419
|
+
const getCellAttrs = (cellDetail, cellValue) => {
|
|
420
|
+
const { column } = cellDetail;
|
|
421
|
+
const attrs = getCellValue(cellDetail, column.attrs, {});
|
|
422
|
+
const justify = getColValue(column, 'justify', false);
|
|
423
|
+
const width = getColValue(column, 'width');
|
|
424
|
+
const minWidth = getColValue(column, 'minWidth');
|
|
425
|
+
const className = `aio-table-cell` + (justify ? ` aio-table-cell-justify` : '');
|
|
426
|
+
const style = { width, minWidth, flex: width ? undefined : 1 };
|
|
427
|
+
return UT.AddToAttrs(attrs, { className, style, attrs: { title: typeof cellValue === 'string' ? cellValue : undefined } });
|
|
428
|
+
};
|
|
429
|
+
const getTitleAttrs = (column) => {
|
|
430
|
+
const attrs = getColValue(column, 'titleAttrs', {});
|
|
431
|
+
const justify = getColValue(column, 'justify', false);
|
|
432
|
+
const width = getColValue(column, 'width');
|
|
433
|
+
const minWidth = getColValue(column, 'minWidth');
|
|
434
|
+
const className = `aio-table-title` + (justify ? ` aio-table-title-justify` : '');
|
|
435
|
+
const style = { width, minWidth, flex: width ? undefined : 1 };
|
|
436
|
+
return UT.AddToAttrs(attrs, { className, style, attrs: { title: typeof column.title === 'string' ? column.title : undefined } });
|
|
437
|
+
};
|
|
438
|
+
const getRowAttrs = (rowDetail) => {
|
|
439
|
+
const { rowOption = {}, onSwap, value, gap = [0, 1] } = getProps();
|
|
440
|
+
const { attrs: rowAttrs } = rowOption;
|
|
441
|
+
const attrs = rowAttrs ? rowAttrs(rowDetail) : {};
|
|
442
|
+
let obj = UT.AddToAttrs(attrs, { className: 'aio-table-row', style: { gap: gap[0] } });
|
|
443
|
+
if (onSwap) {
|
|
444
|
+
obj = Object.assign(Object.assign(Object.assign({}, obj), DragRows.getDragAttrs({ dragIndex: rowDetail.rowIndex })), DragRows.getDropAttrs({ dropIndex: rowDetail.rowIndex, rows: value }));
|
|
445
|
+
}
|
|
446
|
+
return obj;
|
|
447
|
+
};
|
|
448
|
+
return { getCellValue, getColValue, getCellAttrs, getTitleAttrs, getRowAttrs };
|
|
449
|
+
};
|