react-graph-grid 0.0.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/src/GridDB.jsx ADDED
@@ -0,0 +1,880 @@
1
+ /* eslint-disable no-mixed-operators */
2
+ import { useState, useEffect } from 'react';
3
+ import { Images } from './Themes/Images';
4
+ import { GridPKClass } from './GridPK';
5
+ import { Dropdown } from './Dropdown';
6
+ import { WaveType } from './Graph';
7
+ import { NodeStatus } from './Base';
8
+ import { BaseComponent } from './Base';
9
+ // ==================================================================================================================================================================
10
+ export function GridDB(props) {
11
+ let grid = null;
12
+
13
+ const [gridState, setState] = useState({ grid: grid, ind: 0 });
14
+
15
+ grid = gridState.grid;
16
+ let needGetRows = false;
17
+ if (!grid || grid.uid !== props.uid && props.uid != null) {
18
+ grid = null;
19
+ if (props.findGrid) {
20
+ grid = props.findGrid(props);
21
+ }
22
+ grid = grid || new GridDBClass(props);
23
+ needGetRows = !props.noAutoRefresh && !props.parentGrids;
24
+ }
25
+
26
+ if (props.init) {
27
+ props.init(grid);
28
+ }
29
+
30
+ grid.refreshState = function () {
31
+ setState({ grid: grid, ind: grid.stateind++ });
32
+ }
33
+
34
+ grid._waitingRows = needGetRows && (grid.rows.length <= 0 || grid.columns.length <= 0);
35
+
36
+ useEffect(() => {
37
+ grid.setupEvents(grid);
38
+
39
+ if (grid._waitingRows) {
40
+
41
+ grid.getRows({ filters: grid.collectFilters(), grid: grid }).then(
42
+ rows => {
43
+ grid.rows = rows;
44
+ grid.afterGetRows();
45
+ grid.refreshState();
46
+ }
47
+ ).finally(() => {
48
+ grid._waitingRows = false;
49
+ grid.refreshState();
50
+ });
51
+ }
52
+ else if (grid.columns.length <= 0 && grid.getColumns) {
53
+ grid.prepareColumns().then(() => grid.refreshState());
54
+ }
55
+
56
+ return () => {
57
+ grid.clearEvents();
58
+ }
59
+ }, [grid])
60
+
61
+ return (grid.render());
62
+ }
63
+ // ==================================================================================================================================================================
64
+ export class GridDBClass extends GridPKClass {
65
+
66
+ constructor(props) {
67
+ super(props);
68
+
69
+ const grid = this;
70
+ grid.pageNumber = 1;
71
+ grid.pageSize = props.pageSize === 0 ? 0 : props.pageSize || 10;
72
+
73
+ grid.pageSizes = [5, 10, 15, 20, 30, 40, 50, 100];
74
+
75
+ grid.buttons = props.buttons || [];
76
+
77
+ grid.sortDisabled = props.sortDisabled;
78
+
79
+ grid.opt.toolbarClass = props.toolbarClass;
80
+ grid.opt.toolbarButtonsClass = props.toolbarButtonsClass;
81
+ grid.opt.pagerClass = props.pagerClass;
82
+ grid.opt.pagerButtonsClass = props.pagerButtonsClass;
83
+ grid.opt.inputClass = props.inputClass;
84
+
85
+ grid.sortColumns = [];
86
+ grid._sortSeq = 1;
87
+
88
+ grid.multi = props.multi;
89
+ }
90
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
91
+ static gridSettings = {};
92
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
93
+ //visitByWaveOld(e) {
94
+ // const grid = this;
95
+ // if (grid.skipOnWaveVisit(e)) return;
96
+
97
+ // if (e.waveType === WaveType.value) {
98
+ // if (grid.status === NodeStatus.filter) {
99
+ // if (!grid._selecting) {
100
+ // grid.selectedRowIndex = -1;
101
+ // }
102
+ // grid.value = grid.text = '';
103
+ // grid._selectedOptions = [];
104
+ // return;
105
+ // }
106
+ // }
107
+
108
+ // grid.pageNumber = 1;
109
+
110
+ // super.visitByWaveOld(e);
111
+ //}
112
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
113
+ visitByWave(e) {
114
+ const grid = this;
115
+
116
+ const rpr = new Promise(function (resolve) {
117
+ resolve(e);
118
+ })
119
+
120
+ if (grid.skipOnWaveVisit(e)) return rpr;
121
+
122
+ if (e.waveType === WaveType.value) {
123
+ if (grid.status === NodeStatus.filter) {
124
+ if (!grid._selecting) {
125
+ grid.selectedRowIndex = -1;
126
+ }
127
+ grid.value = grid.text = '';
128
+ grid._selectedOptions = [];
129
+ return rpr;
130
+ }
131
+ }
132
+
133
+ grid.pageNumber = 1;
134
+
135
+ return super.visitByWave(e);
136
+ }
137
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
138
+ keyAdd() {
139
+ const grid = this;
140
+ return `${super.keyAdd()}_${grid.pageSize}_${grid.pageNumber}_`;
141
+ }
142
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
143
+ render() {
144
+ const grid = this;
145
+ grid.setupPagerButtons();
146
+
147
+ return (
148
+ <>
149
+ {grid.renderToolbar()}
150
+ {/*grid.renderAppliedFilters()*/}
151
+ {grid.renderPager()}
152
+ {super.render()}
153
+ {grid.renderPager(true)}
154
+ <Dropdown init={(dd) => { grid.menuDropdown = dd; }} getItems={(e) => { return grid.getGridSettings(e); }} onItemClick={(e) => { grid.onSettingsItemClick(e.itemId); }}></Dropdown>
155
+ </>
156
+ )
157
+ }
158
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
159
+ isDisabled() {
160
+ const grid = this;
161
+ return grid._isDisabled === true;
162
+ }
163
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
164
+ setDisabled(value) {
165
+ const grid = this;
166
+ grid._isDisabled = value;
167
+ }
168
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
169
+ isEditing() {
170
+ const grid = this;
171
+ return grid._isEditing === true;
172
+ }
173
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
174
+ setEditing(value) {
175
+ const grid = this;
176
+ grid._isEditing = value;
177
+ }
178
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
179
+ renderToolbar() {
180
+ const grid = this;
181
+ grid.buttons = grid.buttons || [];
182
+ return (
183
+ false ?
184
+ <div
185
+
186
+ key={`gridToolbarDiv_${grid.id}_`}
187
+ className={grid.opt.toolbarClass || BaseComponent.theme.toolbarClass || 'toolbar-default'}
188
+ >
189
+ {
190
+ grid.buttons.map((button, ind) => {
191
+ return (
192
+ button.getVisible && !button.getVisible() ? <span key={`toolbarEmpty_${grid.id}_${button.id}_${ind}_`}></span> :
193
+ <button
194
+ key={`toolbarButton_${grid.id}_${button.id}_${ind}_`}
195
+ ></button>
196
+ )
197
+ })
198
+ }
199
+ </div>
200
+
201
+ :
202
+
203
+ grid.buttons.length <= 0 ? <></> :
204
+ <div
205
+
206
+ key={`gridToolbarDiv_${grid.id}_`}
207
+ className={grid.opt.toolbarClass || 'toolbar-default'}
208
+ >
209
+ {
210
+ grid.buttons.map((button, ind) => {
211
+ return (
212
+ button.render ?
213
+ button.render()
214
+ :
215
+ <button
216
+ key={`toolbarButton_${grid.id}_${button.id}_${ind}_`}
217
+ className={`${button.class || grid.opt.toolbarButtonsClass || BaseComponent.theme.toolbarButtonsClass || 'grid-toolbar-button'}`}
218
+ style={{
219
+ width: button.w ? button.w : button.img ? '' : 'auto',
220
+ display: button.getVisible && !button.getVisible() ? 'none' : '',
221
+ padding: button.padding ? button.padding : '',
222
+ margin: '5px 2px',
223
+ }}
224
+ title={grid.translate(button.title, 'grid-toolbar-button')}
225
+ disabled={button.getDisabled && button.getDisabled({ grid: grid }) || button.disabled ? 'disabled' : ''}
226
+ onClick={button.click ? (e) => {
227
+ e.grid = grid;
228
+ button.click(e);
229
+ } : grid.onButtonClick ? (e) => { grid.onButtonClick(e) } : null}
230
+ >
231
+ {button.img ? button.img() : ''}
232
+ {GridDBClass.gridSettings.buttonSize > 0 || !button.img ? grid.translate(button.label, 'grid-toolbar-button') || grid.translate(button.title, 'grid-toolbar-button') : ''}
233
+ </button>
234
+ );
235
+ })
236
+ }
237
+ </div>
238
+ );
239
+ }
240
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
241
+ renderAppliedFilters() {
242
+ return <></>;
243
+ }
244
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
245
+ renderPager(bottom) {
246
+ const grid = this;
247
+
248
+ return (
249
+ grid.pagerButtons.length <= 0 || bottom && !grid.allowBottomPager ? <></> :
250
+ <div
251
+ key={`pagerDiv_${bottom ? 'bottom' : 'top'}_${grid.id}_`}
252
+ className={grid.opt.pagerClass || BaseComponent.theme.pagerClass || 'grid-pager-default'}
253
+ style={{ display: 'flex', alignItems: 'center' }}
254
+ >
255
+ {
256
+ grid.pagerButtons.map((button, ind) => {
257
+ return (
258
+ button.render ? button.render(button, bottom) :
259
+ <button
260
+ key={`pager_${bottom ? 'bottom' : 'top'}_${grid.id}_${button.id}_${ind}_`}
261
+ grid-pager-item={`${grid.id}_${button.id}_`}
262
+ className={`${button.class || BaseComponent.theme.pagerButtonsClass || 'grid-pager-button'}`}
263
+ title={grid.translate(button.title, 'grid-pager-button')}
264
+ disabled={grid.isEditing() || grid.isDisabled() || button.getDisabled && button.getDisabled({ grid: grid }) || button.disabled ? 'disabled' : ''}
265
+ onClick={button.click ? button.click : null}
266
+ style={{ margin: '5px 2px', minHeight: '2em', display: 'flex' }}
267
+ >
268
+ {button.img ? button.img() : ''}
269
+ {button.label ? grid.translate(button.label, 'grid-pager-button') : ''}
270
+ </button>
271
+ );
272
+ })
273
+ }
274
+ </div>
275
+ );
276
+ }
277
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
278
+ gotoFirstPage() {
279
+ const grid = this;
280
+ grid.pageNumber = 1;
281
+ grid.selectedRowIndex = 0;
282
+ grid.refresh();
283
+ }
284
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
285
+ gotoPrevPage() {
286
+ const grid = this;
287
+ grid.pageNumber = grid.pageNumber > 1 ? grid.pageNumber - 1 : 1;
288
+ grid.selectedRowIndex = 0;
289
+ grid.refresh();
290
+ }
291
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
292
+ gotoNextPage() {
293
+ const grid = this;
294
+ grid.calculatePagesCount();
295
+ grid.pageNumber = grid.pageNumber < grid.pagesCount ? grid.pageNumber + 1 : grid.pageNumber;
296
+ grid.selectedRowIndex = 0;
297
+ grid.refresh();
298
+ }
299
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
300
+ gotoLastPage() {
301
+ const grid = this;
302
+ grid.calculatePagesCount();
303
+ grid.pageNumber = grid.pageNumber < grid.pagesCount ? grid.pagesCount : grid.pageNumber;
304
+ grid.selectedRowIndex = 0;
305
+ grid.refresh();
306
+ }
307
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
308
+ setupPagerButtons() {
309
+ const grid = this;
310
+ if (grid.pagerButtons && grid.pagerButtons.length > 0) return;
311
+
312
+ grid.pagerButtons = [];
313
+ grid.pagerButtonsDict = {};
314
+
315
+ const refresh = {
316
+ id: 0,
317
+ name: 'refresh',
318
+ title: 'Refresh',
319
+ label: Images.images.refresh ? '' : 'Refresh',
320
+ click: function (e) {
321
+ grid.refresh();
322
+ },
323
+ img: Images.images.refresh,
324
+ class: grid.pagerButtonsClass,
325
+ getDisabled: function () {
326
+ return grid._waitingRows;
327
+ },
328
+ }
329
+
330
+ grid.pagerButtons.push(refresh);
331
+ grid.pagerButtonsDict[refresh.id] = grid.pagerButtonsDict[refresh.name] = refresh;
332
+
333
+ if (grid.showGridSettings) {
334
+ const settings = {
335
+ id: 1,
336
+ name: 'settings',
337
+ title: 'Settings',
338
+ label: Images.images.settings ? '' : 'Settings',
339
+ click: function (e) {
340
+ grid.showGridSettings(e);
341
+ },
342
+ img: Images.images.settings,
343
+ class: grid.pagerButtonsClass,
344
+ getDisabled: function () {
345
+ return grid._waitingRows;
346
+ },
347
+ }
348
+
349
+ grid.pagerButtons.push(settings);
350
+ grid.pagerButtonsDict[settings.id] = grid.pagerButtonsDict[settings.name] = settings;
351
+ }
352
+
353
+ if (grid.multi) {
354
+ const pocket = {
355
+ id: 2,
356
+ name: 'pocket',
357
+ title: 'Pocket',
358
+ label: Images.images.pocket ? '' : 'Pocket',
359
+ click: function (e) {
360
+ grid.switchGridPocket(e);
361
+ },
362
+ img: grid.pocketOpened ? Images.images.pocketOpened : Images.images.pocket,
363
+ class: grid.pagerButtonsClass,
364
+ getDisabled: function () {
365
+ return grid._waitingRows;
366
+ },
367
+ }
368
+
369
+ grid.pagerButtons.push(pocket);
370
+ grid.pagerButtonsDict[pocket.id] = grid.pagerButtonsDict[pocket.name] = pocket;
371
+ }
372
+
373
+ if (grid.pageSize > 0) {
374
+
375
+ const first = {
376
+ id: 3,
377
+ name: 'first',
378
+ title: 'First',
379
+ label: Images.images.first ? '' : 'First',
380
+ click: function (e) {
381
+ grid.gotoFirstPage();
382
+ },
383
+ getDisabled: function () {
384
+ return grid._waitingRows || !grid.rows || grid.rows.length <= 0 || grid.pageNumber === 1;
385
+ },
386
+ img: Images.images.first,
387
+ class: grid.pagerButtonsClass,
388
+ }
389
+
390
+ grid.pagerButtons.push(first);
391
+ grid.pagerButtonsDict[first.id] = grid.pagerButtonsDict[first.name] = first;
392
+
393
+ const prev = {
394
+ id: 4,
395
+ name: 'prev',
396
+ title: 'Prev',
397
+ label: Images.images.prev ? '' : 'Prev',
398
+ click: function (e) {
399
+ grid.gotoPrevPage();
400
+ },
401
+ getDisabled: function () {
402
+ return grid._waitingRows || !grid.rows || grid.rows.length <= 0 || grid.pageNumber === 1;
403
+ },
404
+ img: Images.images.prev,
405
+ class: grid.pagerButtonsClass,
406
+ }
407
+
408
+ grid.pagerButtons.push(prev);
409
+ grid.pagerButtonsDict[prev.id] = grid.pagerButtonsDict[prev.name] = prev;
410
+
411
+ const curr = {
412
+ id: 5,
413
+ name: 'curr',
414
+ title: 'Current Page',
415
+ label: 'Current Page',
416
+ click: function (e) {
417
+ },
418
+ getDisabled: function () {
419
+ return grid._waitingRows || !grid.rows || grid.rows.length <= 1;
420
+ },
421
+ render: function (button, bottom) {
422
+ return (
423
+ <input
424
+ key={`pager_${bottom ? 'bottom' : 'top'}_${grid.id}_${button.id}_`}
425
+ title={grid.translate(button.title, 'grid-pager-button')}
426
+ value={grid.pageNumber}
427
+ grid-pager-item={`${grid.id}_${button.id}_`}
428
+ className={`${button.class ? button.class : grid.opt.inputClass || BaseComponent.theme.inputClass || 'grid-pager-current'}`}
429
+ style={{ width: '3em', height: '2em', display: 'inline-block', margin: '0 2px' }}
430
+ disabled={grid._waitingRows || grid.isEditing() || grid.isDisabled() ? 'disabled' : ''}
431
+ onChange={function (e) {
432
+ const newPage = +e.target.value;
433
+
434
+ if (grid.pageNumber !== newPage && newPage >= 1 && newPage <= grid.pagesCount) {
435
+ grid.pageNumber = newPage;
436
+ grid.selectedRowIndex = 0;
437
+ grid.refresh();
438
+ }
439
+ }}
440
+ >
441
+ </input>
442
+ )
443
+ },
444
+ }
445
+
446
+ grid.pagerButtons.push(curr);
447
+ grid.pagerButtonsDict[curr.id] = grid.pagerButtonsDict[curr.name] = curr;
448
+
449
+ const pages = {
450
+ id: 6,
451
+ name: 'pages',
452
+ title: 'Total Pages',
453
+ label: 'Total Pages',
454
+ render: function (button, bottom) {
455
+ return (
456
+ <span
457
+ key={`pager_${bottom ? 'bottom' : 'top'}_${grid.id}_${button.id}_`}
458
+ className={'grid-pager-of'}
459
+ title={grid.translate(button.title, 'grid-pager-button')}
460
+ >
461
+ {` ${grid.translate('of', 'pager-button')} ${grid.pagesCount >= 0 ? grid.pagesCount : '0'}`}
462
+ </span>
463
+ );
464
+ }
465
+ }
466
+
467
+ grid.pagerButtons.push(pages);
468
+ grid.pagerButtonsDict[pages.id] = grid.pagerButtonsDict[pages.name] = pages;
469
+
470
+ const next = {
471
+ id: 7,
472
+ name: 'next',
473
+ title: 'Next',
474
+ label: Images.images.next ? '' : 'Next',
475
+ click: function (e) {
476
+ grid.gotoNextPage();
477
+ },
478
+ getDisabled: function () {
479
+ return grid._waitingRows || !grid.rows || grid.rows.length <= 0 || grid.pageNumber === grid.pagesCount;
480
+ },
481
+ img: Images.images.next,
482
+ class: grid.pagerButtonsClass,
483
+ }
484
+
485
+ grid.pagerButtons.push(next);
486
+ grid.pagerButtonsDict[next.id] = grid.pagerButtonsDict[next.name] = next;
487
+
488
+ const last = {
489
+ id: 8,
490
+ name: 'last',
491
+ title: 'Last',
492
+ label: Images.images.last ? '' : 'Last',
493
+ click: function (e) {
494
+ grid.gotoLastPage();
495
+ },
496
+ getDisabled: function () {
497
+ return grid._waitingRows || !grid.rows || grid.rows.length <= 0 || grid.pageNumber === grid.pagesCount;
498
+ },
499
+ img: Images.images.last,
500
+ class: grid.pagerButtonsClass,
501
+ }
502
+
503
+ grid.pagerButtons.push(last);
504
+ grid.pagerButtonsDict[last.id] = grid.pagerButtonsDict[last.name] = last;
505
+
506
+ const pgsize = {
507
+ id: 9,
508
+ name: 'pgsize',
509
+ title: 'Page Size',
510
+ label: 'Page Size',
511
+ render: function (button, bottom) {
512
+ return (
513
+ <select
514
+ key={`pager_${bottom ? 'bottom' : 'top'}_${grid.id}_${button.id}_`}
515
+ title={grid.translate(button.title, 'grid-pager-button')}
516
+ grid-pager-item={`${grid.id}_${button.id}_`}
517
+ className={`grid-pager-size ${button.class ? button.class : grid.opt.inputClass || BaseComponent.theme.inputClass || ''}`}
518
+ style={{ width: '4.5em', height: '2em', display: 'inline-block', margin: '0 2px' }}
519
+ value={grid.pageSize}
520
+ disabled={grid._waitingRows || grid.isEditing() || grid.isDisabled() ? 'disabled' : ''}
521
+ onChange={function (e) {
522
+ grid.setPageSize(+e.target.value);
523
+ }}
524
+ >
525
+ {
526
+ grid.pageSizes.map((size, ind) => {
527
+ return (
528
+ <option
529
+ value={+size}
530
+ key={`pageSize_${grid.id}_${ind}_`}
531
+ >
532
+ {size}
533
+ </option>
534
+ );
535
+ })
536
+ }
537
+ </select>
538
+ );
539
+ },
540
+ }
541
+
542
+ grid.pagerButtons.push(pgsize);
543
+ grid.pagerButtonsDict[pgsize.id] = grid.pagerButtonsDict[pgsize.name] = pgsize;
544
+ }
545
+
546
+ const rows = {
547
+ id: 10,
548
+ name: 'rows',
549
+ title: 'Total Rows',
550
+ label: 'Total Rows',
551
+ render: function (button, bottom) {
552
+ const total = `${grid.translate('total rows', 'pager-button')} ${grid.totalRows >= 0 ? grid.totalRows : '0'}`;
553
+ return (
554
+ <span
555
+ className={'grid-pager-total'}
556
+ title={total}
557
+ key={`pager_${bottom ? 'bottom' : 'top'}_${grid.id}_${button.id}_`}
558
+ style={{ margin: '5px 2px' }}
559
+ >
560
+ {total}
561
+ </span>
562
+ );
563
+ }
564
+ }
565
+
566
+ grid.pagerButtons.push(rows);
567
+ grid.pagerButtonsDict[rows.id] = grid.pagerButtonsDict[rows.name] = rows;
568
+
569
+ if (!grid.sortDisabled) {
570
+ const sort = {
571
+ id: 11,
572
+ name: 'sort',
573
+ title: 'Sort',
574
+ label: 'Sort',
575
+ render: function (button, bottom) {
576
+ return (
577
+ grid._sortString != null ?
578
+ <span
579
+ className={'grid-pager-total'}
580
+ title={grid._sortString}
581
+ key={`pager_${bottom ? 'bottom' : 'top'}_${grid.id}_${button.id}_`}
582
+ style={{ margin: '5px 2px' }}
583
+ >
584
+ {`${grid._sortString}`}
585
+ </span>
586
+ :
587
+ <></>
588
+ );
589
+ }
590
+ }
591
+
592
+ grid.pagerButtons.push(sort);
593
+ grid.pagerButtonsDict[sort.id] = grid.pagerButtonsDict[sort.name] = sort;
594
+ }
595
+ }
596
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
597
+ setPageSize(newSize) {
598
+ const grid = this;
599
+
600
+ if (grid.pageSize === newSize || grid.pageSizes.indexOf(newSize) < 0) return;
601
+
602
+ grid.pageSize = newSize;
603
+ grid.pageNumber = 1;
604
+ grid.selectedRowIndex = 0;
605
+ grid.checkPocketState();
606
+ grid.refresh();
607
+ }
608
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
609
+ getHeaderGridTemplateColumns(col) {
610
+ return col.sortInd == null ? 'auto 8px' : 'auto 22px';
611
+ }
612
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
613
+ renderHeaderCell(col, context) {
614
+ const grid = this;
615
+ if (grid.sortDisabled) {
616
+ return super.renderHeaderCell(col, context);
617
+ }
618
+
619
+ const title = grid.translate(col.title || col.name) || '';
620
+ const sortDir = !col.sortable ? '' : col.asc ? '&#11205;' : col.desc ? '&#11206;' : '';
621
+
622
+ const parser = new DOMParser();
623
+ const decodedString = parser.parseFromString(`<!doctype html><body>${sortDir}`, 'text/html').body.textContent;
624
+
625
+ const notDisabled = !grid._waitingRows && !grid.isEditing() && !grid.isDisabled();
626
+
627
+ return (
628
+ <>
629
+ <span
630
+ className={`grid-header-title ${col.sortable ? 'grid-header-title-sortable' : ''}`}
631
+ style={{
632
+ cursor: col.sortable && notDisabled ? 'pointer' : '',
633
+ gridColumn: !sortDir ? 'span 2' : '', opacity: notDisabled ? "1" : "0.6",
634
+ whiteSpace: 'nowrap',
635
+ overflowX: 'hidden',
636
+ width: sortDir ? 'calc(100% - 10px)' : '',
637
+ }}
638
+ onClick={(e) => { if (!grid._waitingRows) grid.changeColumnSortOrder(col, e); }}
639
+ disabled={grid._waitingRows || col.disabled ? 'disabled' : ''}
640
+ >
641
+ {title}
642
+ </span>
643
+ {sortDir ? <span className={'grid-header-sort-sign'} style={{ opacity: notDisabled ? "1" : "0.6" }}>{decodedString + (col.sortInd > 0 ? ` ${col.sortInd} ` : '')}</span> : ''}
644
+ </>
645
+ );
646
+ }
647
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
648
+ getGridSettingsList() {
649
+ const grid = this;
650
+ const res = [
651
+ { id: 0, text: grid.translate('Reset columns order', 'grid-menu') },
652
+ { id: 1, text: grid.translate('Reset columns widths', 'grid-menu') },
653
+ ];
654
+
655
+ if (!grid.sortDisabled) {
656
+ res.push({ id: 2, text: grid.translate('Reset columns sort', 'grid-menu') });
657
+ }
658
+
659
+ return res;
660
+ }
661
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
662
+ getGridSettings(e) {
663
+ const grid = this;
664
+ return new Promise(function (resolve, reject) {
665
+
666
+ const items = grid.getGridSettingsList();
667
+ resolve(items);
668
+ });
669
+ }
670
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
671
+ showGridSettings(e) {
672
+ const grid = this;
673
+
674
+ if (!grid.menuDropdown) return;
675
+
676
+ const elem = document.getElementById(e.target.id);
677
+ grid.menuDropdown.opt.parentRect = elem ? elem.getBoundingClientRect() : e.target.getBoundingClientRect();
678
+
679
+ grid.menuDropdown.popup(e);
680
+ }
681
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
682
+ checkPocketState() {
683
+ super.checkPocketState();
684
+
685
+ const grid = this;
686
+ if (!grid.multi) return;
687
+
688
+ grid.setPocketImage();
689
+ }
690
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
691
+ setPocketImage() {
692
+ const grid = this;
693
+ if (!grid.multi) return;
694
+
695
+ const pocket = grid.pagerButtonsDict['pocket'];
696
+ if (!pocket) return;
697
+
698
+ pocket.img = grid.pocketOpened ? Images.images.pocketOpened : Images.images.pocket;
699
+ }
700
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
701
+ switchGridPocket(e) {
702
+ const grid = this;
703
+ if (!grid.multi) return;
704
+
705
+ grid.pocketOpened = !grid.pocketOpened;
706
+
707
+ grid.setPocketImage();
708
+ grid.refreshState();
709
+
710
+ if (grid.graph) {
711
+ grid.graph.triggerWave({ nodes: [grid], withStartNodes: false });
712
+ }
713
+ }
714
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
715
+ loadPocketRows() {
716
+ const grid = this;
717
+ super.loadPocketRows();
718
+
719
+ grid._sortColumns = [];
720
+ for (let col of grid.columns) {
721
+ if (col.sortInd != null && col.sortInd !== null || col.asc || col.desc) {
722
+ grid._sortColumns.push(col);
723
+ }
724
+ }
725
+
726
+ if (grid._sortColumns.length > 0) {
727
+ grid._sortColumns.sort((a, b) => { return a.sortInd > b.sortInd ? 1 : -1 });
728
+ }
729
+ else {
730
+ grid._sortColumns.push({ name: grid.getKeyColumn(), asc: true });
731
+ }
732
+
733
+ //let sortCol = null;
734
+ //for (let col of grid.columns) {
735
+ // if (col.asc || col.desc) {
736
+ // sortCol = col;
737
+ // break;
738
+ // }
739
+ //}
740
+
741
+ //if (sortCol != null) {
742
+ // this._selectedRows.sort(function (a, b) { return a[sortCol.name] > b[sortCol.name] ? (sortCol.asc ? 1 : -1) : (sortCol.asc ? -1 : 1); });
743
+ //}
744
+
745
+ grid._selectedRows.sort((a, b) => {
746
+ let lastCol;
747
+ for (let col of grid._sortColumns) {
748
+ if (a[col.name] === b[col.name]) continue;
749
+ lastCol = col;
750
+ break;
751
+ }
752
+ if (!lastCol) return 0;
753
+ return a[lastCol.name] > b[lastCol.name] ? (lastCol.asc ? 1 : -1) : (lastCol.asc ? -1 : 1);
754
+ });
755
+ }
756
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
757
+ onSettingsItemClick(itemId) {
758
+ const grid = this;
759
+
760
+ switch (String(itemId)) {
761
+ case '0':
762
+ grid.resetColumnsOrderToDefault();
763
+ break;
764
+ case '1':
765
+ grid.resetColumnsWidthsToDefault();
766
+ break;
767
+ case '2':
768
+ grid.resetColumnsSort();
769
+ break;
770
+ default:
771
+ }
772
+ }
773
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
774
+ resetColumnsSort() {
775
+ const grid = this;
776
+ grid._sortString = '';
777
+ for (let col of grid.columns) {
778
+ delete col.asc;
779
+ delete col.desc;
780
+ delete col.sortInd;
781
+ }
782
+ grid.refresh();
783
+ }
784
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
785
+ changeColumnSortOrder(column, e) {
786
+ const grid = this;
787
+
788
+ if (column === grid._skipClickColumn) {
789
+ delete grid._skipClickColumn;
790
+ return;
791
+ }
792
+
793
+ if (!column.sortable || grid.isEditing() || grid.isDisabled()) return;
794
+
795
+ let nextInd = 1;
796
+ if (e.shiftKey) {
797
+ for (let col of grid.columns) {
798
+ if (col.sortInd != null && col.sortInd !== null) {
799
+ nextInd++;
800
+ }
801
+ else if (col.asc || col.desc) {
802
+ col.sortInd = nextInd++;
803
+ }
804
+ }
805
+ }
806
+
807
+ if (column.asc) {
808
+ delete column.asc;
809
+ column.desc = true;
810
+ if (!e.shiftKey) {
811
+ delete column.sortInd;
812
+ }
813
+ }
814
+ else if (column.desc) {
815
+ const prevInd = column.sortInd;
816
+ delete column.desc;
817
+ delete column.sortInd;
818
+ if (e.shiftKey) {
819
+ for (let col of grid.columns) {
820
+ if (col.sortInd > prevInd) col.sortInd--;
821
+ }
822
+ }
823
+ }
824
+ else {
825
+ column.asc = true;
826
+ if (e.shiftKey) {
827
+ column.sortInd = nextInd;
828
+ }
829
+ else {
830
+ delete column.sortInd;
831
+ }
832
+ }
833
+
834
+ if (!e.shiftKey) {
835
+ for (let col of grid.columns) {
836
+ if (col === column) continue;
837
+
838
+ delete col.asc;
839
+ delete col.desc;
840
+ delete col.sortInd;
841
+ }
842
+ }
843
+
844
+ delete grid._sortString;
845
+ grid.selectedRowIndex = 0;
846
+ grid.afterSortColumn(column);
847
+ grid.refresh();
848
+ }
849
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
850
+ afterSortColumn(column) {
851
+ const grid = this;
852
+ grid.getSortedString();
853
+ delete grid._selectedRows;
854
+ }
855
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
856
+ getSortedString() {
857
+ const grid = this;
858
+ //if (grid._sortString != null) return grid._sortString;
859
+
860
+ grid._sortString = '';
861
+ if (grid.sortDisabled) return '';
862
+
863
+ const sortedColumns = [];
864
+ for (let col of grid.columns) {
865
+ if (col.asc || col.desc) sortedColumns.push(col);
866
+ }
867
+
868
+ sortedColumns.sort((a, b) => { return a.sortInd > b.sortInd ? 1 : -1 });
869
+
870
+ const arr = [];
871
+ for (let col of sortedColumns) {
872
+ arr.push((col.title || col.name) + (col.desc ? ' (' + grid.translate('desc') + ')' : ''));
873
+ }
874
+
875
+ grid._sortString = arr.join(', ');
876
+
877
+ grid._sortString = grid._sortString ? grid.translate('sort', 'pager-button') + ': ' + grid._sortString : '';
878
+ }
879
+ // -------------------------------------------------------------------------------------------------------------------------------------------------------------
880
+ }