@logimaxx/kgrid 0.3.1 → 0.5.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/README.md +4 -2
- package/dist/kgrid.js +1559 -124
- package/dist/kgrid.min.js +2 -2
- package/docs/ai-guide.md +24 -10
- package/docs/api.md +22 -4
- package/docs/configuration.md +62 -12
- package/docs/field-types.md +52 -1
- package/docs/table-shell.md +1 -0
- package/integrations/maxxops.example.js +0 -1
- package/package.json +1 -1
- package/src/cells.js +19 -1
- package/src/column-chooser.js +155 -0
- package/src/configure.js +66 -15
- package/src/constants.js +24 -1
- package/src/data-body.js +31 -53
- package/src/dom.js +24 -17
- package/src/events.js +37 -4
- package/src/field-types-builtins.js +296 -5
- package/src/filters.js +50 -6
- package/src/init.js +64 -4
- package/src/insert-row.js +19 -8
- package/src/preferences.js +408 -0
- package/src/row-actions.js +347 -0
- package/styles/table.css +156 -8
package/dist/kgrid.js
CHANGED
|
@@ -1,10 +1,73 @@
|
|
|
1
|
-
/*! @logimaxx/kgrid | (c) Logimaxx System SRL — proprietary | https://logimaxx.ro | built 2026-
|
|
1
|
+
/*! @logimaxx/kgrid | (c) Logimaxx System SRL — proprietary | https://logimaxx.ro | built 2026-09-16T18:38:48.778Z */
|
|
2
2
|
|
|
3
3
|
/* --- configure.js --- */
|
|
4
4
|
/**
|
|
5
5
|
* Host-app integration: call KGrid.configure({ ... }) before mounting tables.
|
|
6
6
|
*/
|
|
7
7
|
(function (CT) {
|
|
8
|
+
/**
|
|
9
|
+
* Flag is on when the API/form value is true, 1, or "1".
|
|
10
|
+
* @param {*} v
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
13
|
+
CT.isFlagOn = function (v) {
|
|
14
|
+
return v === true || v === 1 || v === "1";
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Walk form.elements (includes fields associated via form="id").
|
|
19
|
+
* Checkboxes always emit "1" or "0" — FormData omits unchecked boxes.
|
|
20
|
+
* @param {HTMLFormElement} form
|
|
21
|
+
* @returns {Record<string, *>}
|
|
22
|
+
*/
|
|
23
|
+
function defaultSerializeForm(form) {
|
|
24
|
+
const out = {};
|
|
25
|
+
const els = form && form.elements;
|
|
26
|
+
if (!els) {
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
for (let i = 0; i < els.length; i++) {
|
|
30
|
+
const el = els[i];
|
|
31
|
+
const name = el.name;
|
|
32
|
+
if (!name || el.disabled) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const type = el.type;
|
|
36
|
+
if (type === "submit" || type === "button" || type === "reset" || type === "file") {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (type === "checkbox") {
|
|
40
|
+
out[name] = el.checked ? "1" : "0";
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (type === "radio") {
|
|
44
|
+
if (!el.checked) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
out[name] = el.value;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (el.tagName === "SELECT" && el.multiple) {
|
|
51
|
+
out[name] = Array.from(el.selectedOptions).map(function (o) {
|
|
52
|
+
return o.value;
|
|
53
|
+
});
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const value = el.value;
|
|
57
|
+
if (Object.prototype.hasOwnProperty.call(out, name)) {
|
|
58
|
+
if (!Array.isArray(out[name])) {
|
|
59
|
+
out[name] = [out[name]];
|
|
60
|
+
}
|
|
61
|
+
out[name].push(value);
|
|
62
|
+
} else {
|
|
63
|
+
out[name] = value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
CT.serializeFormDefault = defaultSerializeForm;
|
|
70
|
+
|
|
8
71
|
const defaultConfig = {
|
|
9
72
|
log: function () {},
|
|
10
73
|
onError: function (err) {
|
|
@@ -19,21 +82,7 @@
|
|
|
19
82
|
},
|
|
20
83
|
/** @type {((context: object, onConfirm: Function, onCancel?: Function) => void)|null} */
|
|
21
84
|
deleteConfirm: null,
|
|
22
|
-
serializeForm:
|
|
23
|
-
const fd = new FormData(form);
|
|
24
|
-
const out = {};
|
|
25
|
-
for (const [key, value] of fd.entries()) {
|
|
26
|
-
if (Object.prototype.hasOwnProperty.call(out, key)) {
|
|
27
|
-
if (!Array.isArray(out[key])) {
|
|
28
|
-
out[key] = [out[key]];
|
|
29
|
-
}
|
|
30
|
-
out[key].push(value);
|
|
31
|
-
} else {
|
|
32
|
-
out[key] = value;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return out;
|
|
36
|
-
},
|
|
85
|
+
serializeForm: defaultSerializeForm,
|
|
37
86
|
/** @type {Record<string, Function|object>|null} name → wrapper fn or field type plugin */
|
|
38
87
|
customInputTypes: null,
|
|
39
88
|
/** @deprecated use customInputTypes */
|
|
@@ -42,6 +91,8 @@
|
|
|
42
91
|
kviews: null,
|
|
43
92
|
/** Default delay (ms) before filter submit; 0 = immediate. Applies to the resolved filter-submit event. */
|
|
44
93
|
filterDebounceMs: 300,
|
|
94
|
+
/** { get(key), set(key, value|null) } — null uses localStorage */
|
|
95
|
+
preferencesStorage: null,
|
|
45
96
|
};
|
|
46
97
|
|
|
47
98
|
CT._config = Object.assign({}, defaultConfig);
|
|
@@ -154,9 +205,23 @@
|
|
|
154
205
|
"paging": false,
|
|
155
206
|
"create": false,
|
|
156
207
|
"update": false,
|
|
208
|
+
/** @deprecated use rowActions items [{ action: "delete" }] */
|
|
157
209
|
"delete": false,
|
|
158
|
-
"clone"
|
|
210
|
+
/** @deprecated use rowActions items [{ action: "clone" }] */
|
|
211
|
+
"clone": false,
|
|
212
|
+
"columnChooser": false
|
|
159
213
|
},
|
|
214
|
+
/**
|
|
215
|
+
* Row action chrome: { display: "buttons"|"dropdown", items: [...] }.
|
|
216
|
+
* Built-ins: delete, clone. Save/cancel come from features.update.
|
|
217
|
+
*/
|
|
218
|
+
rowActions: null,
|
|
219
|
+
/** Persist key for layout (and filters). Required for localStorage. */
|
|
220
|
+
storageKey: null,
|
|
221
|
+
/** Extra suffix for saved filters only (e.g. company id). Layout ignores this. */
|
|
222
|
+
filterStorageScope: null,
|
|
223
|
+
columnChooserLabel: "Columns",
|
|
224
|
+
columnChooserResetLabel: "Reset columns",
|
|
160
225
|
"defaultInteraction": "view",
|
|
161
226
|
"insertFormRow": {
|
|
162
227
|
"position": "top"
|
|
@@ -183,6 +248,15 @@
|
|
|
183
248
|
label: null,
|
|
184
249
|
name: null,
|
|
185
250
|
hidden: false,
|
|
251
|
+
/** When true, column chooser cannot hide this column (still reorderable). */
|
|
252
|
+
locked: false,
|
|
253
|
+
/**
|
|
254
|
+
* Schema: start user-hidden (collapsed) until the user shows it in the chooser.
|
|
255
|
+
* Unlike `hidden`, the column stays in the chooser / DOM. Ignored when `locked`.
|
|
256
|
+
*/
|
|
257
|
+
defaultHidden: false,
|
|
258
|
+
/** Runtime: user hid this column via chooser. Not a schema flag. */
|
|
259
|
+
userHidden: false,
|
|
186
260
|
/** CSS class(es) on header/filter/data/insert cells (alias: columnClass) */
|
|
187
261
|
class: null,
|
|
188
262
|
columnClass: null,
|
|
@@ -351,36 +425,42 @@
|
|
|
351
425
|
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
352
426
|
};
|
|
353
427
|
|
|
354
|
-
/**
|
|
355
|
-
* Whether the table needs a trailing row-actions column (header, filters, data rows, colspan).
|
|
356
|
-
* @param {Object} options table options with features
|
|
357
|
-
* @returns {boolean}
|
|
358
|
-
*/
|
|
359
|
-
CT.hasActionColumn = function (options) {
|
|
360
|
-
const f = options && options.features;
|
|
361
|
-
if (!f) {
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
return !!(f.delete || f.update || f.create || f.clone);
|
|
365
|
-
};
|
|
366
|
-
|
|
367
428
|
/**
|
|
368
429
|
* Sync <colgroup> so row-actions width can collapse in view (table-layout: fixed).
|
|
369
430
|
* @param {JQuery} $table
|
|
370
431
|
* @param {number} dataColumnCount visible data columns (no row-actions)
|
|
371
432
|
* @param {boolean} hasActions
|
|
433
|
+
* @param {Object} [options] table options (for action column width)
|
|
372
434
|
*/
|
|
373
|
-
CT.syncActionColumnColgroup = function ($table, dataColumnCount, hasActions) {
|
|
435
|
+
CT.syncActionColumnColgroup = function ($table, dataColumnCount, hasActions, options, layoutColumns) {
|
|
374
436
|
let $colgroup = $table.children("colgroup.kgrid-colgroup");
|
|
375
437
|
if (!$colgroup.length) {
|
|
376
438
|
$colgroup = $("<colgroup>").addClass("kgrid-colgroup").prependTo($table);
|
|
377
439
|
}
|
|
378
440
|
$colgroup.empty();
|
|
379
|
-
|
|
380
|
-
|
|
441
|
+
const named = Array.isArray(layoutColumns) ? layoutColumns : null;
|
|
442
|
+
if (named && named.length) {
|
|
443
|
+
named.forEach(function (col) {
|
|
444
|
+
const $col = $("<col>");
|
|
445
|
+
if (col && col.name) {
|
|
446
|
+
$col.attr("data-name", col.name);
|
|
447
|
+
}
|
|
448
|
+
if (col && col.userHidden) {
|
|
449
|
+
$col.addClass("kgrid-user-hidden");
|
|
450
|
+
}
|
|
451
|
+
$colgroup.append($col);
|
|
452
|
+
});
|
|
453
|
+
} else {
|
|
454
|
+
for (let i = 0; i < dataColumnCount; i++) {
|
|
455
|
+
$colgroup.append($("<col>"));
|
|
456
|
+
}
|
|
381
457
|
}
|
|
382
458
|
if (hasActions) {
|
|
383
|
-
$colgroup.append(
|
|
459
|
+
$colgroup.append(
|
|
460
|
+
$("<col>")
|
|
461
|
+
.addClass("kgrid-row-actions-col")
|
|
462
|
+
.css("width", CT.actionColumnWidth(options))
|
|
463
|
+
);
|
|
384
464
|
}
|
|
385
465
|
};
|
|
386
466
|
|
|
@@ -439,11 +519,362 @@
|
|
|
439
519
|
if (cls) {
|
|
440
520
|
$el.addClass(cls);
|
|
441
521
|
}
|
|
522
|
+
$el.toggleClass("kgrid-user-hidden", !!col.userHidden);
|
|
442
523
|
return $el;
|
|
443
524
|
};
|
|
444
525
|
})(window.KGrid);
|
|
445
526
|
|
|
446
527
|
|
|
528
|
+
/* --- row-actions.js --- */
|
|
529
|
+
/**
|
|
530
|
+
* Declarative row actions: menu items (delete/clone/custom) + auto save/cancel from features.update.
|
|
531
|
+
*/
|
|
532
|
+
(function (CT) {
|
|
533
|
+
CT.BUILTIN_ROW_ACTIONS = {
|
|
534
|
+
clone: {
|
|
535
|
+
action: "clone",
|
|
536
|
+
icon: "fa-regular fa-copy",
|
|
537
|
+
label: "Clone",
|
|
538
|
+
title: "Clone item",
|
|
539
|
+
when: "idle",
|
|
540
|
+
btnClass: "btn btn-sm btn-outline-secondary clone-item",
|
|
541
|
+
groupClass: "clone-item-grp",
|
|
542
|
+
},
|
|
543
|
+
delete: {
|
|
544
|
+
action: "delete",
|
|
545
|
+
icon: "fas fa-trash",
|
|
546
|
+
label: "Delete",
|
|
547
|
+
title: "Delete item",
|
|
548
|
+
when: "idle",
|
|
549
|
+
btnClass: "btn btn-sm btn-danger delete-item",
|
|
550
|
+
groupClass: "delete-item-grp",
|
|
551
|
+
},
|
|
552
|
+
save: {
|
|
553
|
+
action: "save",
|
|
554
|
+
icon: "fas fa-save",
|
|
555
|
+
label: "Save",
|
|
556
|
+
title: "Save item",
|
|
557
|
+
when: "editing",
|
|
558
|
+
btnClass: "btn btn-sm btn-success save-item",
|
|
559
|
+
groupClass: "edit-item-grp",
|
|
560
|
+
},
|
|
561
|
+
cancel: {
|
|
562
|
+
action: "cancel",
|
|
563
|
+
icon: "fas fa-undo",
|
|
564
|
+
label: "Cancel",
|
|
565
|
+
title: "Cancel edit",
|
|
566
|
+
when: "editing",
|
|
567
|
+
btnClass: "btn btn-sm btn-secondary cancel-edit",
|
|
568
|
+
groupClass: "edit-item-grp",
|
|
569
|
+
},
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
function warn(msg) {
|
|
573
|
+
if (typeof console !== "undefined" && typeof console.warn === "function") {
|
|
574
|
+
console.warn(msg);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function resolveHandler(name, handlers, options) {
|
|
579
|
+
if (!name || typeof name !== "string") {
|
|
580
|
+
return null;
|
|
581
|
+
}
|
|
582
|
+
const fn =
|
|
583
|
+
(handlers && handlers[name]) ||
|
|
584
|
+
(options.functions && options.functions[name]);
|
|
585
|
+
return typeof fn === "function" ? fn : null;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Merge a raw item with builtin defaults (or treat as custom).
|
|
590
|
+
* @param {Object} raw
|
|
591
|
+
* @param {Object} [handlers]
|
|
592
|
+
* @param {Object} options
|
|
593
|
+
* @returns {Object|null}
|
|
594
|
+
*/
|
|
595
|
+
CT.normalizeRowActionItem = function (raw, handlers, options) {
|
|
596
|
+
if (!raw || typeof raw !== "object") {
|
|
597
|
+
return null;
|
|
598
|
+
}
|
|
599
|
+
const action = raw.action;
|
|
600
|
+
if (action === "save" || action === "cancel") {
|
|
601
|
+
warn(
|
|
602
|
+
"KGrid: rowActions items should not list '" +
|
|
603
|
+
action +
|
|
604
|
+
"' — it is added automatically when features.update is true"
|
|
605
|
+
);
|
|
606
|
+
return null;
|
|
607
|
+
}
|
|
608
|
+
let base = {};
|
|
609
|
+
if (action && CT.BUILTIN_ROW_ACTIONS[action]) {
|
|
610
|
+
base = { ...CT.BUILTIN_ROW_ACTIONS[action] };
|
|
611
|
+
} else if (!raw.id) {
|
|
612
|
+
warn("KGrid: custom rowAction requires id: " + JSON.stringify(raw));
|
|
613
|
+
return null;
|
|
614
|
+
} else {
|
|
615
|
+
base = {
|
|
616
|
+
id: raw.id,
|
|
617
|
+
when: "idle",
|
|
618
|
+
btnClass: "btn btn-sm btn-outline-secondary",
|
|
619
|
+
groupClass: "kgrid-custom-action-grp",
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
const item = { ...base, ...raw };
|
|
624
|
+
if (action && CT.BUILTIN_ROW_ACTIONS[action]) {
|
|
625
|
+
item.action = action;
|
|
626
|
+
}
|
|
627
|
+
if (!item.when) {
|
|
628
|
+
item.when = item.action ? base.when || "idle" : "idle";
|
|
629
|
+
}
|
|
630
|
+
if (!item.title && item.label) {
|
|
631
|
+
item.title = item.label;
|
|
632
|
+
}
|
|
633
|
+
if (!item.label && item.title) {
|
|
634
|
+
item.label = item.title;
|
|
635
|
+
}
|
|
636
|
+
if (typeof item.callback === "string") {
|
|
637
|
+
const fn = resolveHandler(item.callback, handlers, options);
|
|
638
|
+
if (!fn) {
|
|
639
|
+
throw new Error(
|
|
640
|
+
"rowAction callback " + item.callback + " not found or is not a function"
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
item.callback = fn;
|
|
644
|
+
}
|
|
645
|
+
if (item.id && typeof item.callback !== "function" && !item.action) {
|
|
646
|
+
throw new Error("Custom rowAction '" + item.id + "' requires a callback");
|
|
647
|
+
}
|
|
648
|
+
return item;
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Resolve and cache rowActions on options.
|
|
653
|
+
* @param {Object} options
|
|
654
|
+
* @param {Object} [handlers]
|
|
655
|
+
* @returns {{ display: string, menuItems: Object[], editingItems: Object[] }}
|
|
656
|
+
*/
|
|
657
|
+
CT.resolveRowActions = function (options, handlers) {
|
|
658
|
+
if (options && options._resolvedRowActions && arguments.length < 2) {
|
|
659
|
+
return options._resolvedRowActions;
|
|
660
|
+
}
|
|
661
|
+
const f = (options && options.features) || {};
|
|
662
|
+
let display = "buttons";
|
|
663
|
+
let rawItems = [];
|
|
664
|
+
|
|
665
|
+
if (options && options.rowActions != null) {
|
|
666
|
+
const ra = options.rowActions;
|
|
667
|
+
if (Array.isArray(ra)) {
|
|
668
|
+
rawItems = ra;
|
|
669
|
+
} else if (CT.isPlainObject(ra)) {
|
|
670
|
+
display = ra.display === "dropdown" ? "dropdown" : "buttons";
|
|
671
|
+
rawItems = Array.isArray(ra.items) ? ra.items : [];
|
|
672
|
+
}
|
|
673
|
+
if (f.delete || f.clone) {
|
|
674
|
+
warn(
|
|
675
|
+
"KGrid: features.delete / features.clone are ignored when rowActions is set"
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
} else {
|
|
679
|
+
if (f.clone) {
|
|
680
|
+
rawItems.push({ action: "clone" });
|
|
681
|
+
}
|
|
682
|
+
if (f.delete) {
|
|
683
|
+
rawItems.push({ action: "delete" });
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const menuItems = [];
|
|
688
|
+
rawItems.forEach(function (raw) {
|
|
689
|
+
const item = CT.normalizeRowActionItem(raw, handlers, options || {});
|
|
690
|
+
if (item) {
|
|
691
|
+
menuItems.push(item);
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
const editingItems = [];
|
|
696
|
+
if (f.update) {
|
|
697
|
+
editingItems.push({ ...CT.BUILTIN_ROW_ACTIONS.save });
|
|
698
|
+
editingItems.push({ ...CT.BUILTIN_ROW_ACTIONS.cancel });
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
const resolved = { display: display, menuItems: menuItems, editingItems: editingItems };
|
|
702
|
+
if (options) {
|
|
703
|
+
options._resolvedRowActions = resolved;
|
|
704
|
+
}
|
|
705
|
+
return resolved;
|
|
706
|
+
};
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Whether the table needs a trailing row-actions column.
|
|
710
|
+
* @param {Object} options
|
|
711
|
+
* @returns {boolean}
|
|
712
|
+
*/
|
|
713
|
+
CT.hasActionColumn = function (options) {
|
|
714
|
+
const f = options && options.features;
|
|
715
|
+
if (f && f.create) {
|
|
716
|
+
return true;
|
|
717
|
+
}
|
|
718
|
+
const ra = CT.resolveRowActions(options);
|
|
719
|
+
return ra.menuItems.length > 0 || ra.editingItems.length > 0;
|
|
720
|
+
};
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Compact width for the row-actions column under table-layout:fixed.
|
|
724
|
+
* @param {Object} [options]
|
|
725
|
+
* @returns {string} CSS width
|
|
726
|
+
*/
|
|
727
|
+
CT.actionColumnWidth = function (options) {
|
|
728
|
+
const ra = CT.resolveRowActions(options);
|
|
729
|
+
const f = (options && options.features) || {};
|
|
730
|
+
const editing = ra.editingItems.length;
|
|
731
|
+
const insert = f.create ? 1 : 0;
|
|
732
|
+
let idle;
|
|
733
|
+
if (ra.display === "dropdown" && ra.menuItems.length > 0) {
|
|
734
|
+
idle = 1;
|
|
735
|
+
} else {
|
|
736
|
+
idle = ra.menuItems.filter(function (it) {
|
|
737
|
+
return it.when !== "editing";
|
|
738
|
+
}).length;
|
|
739
|
+
}
|
|
740
|
+
const n = Math.max(idle, editing, insert, 1);
|
|
741
|
+
return (2.5 * n + 0.75).toFixed(2) + "rem";
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
function iconHtml(icon) {
|
|
745
|
+
if (!icon) {
|
|
746
|
+
return "";
|
|
747
|
+
}
|
|
748
|
+
return "<i class='" + icon + "'></i>";
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
function appendButton($parent, item, dataRowFormId) {
|
|
752
|
+
const $btn = $("<button>")
|
|
753
|
+
.addClass(item.btnClass || "btn btn-sm btn-outline-secondary")
|
|
754
|
+
.attr("type", item.action === "save" ? "submit" : "button")
|
|
755
|
+
.attr("title", item.title || item.label || "");
|
|
756
|
+
if (item.class) {
|
|
757
|
+
$btn.addClass(item.class);
|
|
758
|
+
}
|
|
759
|
+
if (item.action === "save" || item.action === "cancel") {
|
|
760
|
+
$btn.attr("name", item.action === "save" ? "save" : "cancel");
|
|
761
|
+
if (dataRowFormId) {
|
|
762
|
+
$btn.attr("form", dataRowFormId);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
if (item.action === "cancel") {
|
|
766
|
+
$btn.attr(
|
|
767
|
+
"onclick",
|
|
768
|
+
"$(this).parents('[data-type=item]').data().instance.loadFromRemote()"
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
if (item.id) {
|
|
772
|
+
$btn.attr("data-kgrid-action", item.id);
|
|
773
|
+
}
|
|
774
|
+
if (item.action) {
|
|
775
|
+
$btn.attr("data-kgrid-builtin", item.action);
|
|
776
|
+
}
|
|
777
|
+
if (item.icon) {
|
|
778
|
+
$btn.html(iconHtml(item.icon));
|
|
779
|
+
if (item.showLabel && item.label) {
|
|
780
|
+
$btn.append(document.createTextNode(" " + item.label));
|
|
781
|
+
}
|
|
782
|
+
} else if (item.label) {
|
|
783
|
+
$btn.text(item.label);
|
|
784
|
+
}
|
|
785
|
+
$btn.appendTo($parent);
|
|
786
|
+
return $btn;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
/** Minimal escape for button text (labels). */
|
|
790
|
+
CT.escapeHtml = CT.escapeHtml || function (str) {
|
|
791
|
+
return String(str)
|
|
792
|
+
.replace(/&/g, "&")
|
|
793
|
+
.replace(/</g, "<")
|
|
794
|
+
.replace(/>/g, ">")
|
|
795
|
+
.replace(/"/g, """);
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Fill .kgrid-row-actions cell for a data row template.
|
|
800
|
+
* @param {JQuery} $buttonColumn
|
|
801
|
+
* @param {Object} options
|
|
802
|
+
* @param {string|null} dataRowFormId
|
|
803
|
+
*/
|
|
804
|
+
CT.renderRowActions = function ($buttonColumn, options, dataRowFormId) {
|
|
805
|
+
const ra = CT.resolveRowActions(options);
|
|
806
|
+
const idleItems = ra.menuItems.filter(function (it) {
|
|
807
|
+
return it.when !== "editing";
|
|
808
|
+
});
|
|
809
|
+
const editingExtras = ra.menuItems.filter(function (it) {
|
|
810
|
+
return it.when === "editing";
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
if (ra.display === "dropdown" && idleItems.length > 0) {
|
|
814
|
+
const $menuWrap = $("<div>")
|
|
815
|
+
.addClass("btn-group kgrid-row-actions-menu")
|
|
816
|
+
.appendTo($buttonColumn);
|
|
817
|
+
$("<button>")
|
|
818
|
+
.addClass("btn btn-sm btn-outline-secondary dropdown-toggle")
|
|
819
|
+
.attr({
|
|
820
|
+
type: "button",
|
|
821
|
+
"data-bs-toggle": "dropdown",
|
|
822
|
+
"aria-expanded": "false",
|
|
823
|
+
title: "Actions",
|
|
824
|
+
})
|
|
825
|
+
.html("<i class='fas fa-ellipsis-v'></i>")
|
|
826
|
+
.appendTo($menuWrap);
|
|
827
|
+
const $menu = $("<ul>").addClass("dropdown-menu dropdown-menu-end").appendTo($menuWrap);
|
|
828
|
+
idleItems.forEach(function (item) {
|
|
829
|
+
const $li = $("<li>").appendTo($menu);
|
|
830
|
+
const $a = $("<button>")
|
|
831
|
+
.addClass("dropdown-item")
|
|
832
|
+
.attr("type", "button")
|
|
833
|
+
.appendTo($li);
|
|
834
|
+
if (item.action === "clone") {
|
|
835
|
+
$a.addClass("clone-item");
|
|
836
|
+
} else if (item.action === "delete") {
|
|
837
|
+
$a.addClass("delete-item text-danger");
|
|
838
|
+
}
|
|
839
|
+
if (item.id) {
|
|
840
|
+
$a.attr("data-kgrid-action", item.id);
|
|
841
|
+
}
|
|
842
|
+
if (item.action) {
|
|
843
|
+
$a.attr("data-kgrid-builtin", item.action);
|
|
844
|
+
}
|
|
845
|
+
if (item.class) {
|
|
846
|
+
$a.addClass(item.class);
|
|
847
|
+
}
|
|
848
|
+
const label = item.label || item.title || item.action || item.id;
|
|
849
|
+
if (item.icon) {
|
|
850
|
+
$a.html(iconHtml(item.icon) + " " + CT.escapeHtml(label));
|
|
851
|
+
} else {
|
|
852
|
+
$a.text(label);
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
} else {
|
|
856
|
+
idleItems.forEach(function (item) {
|
|
857
|
+
const $grp = $("<div>")
|
|
858
|
+
.addClass(item.groupClass || "btn-group kgrid-custom-action-grp")
|
|
859
|
+
.appendTo($buttonColumn);
|
|
860
|
+
if (item.when === "always") {
|
|
861
|
+
$grp.addClass("kgrid-action-always");
|
|
862
|
+
}
|
|
863
|
+
appendButton($grp, item, dataRowFormId);
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
const editingAll = ra.editingItems.concat(editingExtras);
|
|
868
|
+
if (editingAll.length) {
|
|
869
|
+
const $grp = $("<div>").addClass("btn-group edit-item-grp").appendTo($buttonColumn);
|
|
870
|
+
editingAll.forEach(function (item) {
|
|
871
|
+
appendButton($grp, item, dataRowFormId);
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
})(window.KGrid);
|
|
876
|
+
|
|
877
|
+
|
|
447
878
|
/* --- table-shell.js --- */
|
|
448
879
|
/**
|
|
449
880
|
* Build the KGrid table DOM skeleton (self-contained; no external HTML file).
|
|
@@ -835,16 +1266,307 @@
|
|
|
835
1266
|
* Built-in field types with no external library dependency (plain HTML / jQuery DOM).
|
|
836
1267
|
*/
|
|
837
1268
|
(function (CT) {
|
|
1269
|
+
const MULTI_SELECT_VALUE_CLASS = "kgrid-multi-select-value";
|
|
1270
|
+
const MULTI_SELECT_SEP = ";";
|
|
1271
|
+
|
|
1272
|
+
/**
|
|
1273
|
+
* Normalize multi_select values to a semicolon-joined string (dbAPI `><` / IN).
|
|
1274
|
+
* @param {*} value
|
|
1275
|
+
* @param {string} [sep]
|
|
1276
|
+
* @returns {string}
|
|
1277
|
+
*/
|
|
1278
|
+
CT.normalizeMultiSelectValue = function (value, sep) {
|
|
1279
|
+
const separator = sep || MULTI_SELECT_SEP;
|
|
1280
|
+
if (value == null || value === "") {
|
|
1281
|
+
return "";
|
|
1282
|
+
}
|
|
1283
|
+
if (Array.isArray(value)) {
|
|
1284
|
+
return value
|
|
1285
|
+
.filter(function (v) {
|
|
1286
|
+
return v != null && v !== "";
|
|
1287
|
+
})
|
|
1288
|
+
.map(String)
|
|
1289
|
+
.join(separator);
|
|
1290
|
+
}
|
|
1291
|
+
return String(value);
|
|
1292
|
+
};
|
|
1293
|
+
|
|
1294
|
+
CT.parseMultiSelectValue = function (value, sep) {
|
|
1295
|
+
const str = CT.normalizeMultiSelectValue(value, sep);
|
|
1296
|
+
if (!str) {
|
|
1297
|
+
return [];
|
|
1298
|
+
}
|
|
1299
|
+
return str.split(sep || MULTI_SELECT_SEP).filter(Boolean);
|
|
1300
|
+
};
|
|
1301
|
+
|
|
1302
|
+
(function installMultiSelectValHooks() {
|
|
1303
|
+
const prev = $.valHooks.hidden || {};
|
|
1304
|
+
$.valHooks.hidden = {
|
|
1305
|
+
get: function (elem) {
|
|
1306
|
+
if (elem && elem.classList && elem.classList.contains(MULTI_SELECT_VALUE_CLASS)) {
|
|
1307
|
+
return elem.value;
|
|
1308
|
+
}
|
|
1309
|
+
return prev.get ? prev.get(elem) : undefined;
|
|
1310
|
+
},
|
|
1311
|
+
set: function (elem, value) {
|
|
1312
|
+
if (elem && elem.classList && elem.classList.contains(MULTI_SELECT_VALUE_CLASS)) {
|
|
1313
|
+
const sep = $(elem).data("kgridMultiSep") || MULTI_SELECT_SEP;
|
|
1314
|
+
elem.value = CT.normalizeMultiSelectValue(value, sep);
|
|
1315
|
+
$(elem).triggerHandler("kgrid:multiselect:set");
|
|
1316
|
+
return true;
|
|
1317
|
+
}
|
|
1318
|
+
return prev.set ? prev.set(elem, value) : undefined;
|
|
1319
|
+
},
|
|
1320
|
+
};
|
|
1321
|
+
})();
|
|
1322
|
+
|
|
1323
|
+
function assertMultiSelectOptions(config, mode) {
|
|
1324
|
+
if (!Array.isArray(config.options)) {
|
|
1325
|
+
throw new Error(
|
|
1326
|
+
"multi_select requires an options array (" +
|
|
1327
|
+
mode +
|
|
1328
|
+
"): " +
|
|
1329
|
+
JSON.stringify(config, null, 2)
|
|
1330
|
+
);
|
|
1331
|
+
}
|
|
1332
|
+
config.options.forEach(function (opt) {
|
|
1333
|
+
if (!opt || typeof opt.label !== "string" || typeof opt.value !== "string") {
|
|
1334
|
+
throw new Error(
|
|
1335
|
+
"multi_select options need string label and value: " +
|
|
1336
|
+
JSON.stringify(config, null, 2)
|
|
1337
|
+
);
|
|
1338
|
+
}
|
|
1339
|
+
});
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
function multiSelectEmptyLabel(config) {
|
|
1343
|
+
if (config.placeholder != null && config.placeholder !== "") {
|
|
1344
|
+
return String(config.placeholder);
|
|
1345
|
+
}
|
|
1346
|
+
return "All";
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
function multiSelectSummary(selected, options, emptyLabel) {
|
|
1350
|
+
if (!selected.length) {
|
|
1351
|
+
return emptyLabel;
|
|
1352
|
+
}
|
|
1353
|
+
if (selected.length === 1) {
|
|
1354
|
+
const match = options.find(function (opt) {
|
|
1355
|
+
return opt.value === selected[0];
|
|
1356
|
+
});
|
|
1357
|
+
return match ? match.label : selected[0];
|
|
1358
|
+
}
|
|
1359
|
+
return selected.length + " selected";
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
function buildMultiSelectUi($input, config, mode) {
|
|
1363
|
+
const sep = config.separator || MULTI_SELECT_SEP;
|
|
1364
|
+
const options = config.options || [];
|
|
1365
|
+
const emptyLabel = multiSelectEmptyLabel(config);
|
|
1366
|
+
const compact = mode === "filter";
|
|
1367
|
+
|
|
1368
|
+
$input.data("kgridMultiSep", sep);
|
|
1369
|
+
$input.addClass(MULTI_SELECT_VALUE_CLASS);
|
|
1370
|
+
|
|
1371
|
+
const $root = $("<div>")
|
|
1372
|
+
.addClass("kgrid-multi-select")
|
|
1373
|
+
.attr("data-mode", mode);
|
|
1374
|
+
const $panel = $("<div>").addClass("kgrid-multi-select-panel");
|
|
1375
|
+
let $toggle = null;
|
|
1376
|
+
|
|
1377
|
+
if (compact) {
|
|
1378
|
+
$toggle = $("<button>")
|
|
1379
|
+
.attr({ type: "button", "aria-expanded": "false" })
|
|
1380
|
+
.addClass("kgrid-multi-select-toggle form-select form-select-sm");
|
|
1381
|
+
$panel.attr("hidden", "hidden");
|
|
1382
|
+
$root.append($toggle, $panel);
|
|
1383
|
+
} else {
|
|
1384
|
+
$root.addClass("kgrid-multi-select-open");
|
|
1385
|
+
$root.append($panel);
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
options.forEach(function (opt, index) {
|
|
1389
|
+
const uid = "kgrid_ms_" + CT.uuid() + "_" + index;
|
|
1390
|
+
const $label = $("<label>")
|
|
1391
|
+
.addClass("kgrid-multi-select-option")
|
|
1392
|
+
.attr("for", uid);
|
|
1393
|
+
$("<input>")
|
|
1394
|
+
.attr({
|
|
1395
|
+
type: "checkbox",
|
|
1396
|
+
id: uid,
|
|
1397
|
+
value: opt.value,
|
|
1398
|
+
class: "kgrid-multi-select-check",
|
|
1399
|
+
})
|
|
1400
|
+
.appendTo($label);
|
|
1401
|
+
$("<span>").addClass("kgrid-multi-select-label").text(opt.label).appendTo($label);
|
|
1402
|
+
$panel.append($label);
|
|
1403
|
+
});
|
|
1404
|
+
|
|
1405
|
+
$input.before($root);
|
|
1406
|
+
$root.append($input);
|
|
1407
|
+
|
|
1408
|
+
function selectedValues() {
|
|
1409
|
+
return CT.parseMultiSelectValue($input[0].value, sep);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
function syncCheckboxesFromInput() {
|
|
1413
|
+
const selected = selectedValues();
|
|
1414
|
+
$panel.find("input[type='checkbox']").each(function () {
|
|
1415
|
+
this.checked = selected.indexOf(this.value) !== -1;
|
|
1416
|
+
});
|
|
1417
|
+
if ($toggle) {
|
|
1418
|
+
$toggle.text(multiSelectSummary(selected, options, emptyLabel));
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
function syncInputFromCheckboxes(triggerChange) {
|
|
1423
|
+
const vals = [];
|
|
1424
|
+
$panel.find("input[type='checkbox']:checked").each(function () {
|
|
1425
|
+
vals.push(this.value);
|
|
1426
|
+
});
|
|
1427
|
+
const next = vals.join(sep);
|
|
1428
|
+
if ($input[0].value !== next) {
|
|
1429
|
+
$input[0].value = next;
|
|
1430
|
+
if (triggerChange) {
|
|
1431
|
+
$input.trigger("change");
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
if ($toggle) {
|
|
1435
|
+
$toggle.text(multiSelectSummary(vals, options, emptyLabel));
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
function setOpen(open) {
|
|
1440
|
+
if (!$toggle) {
|
|
1441
|
+
return;
|
|
1442
|
+
}
|
|
1443
|
+
if (open) {
|
|
1444
|
+
// Leave the table/card overflow context so the list is fully visible.
|
|
1445
|
+
$panel.appendTo(document.body);
|
|
1446
|
+
$panel.addClass("kgrid-multi-select-panel-floating");
|
|
1447
|
+
$panel.removeAttr("hidden");
|
|
1448
|
+
$root.addClass("kgrid-multi-select-open");
|
|
1449
|
+
$toggle.attr("aria-expanded", "true");
|
|
1450
|
+
positionFilterPanel();
|
|
1451
|
+
} else {
|
|
1452
|
+
$panel.attr("hidden", "hidden");
|
|
1453
|
+
$root.removeClass("kgrid-multi-select-open");
|
|
1454
|
+
$toggle.attr("aria-expanded", "false");
|
|
1455
|
+
clearFilterPanelPosition();
|
|
1456
|
+
$panel.removeClass("kgrid-multi-select-panel-floating");
|
|
1457
|
+
$panel.insertAfter($toggle);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
function positionFilterPanel() {
|
|
1462
|
+
if (!$toggle) {
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1465
|
+
const rect = $toggle[0].getBoundingClientRect();
|
|
1466
|
+
const width = Math.max(rect.width, 12 * 16);
|
|
1467
|
+
let left = rect.left;
|
|
1468
|
+
const maxLeft = window.innerWidth - width - 8;
|
|
1469
|
+
if (left > maxLeft) {
|
|
1470
|
+
left = Math.max(8, maxLeft);
|
|
1471
|
+
}
|
|
1472
|
+
let top = rect.bottom + 2;
|
|
1473
|
+
const approxHeight = Math.min(14 * 16, options.length * 28 + 16);
|
|
1474
|
+
if (top + approxHeight > window.innerHeight - 8 && rect.top > approxHeight + 8) {
|
|
1475
|
+
top = rect.top - approxHeight - 2;
|
|
1476
|
+
}
|
|
1477
|
+
$panel.css({
|
|
1478
|
+
position: "fixed",
|
|
1479
|
+
top: top + "px",
|
|
1480
|
+
left: left + "px",
|
|
1481
|
+
width: width + "px",
|
|
1482
|
+
minWidth: width + "px",
|
|
1483
|
+
maxWidth: "min(18rem, calc(100vw - 16px))",
|
|
1484
|
+
zIndex: 1080,
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
function clearFilterPanelPosition() {
|
|
1489
|
+
$panel.css({
|
|
1490
|
+
position: "",
|
|
1491
|
+
top: "",
|
|
1492
|
+
left: "",
|
|
1493
|
+
width: "",
|
|
1494
|
+
minWidth: "",
|
|
1495
|
+
maxWidth: "",
|
|
1496
|
+
zIndex: "",
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
const ns = ".kgridMultiSelect_" + CT.uuid();
|
|
1501
|
+
|
|
1502
|
+
$panel.on("change", "input[type='checkbox']", function () {
|
|
1503
|
+
syncInputFromCheckboxes(true);
|
|
1504
|
+
});
|
|
1505
|
+
|
|
1506
|
+
$input.on("kgrid:multiselect:set", function () {
|
|
1507
|
+
syncCheckboxesFromInput();
|
|
1508
|
+
});
|
|
1509
|
+
|
|
1510
|
+
if ($toggle) {
|
|
1511
|
+
$toggle.on("click", function (e) {
|
|
1512
|
+
e.preventDefault();
|
|
1513
|
+
e.stopPropagation();
|
|
1514
|
+
setOpen(!$root.hasClass("kgrid-multi-select-open"));
|
|
1515
|
+
});
|
|
1516
|
+
$(document).on("mousedown" + ns, function (e) {
|
|
1517
|
+
if (!$root.hasClass("kgrid-multi-select-open")) {
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
if ($(e.target).closest($root).length || $(e.target).closest($panel).length) {
|
|
1521
|
+
return;
|
|
1522
|
+
}
|
|
1523
|
+
setOpen(false);
|
|
1524
|
+
});
|
|
1525
|
+
$(window).on("resize" + ns + " scroll" + ns, function () {
|
|
1526
|
+
if ($root.hasClass("kgrid-multi-select-open")) {
|
|
1527
|
+
positionFilterPanel();
|
|
1528
|
+
}
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
const formBind = function () {
|
|
1533
|
+
const formEl = $input.prop("form") || ($input[0] && $input[0].form);
|
|
1534
|
+
if (!formEl) {
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
$(formEl).off("reset" + ns).on("reset" + ns, function () {
|
|
1538
|
+
setTimeout(syncCheckboxesFromInput, 0);
|
|
1539
|
+
});
|
|
1540
|
+
};
|
|
1541
|
+
formBind();
|
|
1542
|
+
setTimeout(formBind, 0);
|
|
1543
|
+
|
|
1544
|
+
syncCheckboxesFromInput();
|
|
1545
|
+
return $root;
|
|
1546
|
+
}
|
|
1547
|
+
|
|
838
1548
|
CT.registerFieldType("multi_select", {
|
|
1549
|
+
filterEvents: "change",
|
|
1550
|
+
filterDebounceMs: 0,
|
|
1551
|
+
validate(config, mode) {
|
|
1552
|
+
assertMultiSelectOptions(config, mode);
|
|
1553
|
+
},
|
|
839
1554
|
create({ config }) {
|
|
840
|
-
const $input = $("<
|
|
841
|
-
if (
|
|
842
|
-
config.
|
|
843
|
-
$("<option>").text(opt.label).attr("value", opt.value).appendTo($input);
|
|
844
|
-
});
|
|
1555
|
+
const $input = $("<input type='hidden'>").addClass(MULTI_SELECT_VALUE_CLASS);
|
|
1556
|
+
if (config.separator) {
|
|
1557
|
+
$input.data("kgridMultiSep", config.separator);
|
|
845
1558
|
}
|
|
846
1559
|
return { $input, skipValueAttr: true };
|
|
847
1560
|
},
|
|
1561
|
+
mount(ctx) {
|
|
1562
|
+
buildMultiSelectUi(ctx.$input, ctx.config || {}, ctx.mode);
|
|
1563
|
+
if (ctx.mode === "update" && ctx.item && ctx.col && ctx.col.name) {
|
|
1564
|
+
const raw = ctx.item.attributes ? ctx.item.attributes[ctx.col.name] : null;
|
|
1565
|
+
if (raw != null && raw !== "") {
|
|
1566
|
+
ctx.$input.val(raw);
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
},
|
|
848
1570
|
});
|
|
849
1571
|
|
|
850
1572
|
CT.registerFieldType("date_range", {
|
|
@@ -1106,8 +1828,9 @@
|
|
|
1106
1828
|
* @param {HTMLFormElement|JQuery} filterFormEl
|
|
1107
1829
|
* @param {Object} options
|
|
1108
1830
|
* @param {Object} [collection] KViews collection
|
|
1831
|
+
* @param {{ skipInitSubmit?: boolean }} [extra]
|
|
1109
1832
|
*/
|
|
1110
|
-
CT.setupDefaultFilters = function (filterFormEl, options, collection) {
|
|
1833
|
+
CT.setupDefaultFilters = function (filterFormEl, options, collection, extra) {
|
|
1111
1834
|
const form = $(filterFormEl)[0];
|
|
1112
1835
|
if (!form || !options || !options.features || !options.features.filtering) {
|
|
1113
1836
|
return;
|
|
@@ -1168,7 +1891,7 @@
|
|
|
1168
1891
|
const missing = persisted.some(function (col) {
|
|
1169
1892
|
return urlFilter.indexOf(col.name + "=") === -1;
|
|
1170
1893
|
});
|
|
1171
|
-
if (missing) {
|
|
1894
|
+
if (missing && !(extra && extra.skipInitSubmit)) {
|
|
1172
1895
|
collection.filtering.handleSubmit(form);
|
|
1173
1896
|
}
|
|
1174
1897
|
};
|
|
@@ -1285,16 +2008,25 @@
|
|
|
1285
2008
|
}
|
|
1286
2009
|
}
|
|
1287
2010
|
|
|
1288
|
-
|
|
2011
|
+
const operator =
|
|
2012
|
+
filter.operator ||
|
|
2013
|
+
(filter.type === "multi_select" ? "><" : undefined);
|
|
2014
|
+
if (operator != null) {
|
|
2015
|
+
input.attr("data-operator", operator);
|
|
2016
|
+
}
|
|
1289
2017
|
input.attr("form", filterFormId);
|
|
1290
2018
|
input.attr("name", col.name);
|
|
1291
2019
|
|
|
1292
2020
|
const defVal = CT.filterDefaultValue(filter.default);
|
|
1293
2021
|
if (defVal != null && defVal !== "" && !input.val()) {
|
|
1294
|
-
|
|
1295
|
-
|
|
2022
|
+
const normalized =
|
|
2023
|
+
filter.type === "multi_select"
|
|
2024
|
+
? CT.normalizeMultiSelectValue(defVal, filter.separator)
|
|
2025
|
+
: String(defVal);
|
|
2026
|
+
input.val(normalized);
|
|
2027
|
+
input.attr("data-default", normalized);
|
|
1296
2028
|
if (input[0]) {
|
|
1297
|
-
input[0].defaultValue =
|
|
2029
|
+
input[0].defaultValue = normalized;
|
|
1298
2030
|
}
|
|
1299
2031
|
}
|
|
1300
2032
|
|
|
@@ -1323,15 +2055,49 @@
|
|
|
1323
2055
|
return filterForm;
|
|
1324
2056
|
};
|
|
1325
2057
|
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
2058
|
+
/** Write current form fields into collection.url.parameters.filter (same rules as KViews Filtering). */
|
|
2059
|
+
CT.syncFormFiltersToCollectionUrl = function (form, collection) {
|
|
2060
|
+
if (!form || !collection || !collection.url) {
|
|
2061
|
+
return;
|
|
2062
|
+
}
|
|
2063
|
+
if (!collection.url.parameters) {
|
|
2064
|
+
collection.url.parameters = {};
|
|
2065
|
+
}
|
|
2066
|
+
const filter = [];
|
|
2067
|
+
const els = form.elements;
|
|
2068
|
+
if (!els) {
|
|
2069
|
+
return;
|
|
2070
|
+
}
|
|
2071
|
+
for (let i = 0; i < els.length; i++) {
|
|
2072
|
+
const el = els[i];
|
|
2073
|
+
if (!el || !el.name) {
|
|
2074
|
+
continue;
|
|
2075
|
+
}
|
|
2076
|
+
const $el = $(el);
|
|
2077
|
+
const value = $el.val();
|
|
2078
|
+
if (value == null || value === "") {
|
|
2079
|
+
continue;
|
|
2080
|
+
}
|
|
2081
|
+
const operator = $el.attr("data-operator") || $el.data("operator") || "=";
|
|
2082
|
+
filter.push(el.name + operator + value);
|
|
2083
|
+
}
|
|
2084
|
+
collection.offset = 0;
|
|
2085
|
+
if (filter.length) {
|
|
2086
|
+
collection.url.parameters.filter = filter.join(",");
|
|
2087
|
+
} else {
|
|
2088
|
+
delete collection.url.parameters.filter;
|
|
2089
|
+
}
|
|
2090
|
+
};
|
|
2091
|
+
|
|
2092
|
+
CT.FilterForm = function (form) {
|
|
2093
|
+
this.form = $(form)[0];
|
|
2094
|
+
this.filter = (name, value, operator = "~=~") => {
|
|
2095
|
+
if (!this.form) return this;
|
|
2096
|
+
let $field = CT.filterFormField(this.form, name);
|
|
2097
|
+
if (!$field.length) {
|
|
2098
|
+
CT.ensureFilterField(this.form, name, value, operator);
|
|
2099
|
+
$field = CT.filterFormField(this.form, name);
|
|
2100
|
+
}
|
|
1335
2101
|
if (!$field.length) return this;
|
|
1336
2102
|
CT.flushFilterSubmit($field);
|
|
1337
2103
|
$field.val(value);
|
|
@@ -1358,6 +2124,19 @@
|
|
|
1358
2124
|
|
|
1359
2125
|
/* --- cells.js --- */
|
|
1360
2126
|
(function (CT) {
|
|
2127
|
+
/**
|
|
2128
|
+
* Bootstrap switch wrapper around a checkbox used as a boolean flag.
|
|
2129
|
+
* @param {JQuery} $input
|
|
2130
|
+
* @returns {JQuery} wrapper
|
|
2131
|
+
*/
|
|
2132
|
+
CT.wrapFlagSwitch = function ($input) {
|
|
2133
|
+
$input
|
|
2134
|
+
.attr({ type: "checkbox", role: "switch", value: "1" })
|
|
2135
|
+
.removeClass("form-control form-input form-control-sm")
|
|
2136
|
+
.addClass("form-check-input");
|
|
2137
|
+
return $("<div class='form-check form-switch kgrid-flag-switch mb-0'>").append($input);
|
|
2138
|
+
};
|
|
2139
|
+
|
|
1361
2140
|
/**
|
|
1362
2141
|
* Setup data cell
|
|
1363
2142
|
* @param {Object} col
|
|
@@ -1427,6 +2206,10 @@
|
|
|
1427
2206
|
$("<div>").addClass("cell-input").append(tpl).appendTo($cell);
|
|
1428
2207
|
return $cell;
|
|
1429
2208
|
}
|
|
2209
|
+
case "checkbox":
|
|
2210
|
+
input = $("<input autocomplete='off' type='checkbox' class='form-check-input'/>");
|
|
2211
|
+
skipValueAttr = true;
|
|
2212
|
+
break;
|
|
1430
2213
|
default:
|
|
1431
2214
|
if(CT.isValidInputType(updateType)) {
|
|
1432
2215
|
input = $(`<input autocomplete='off' type='${updateType}' class='form-input form-control form-control-sm'/>`);
|
|
@@ -1466,7 +2249,8 @@
|
|
|
1466
2249
|
if(!updateConfig.disabled && !updateConfig.readonly)
|
|
1467
2250
|
input.attr("onchange","$(this).parents('tr').addClass('editing')");
|
|
1468
2251
|
|
|
1469
|
-
$
|
|
2252
|
+
const $control = updateType === "checkbox" ? CT.wrapFlagSwitch(input) : input;
|
|
2253
|
+
$("<div>").addClass("cell-input").append($control).appendTo($cell);
|
|
1470
2254
|
return $cell;
|
|
1471
2255
|
};
|
|
1472
2256
|
})(window.KGrid);
|
|
@@ -1484,8 +2268,37 @@
|
|
|
1484
2268
|
return td;
|
|
1485
2269
|
};
|
|
1486
2270
|
|
|
1487
|
-
|
|
2271
|
+
/**
|
|
2272
|
+
* Fill a data <tr> with cells + optional row-actions (KViews item template).
|
|
2273
|
+
* @param {JQuery} dataRow
|
|
2274
|
+
* @param {Object} options
|
|
2275
|
+
* @returns {JQuery} dataRow
|
|
2276
|
+
*/
|
|
2277
|
+
CT.fillDataRow = function (dataRow, options) {
|
|
1488
2278
|
const columns = [...options.columns];
|
|
2279
|
+
const dataRowFormId = "data_row_form_"+CT.uuid()+"_{{this.id}}";
|
|
2280
|
+
const editForm = options.features && options.features.update
|
|
2281
|
+
? $("<form class='edit-form table-row-form'>").attr("id", dataRowFormId)
|
|
2282
|
+
: null;
|
|
2283
|
+
|
|
2284
|
+
columns.forEach(col => {
|
|
2285
|
+
const dataCell = CT.setupCell(col,editForm);
|
|
2286
|
+
if(!col.hidden) {
|
|
2287
|
+
dataCell.appendTo(dataRow);
|
|
2288
|
+
}
|
|
2289
|
+
});
|
|
2290
|
+
|
|
2291
|
+
if (CT.hasActionColumn(options)) {
|
|
2292
|
+
const buttonColumn = $("<td>").addClass("kgrid-row-actions").appendTo(dataRow);
|
|
2293
|
+
CT.renderRowActions(buttonColumn, options, dataRowFormId);
|
|
2294
|
+
}
|
|
2295
|
+
if (editForm) {
|
|
2296
|
+
CT.anchorRowForm(editForm, dataRow);
|
|
2297
|
+
}
|
|
2298
|
+
return dataRow;
|
|
2299
|
+
};
|
|
2300
|
+
|
|
2301
|
+
CT.setupDataBody = function (dataBody, options, labelsRow, filterForm, pagingFooter, noDataTbody) {
|
|
1489
2302
|
const dataRow = $("<tr>").appendTo(dataBody);
|
|
1490
2303
|
if(options.dataRowAttrs && typeof options.dataRowAttrs!=="object") {
|
|
1491
2304
|
throw new Error("options.dataRowAttrs must be an object");
|
|
@@ -1514,58 +2327,7 @@
|
|
|
1514
2327
|
}
|
|
1515
2328
|
}
|
|
1516
2329
|
|
|
1517
|
-
|
|
1518
|
-
const editForm = options.features.update
|
|
1519
|
-
? $("<form class='edit-form table-row-form'>").attr("id", dataRowFormId)
|
|
1520
|
-
: null;
|
|
1521
|
-
|
|
1522
|
-
columns.forEach(col => {
|
|
1523
|
-
const dataCell = CT.setupCell(col,editForm);
|
|
1524
|
-
if(!col.hidden) {
|
|
1525
|
-
dataCell.appendTo(dataRow);
|
|
1526
|
-
}
|
|
1527
|
-
});
|
|
1528
|
-
|
|
1529
|
-
if (CT.hasActionColumn(options)) {
|
|
1530
|
-
const buttonColumn = $("<td>").addClass("kgrid-row-actions").appendTo(dataRow);
|
|
1531
|
-
if(options.features.clone) {
|
|
1532
|
-
$("<div>").addClass("btn-group clone-item-grp").appendTo(buttonColumn).append(
|
|
1533
|
-
$("<button>").addClass("btn btn-sm btn-outline-secondary clone-item")
|
|
1534
|
-
.attr("type","button")
|
|
1535
|
-
.attr("title","Clone item")
|
|
1536
|
-
.append("<i class='fa-regular fa-copy'></i>"));
|
|
1537
|
-
}
|
|
1538
|
-
if(options.features.delete) {
|
|
1539
|
-
$("<div>").addClass("btn-group delete-item-grp").appendTo(buttonColumn).append(
|
|
1540
|
-
$("<button>").addClass("btn btn-sm btn-danger delete-item")
|
|
1541
|
-
.attr("type","button")
|
|
1542
|
-
.attr("title","Delete item")
|
|
1543
|
-
.append("<i class='fas fa-trash'></i>"));
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
if(options.features.update) {
|
|
1547
|
-
const grp = $("<div>").addClass("btn-group edit-item-grp").appendTo(buttonColumn);
|
|
1548
|
-
$("<button>").addClass("btn btn-sm btn-success save-item")
|
|
1549
|
-
.attr("type","submit")
|
|
1550
|
-
.attr("name","save")
|
|
1551
|
-
.attr("title","Save item")
|
|
1552
|
-
.attr("form",dataRowFormId)
|
|
1553
|
-
.html("<i class='fas fa-save'></i>")
|
|
1554
|
-
.appendTo(grp);
|
|
1555
|
-
$("<button>").addClass("btn btn-sm btn-secondary cancel-edit")
|
|
1556
|
-
.attr("type","button")
|
|
1557
|
-
.attr("name","cancel")
|
|
1558
|
-
.attr("title","Cancel edit")
|
|
1559
|
-
.attr("form",dataRowFormId)
|
|
1560
|
-
.attr("onclick","$(this).parents('[data-type=item]').data().instance.loadFromRemote()")
|
|
1561
|
-
.html("<i class='fas fa-undo'></i>")
|
|
1562
|
-
.appendTo(grp);
|
|
1563
|
-
}
|
|
1564
|
-
}
|
|
1565
|
-
if (editForm) {
|
|
1566
|
-
CT.anchorRowForm(editForm, dataRow);
|
|
1567
|
-
}
|
|
1568
|
-
|
|
2330
|
+
CT.fillDataRow(dataRow, options);
|
|
1569
2331
|
return dataBody;
|
|
1570
2332
|
};
|
|
1571
2333
|
|
|
@@ -1620,7 +2382,7 @@
|
|
|
1620
2382
|
grid.instance.newItem(data).then(()=>{
|
|
1621
2383
|
event.target.reset();
|
|
1622
2384
|
if(typeof options.onNewItemCreated=="function") {
|
|
1623
|
-
options.onNewItemCreated(data);
|
|
2385
|
+
options.onNewItemCreated(data, event.target);
|
|
1624
2386
|
}
|
|
1625
2387
|
}).catch(CT.onError);
|
|
1626
2388
|
});
|
|
@@ -1678,6 +2440,10 @@
|
|
|
1678
2440
|
case "hidden":
|
|
1679
2441
|
input = $(`<input type='hidden' class='form-input form-control form-control-sm'/>`);
|
|
1680
2442
|
break;
|
|
2443
|
+
case "checkbox":
|
|
2444
|
+
input = $("<input autocomplete='off' type='checkbox' class='form-check-input'/>");
|
|
2445
|
+
input.attr("data-type", insertType);
|
|
2446
|
+
break;
|
|
1681
2447
|
default:
|
|
1682
2448
|
if(CT.isValidInputType(insertType)) {
|
|
1683
2449
|
input = $(`<input autocomplete='off' type='${insertType}' class='form-input form-control form-control-sm'/>`);
|
|
@@ -1688,12 +2454,18 @@
|
|
|
1688
2454
|
}
|
|
1689
2455
|
}
|
|
1690
2456
|
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
2457
|
+
const rawDefault = (typeof insertConfig.default === "object" && insertConfig.default && insertConfig.default.value != null)
|
|
2458
|
+
? insertConfig.default.value
|
|
2459
|
+
: insertConfig.default;
|
|
2460
|
+
if (insertType === "checkbox") {
|
|
2461
|
+
const on = CT.isFlagOn(rawDefault);
|
|
2462
|
+
input.prop("checked", on).prop("defaultChecked", on);
|
|
2463
|
+
} else if(insertConfig.default != null && insertConfig.default !== "" && !input.val()) {
|
|
2464
|
+
if(String(rawDefault).trim()) {
|
|
2465
|
+
input.val(rawDefault).trigger("change");
|
|
2466
|
+
if (input[0] && "defaultValue" in input[0]) {
|
|
2467
|
+
input[0].defaultValue = input[0].value;
|
|
2468
|
+
}
|
|
1697
2469
|
}
|
|
1698
2470
|
}
|
|
1699
2471
|
|
|
@@ -1716,7 +2488,8 @@
|
|
|
1716
2488
|
}
|
|
1717
2489
|
|
|
1718
2490
|
if(insertConfig.type!=="hidden") {
|
|
1719
|
-
const $
|
|
2491
|
+
const $control = insertType === "checkbox" ? CT.wrapFlagSwitch(input) : input;
|
|
2492
|
+
const $td = $("<td>").append($control).appendTo(newRecordRow).attr("data-label", col.label);
|
|
1720
2493
|
CT.applyColumnCellMeta($td, col);
|
|
1721
2494
|
}
|
|
1722
2495
|
CT.mountField({
|
|
@@ -1823,6 +2596,14 @@
|
|
|
1823
2596
|
$(input).val(typeof val === "boolean" ? String(val) : val);
|
|
1824
2597
|
});
|
|
1825
2598
|
|
|
2599
|
+
view.el.find("input[type='checkbox']").each((index, input) => {
|
|
2600
|
+
const col = colMap.get(input.name);
|
|
2601
|
+
if (!col) {
|
|
2602
|
+
return;
|
|
2603
|
+
}
|
|
2604
|
+
input.checked = CT.isFlagOn(item.attributes[col.name]);
|
|
2605
|
+
});
|
|
2606
|
+
|
|
1826
2607
|
view.el.find("form.edit-form").off("submit").on("submit",(event)=>{
|
|
1827
2608
|
const form = event.target;
|
|
1828
2609
|
event.preventDefault();
|
|
@@ -1837,8 +2618,12 @@
|
|
|
1837
2618
|
});
|
|
1838
2619
|
}
|
|
1839
2620
|
|
|
1840
|
-
|
|
1841
|
-
|
|
2621
|
+
const ra = CT.resolveRowActions(options);
|
|
2622
|
+
const hasClone = ra.menuItems.some((it) => it.action === "clone");
|
|
2623
|
+
const hasDelete = ra.menuItems.some((it) => it.action === "delete");
|
|
2624
|
+
|
|
2625
|
+
if (hasClone) {
|
|
2626
|
+
view.el.find(".clone-item").off("click").on("click", (event) => {
|
|
1842
2627
|
event.preventDefault();
|
|
1843
2628
|
if (typeof options.onClone === "function") {
|
|
1844
2629
|
options.onClone(item, view, event);
|
|
@@ -1846,8 +2631,8 @@
|
|
|
1846
2631
|
});
|
|
1847
2632
|
}
|
|
1848
2633
|
|
|
1849
|
-
if(
|
|
1850
|
-
view.el.find("
|
|
2634
|
+
if (hasDelete) {
|
|
2635
|
+
view.el.find(".delete-item").off("click").on("click", (event) => {
|
|
1851
2636
|
event.preventDefault();
|
|
1852
2637
|
view.el.addClass("confirm-delete");
|
|
1853
2638
|
const clearConfirmState = () => view.el.removeClass("confirm-delete");
|
|
@@ -1861,6 +2646,27 @@
|
|
|
1861
2646
|
});
|
|
1862
2647
|
}
|
|
1863
2648
|
|
|
2649
|
+
const customById = new Map();
|
|
2650
|
+
ra.menuItems.forEach((it) => {
|
|
2651
|
+
if (it.id && typeof it.callback === "function") {
|
|
2652
|
+
customById.set(it.id, it.callback);
|
|
2653
|
+
}
|
|
2654
|
+
});
|
|
2655
|
+
if (customById.size) {
|
|
2656
|
+
view.el
|
|
2657
|
+
.find("[data-kgrid-action]")
|
|
2658
|
+
.off("click.kgridAction")
|
|
2659
|
+
.on("click.kgridAction", (event) => {
|
|
2660
|
+
const id = event.currentTarget.getAttribute("data-kgrid-action");
|
|
2661
|
+
const cb = customById.get(id);
|
|
2662
|
+
if (!cb) {
|
|
2663
|
+
return;
|
|
2664
|
+
}
|
|
2665
|
+
event.preventDefault();
|
|
2666
|
+
cb(event, item, view);
|
|
2667
|
+
});
|
|
2668
|
+
}
|
|
2669
|
+
|
|
1864
2670
|
if (typeof options.onRowFields === "function") {
|
|
1865
2671
|
options.onRowFields(item, view, table);
|
|
1866
2672
|
}
|
|
@@ -1868,6 +2674,575 @@
|
|
|
1868
2674
|
})(window.KGrid);
|
|
1869
2675
|
|
|
1870
2676
|
|
|
2677
|
+
/* --- preferences.js --- */
|
|
2678
|
+
/**
|
|
2679
|
+
* User preferences: column layout (order + hide) and filter values.
|
|
2680
|
+
* Layout is keyed by storageKey; filters also use filterStorageScope (e.g. company).
|
|
2681
|
+
*/
|
|
2682
|
+
(function (CT) {
|
|
2683
|
+
CT.PREFERENCES_VERSION = 1;
|
|
2684
|
+
|
|
2685
|
+
CT.localStoragePreferences = {
|
|
2686
|
+
get: function (key) {
|
|
2687
|
+
try {
|
|
2688
|
+
const root = typeof window !== "undefined" ? window : globalThis;
|
|
2689
|
+
const ls = root && root.localStorage;
|
|
2690
|
+
if (!ls) {
|
|
2691
|
+
return null;
|
|
2692
|
+
}
|
|
2693
|
+
const raw = ls.getItem(key);
|
|
2694
|
+
return raw ? JSON.parse(raw) : null;
|
|
2695
|
+
} catch (err) {
|
|
2696
|
+
return null;
|
|
2697
|
+
}
|
|
2698
|
+
},
|
|
2699
|
+
set: function (key, value) {
|
|
2700
|
+
try {
|
|
2701
|
+
const root = typeof window !== "undefined" ? window : globalThis;
|
|
2702
|
+
const ls = root && root.localStorage;
|
|
2703
|
+
if (!ls) {
|
|
2704
|
+
return;
|
|
2705
|
+
}
|
|
2706
|
+
if (value == null) {
|
|
2707
|
+
ls.removeItem(key);
|
|
2708
|
+
return;
|
|
2709
|
+
}
|
|
2710
|
+
ls.setItem(key, JSON.stringify(value));
|
|
2711
|
+
} catch (err) {
|
|
2712
|
+
/* quota / private mode */
|
|
2713
|
+
}
|
|
2714
|
+
},
|
|
2715
|
+
};
|
|
2716
|
+
|
|
2717
|
+
CT.preferencesStorageFor = function (options) {
|
|
2718
|
+
if (options && options.preferencesStorage) {
|
|
2719
|
+
return options.preferencesStorage;
|
|
2720
|
+
}
|
|
2721
|
+
if (CT._config && CT._config.preferencesStorage) {
|
|
2722
|
+
return CT._config.preferencesStorage;
|
|
2723
|
+
}
|
|
2724
|
+
return CT.localStoragePreferences;
|
|
2725
|
+
};
|
|
2726
|
+
|
|
2727
|
+
CT.layoutStorageKey = function (storageKey) {
|
|
2728
|
+
return "kgrid:" + storageKey + ":layout";
|
|
2729
|
+
};
|
|
2730
|
+
|
|
2731
|
+
CT.filtersStorageKey = function (storageKey, scope) {
|
|
2732
|
+
let key = "kgrid:" + storageKey + ":filters";
|
|
2733
|
+
if (scope != null && String(scope) !== "") {
|
|
2734
|
+
key += ":" + String(scope);
|
|
2735
|
+
}
|
|
2736
|
+
return key;
|
|
2737
|
+
};
|
|
2738
|
+
|
|
2739
|
+
CT.chooserColumns = function (columns) {
|
|
2740
|
+
return (columns || []).filter(function (col) {
|
|
2741
|
+
return col && col.name && !col.hidden;
|
|
2742
|
+
});
|
|
2743
|
+
};
|
|
2744
|
+
|
|
2745
|
+
CT.layoutFromColumns = function (columns) {
|
|
2746
|
+
return {
|
|
2747
|
+
v: CT.PREFERENCES_VERSION,
|
|
2748
|
+
columns: CT.chooserColumns(columns).map(function (col) {
|
|
2749
|
+
return { name: col.name, hidden: !!col.userHidden };
|
|
2750
|
+
}),
|
|
2751
|
+
};
|
|
2752
|
+
};
|
|
2753
|
+
|
|
2754
|
+
CT.parseFilterExpression = function (part) {
|
|
2755
|
+
const s = String(part || "");
|
|
2756
|
+
const ops = ["~=~", ">=", "<=", "!=", "=", ">", "<"];
|
|
2757
|
+
for (let i = 0; i < ops.length; i++) {
|
|
2758
|
+
const op = ops[i];
|
|
2759
|
+
const idx = s.indexOf(op);
|
|
2760
|
+
if (idx > 0) {
|
|
2761
|
+
return {
|
|
2762
|
+
name: s.slice(0, idx),
|
|
2763
|
+
operator: op,
|
|
2764
|
+
value: s.slice(idx + op.length),
|
|
2765
|
+
};
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
return null;
|
|
2769
|
+
};
|
|
2770
|
+
|
|
2771
|
+
CT.isUserFilterColumn = function (col) {
|
|
2772
|
+
return !!(
|
|
2773
|
+
col &&
|
|
2774
|
+
col.name &&
|
|
2775
|
+
!col.hidden &&
|
|
2776
|
+
(!col.features || col.features.filter !== false)
|
|
2777
|
+
);
|
|
2778
|
+
};
|
|
2779
|
+
|
|
2780
|
+
CT.readUserFilters = function (form, columns) {
|
|
2781
|
+
if (!form) {
|
|
2782
|
+
return [];
|
|
2783
|
+
}
|
|
2784
|
+
const out = [];
|
|
2785
|
+
(columns || []).forEach(function (col) {
|
|
2786
|
+
if (!CT.isUserFilterColumn(col)) {
|
|
2787
|
+
return;
|
|
2788
|
+
}
|
|
2789
|
+
const $field = CT.filterFormField(form, col.name);
|
|
2790
|
+
if (!$field.length) {
|
|
2791
|
+
return;
|
|
2792
|
+
}
|
|
2793
|
+
const value = $field.val();
|
|
2794
|
+
if (value == null || value === "" || (Array.isArray(value) && !value.length)) {
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2797
|
+
const operator =
|
|
2798
|
+
$field.attr("data-operator") ||
|
|
2799
|
+
(col.filter && col.filter.operator) ||
|
|
2800
|
+
"~=~";
|
|
2801
|
+
out.push({
|
|
2802
|
+
name: col.name,
|
|
2803
|
+
value: Array.isArray(value) ? value : String(value),
|
|
2804
|
+
operator: operator,
|
|
2805
|
+
});
|
|
2806
|
+
});
|
|
2807
|
+
return out;
|
|
2808
|
+
};
|
|
2809
|
+
|
|
2810
|
+
CT.applyUserFilters = function (form, columns, saved) {
|
|
2811
|
+
if (!form || !saved || !Array.isArray(saved.filters)) {
|
|
2812
|
+
return;
|
|
2813
|
+
}
|
|
2814
|
+
saved.filters.forEach(function (entry) {
|
|
2815
|
+
if (!entry || !entry.name) {
|
|
2816
|
+
return;
|
|
2817
|
+
}
|
|
2818
|
+
const col = (columns || []).find(function (c) {
|
|
2819
|
+
return c && c.name === entry.name;
|
|
2820
|
+
});
|
|
2821
|
+
if (!CT.isUserFilterColumn(col)) {
|
|
2822
|
+
return;
|
|
2823
|
+
}
|
|
2824
|
+
if (entry.value == null || entry.value === "") {
|
|
2825
|
+
return;
|
|
2826
|
+
}
|
|
2827
|
+
let $field = CT.filterFormField(form, entry.name);
|
|
2828
|
+
if (!$field.length) {
|
|
2829
|
+
CT.ensureFilterField(form, entry.name, entry.value, entry.operator);
|
|
2830
|
+
$field = CT.filterFormField(form, entry.name);
|
|
2831
|
+
}
|
|
2832
|
+
if (!$field.length) {
|
|
2833
|
+
return;
|
|
2834
|
+
}
|
|
2835
|
+
$field.val(entry.value);
|
|
2836
|
+
if (entry.operator) {
|
|
2837
|
+
$field.attr("data-operator", entry.operator);
|
|
2838
|
+
}
|
|
2839
|
+
});
|
|
2840
|
+
};
|
|
2841
|
+
|
|
2842
|
+
/** Copy URL filter parts onto the form when the field is missing or empty. */
|
|
2843
|
+
CT.ensureUrlFiltersOnForm = function (form, collection) {
|
|
2844
|
+
if (!form || !collection || !collection.url || !collection.url.parameters) {
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2847
|
+
const urlFilter = String(collection.url.parameters.filter || "");
|
|
2848
|
+
if (!urlFilter) {
|
|
2849
|
+
return;
|
|
2850
|
+
}
|
|
2851
|
+
urlFilter.split(",").forEach(function (part) {
|
|
2852
|
+
const parsed = CT.parseFilterExpression(part.trim());
|
|
2853
|
+
if (!parsed || !parsed.name || parsed.value === "") {
|
|
2854
|
+
return;
|
|
2855
|
+
}
|
|
2856
|
+
const $existing = CT.filterFormField(form, parsed.name);
|
|
2857
|
+
if ($existing.length && $existing.val()) {
|
|
2858
|
+
return;
|
|
2859
|
+
}
|
|
2860
|
+
if ($existing.length) {
|
|
2861
|
+
$existing.val(parsed.value);
|
|
2862
|
+
$existing.attr("data-operator", parsed.operator);
|
|
2863
|
+
return;
|
|
2864
|
+
}
|
|
2865
|
+
CT.ensureFilterField(form, parsed.name, parsed.value, parsed.operator);
|
|
2866
|
+
});
|
|
2867
|
+
};
|
|
2868
|
+
|
|
2869
|
+
CT.preferencesLoadLayout = function (options) {
|
|
2870
|
+
if (!options || !options.storageKey) {
|
|
2871
|
+
return null;
|
|
2872
|
+
}
|
|
2873
|
+
const stored = CT.preferencesStorageFor(options).get(
|
|
2874
|
+
CT.layoutStorageKey(options.storageKey)
|
|
2875
|
+
);
|
|
2876
|
+
if (!stored || stored.v !== CT.PREFERENCES_VERSION || !Array.isArray(stored.columns)) {
|
|
2877
|
+
return null;
|
|
2878
|
+
}
|
|
2879
|
+
return stored;
|
|
2880
|
+
};
|
|
2881
|
+
|
|
2882
|
+
CT.preferencesSaveLayout = function (options, layout) {
|
|
2883
|
+
if (!options || !options.storageKey) {
|
|
2884
|
+
return;
|
|
2885
|
+
}
|
|
2886
|
+
CT.preferencesStorageFor(options).set(
|
|
2887
|
+
CT.layoutStorageKey(options.storageKey),
|
|
2888
|
+
layout
|
|
2889
|
+
);
|
|
2890
|
+
};
|
|
2891
|
+
|
|
2892
|
+
CT.preferencesLoadFilters = function (options) {
|
|
2893
|
+
if (!options || !options.storageKey) {
|
|
2894
|
+
return null;
|
|
2895
|
+
}
|
|
2896
|
+
const stored = CT.preferencesStorageFor(options).get(
|
|
2897
|
+
CT.filtersStorageKey(options.storageKey, options.filterStorageScope)
|
|
2898
|
+
);
|
|
2899
|
+
if (!stored || stored.v !== CT.PREFERENCES_VERSION || !Array.isArray(stored.filters)) {
|
|
2900
|
+
return null;
|
|
2901
|
+
}
|
|
2902
|
+
return stored;
|
|
2903
|
+
};
|
|
2904
|
+
|
|
2905
|
+
CT.preferencesSaveFilters = function (options, filters) {
|
|
2906
|
+
if (!options || !options.storageKey) {
|
|
2907
|
+
return;
|
|
2908
|
+
}
|
|
2909
|
+
CT.preferencesStorageFor(options).set(
|
|
2910
|
+
CT.filtersStorageKey(options.storageKey, options.filterStorageScope),
|
|
2911
|
+
{ v: CT.PREFERENCES_VERSION, filters: filters || [] }
|
|
2912
|
+
);
|
|
2913
|
+
};
|
|
2914
|
+
|
|
2915
|
+
CT.reorderColumns = function (columns, orderedVisibleNames) {
|
|
2916
|
+
const byName = new Map();
|
|
2917
|
+
const schemaHidden = [];
|
|
2918
|
+
(columns || []).forEach(function (col, i) {
|
|
2919
|
+
if (col && col.hidden) {
|
|
2920
|
+
schemaHidden.push({ col: col, index: i });
|
|
2921
|
+
return;
|
|
2922
|
+
}
|
|
2923
|
+
if (col && col.name) {
|
|
2924
|
+
byName.set(col.name, col);
|
|
2925
|
+
}
|
|
2926
|
+
});
|
|
2927
|
+
const visible = [];
|
|
2928
|
+
(orderedVisibleNames || []).forEach(function (name) {
|
|
2929
|
+
if (byName.has(name)) {
|
|
2930
|
+
visible.push(byName.get(name));
|
|
2931
|
+
byName.delete(name);
|
|
2932
|
+
}
|
|
2933
|
+
});
|
|
2934
|
+
byName.forEach(function (col) {
|
|
2935
|
+
visible.push(col);
|
|
2936
|
+
});
|
|
2937
|
+
const result = visible.slice();
|
|
2938
|
+
schemaHidden.forEach(function (entry) {
|
|
2939
|
+
result.splice(Math.min(entry.index, result.length), 0, entry.col);
|
|
2940
|
+
});
|
|
2941
|
+
return result;
|
|
2942
|
+
};
|
|
2943
|
+
|
|
2944
|
+
CT.columnDefaultUserHidden = function (col) {
|
|
2945
|
+
return !!(col && col.defaultHidden && !col.locked && !col.hidden);
|
|
2946
|
+
};
|
|
2947
|
+
|
|
2948
|
+
CT.mergeLayoutIntoColumns = function (columns, layout) {
|
|
2949
|
+
const list = (columns || []).slice();
|
|
2950
|
+
list.forEach(function (col) {
|
|
2951
|
+
if (col && !col.hidden) {
|
|
2952
|
+
col.userHidden = CT.columnDefaultUserHidden(col);
|
|
2953
|
+
}
|
|
2954
|
+
});
|
|
2955
|
+
const visible = CT.chooserColumns(list);
|
|
2956
|
+
const byName = new Map(
|
|
2957
|
+
visible.map(function (col) {
|
|
2958
|
+
return [col.name, col];
|
|
2959
|
+
})
|
|
2960
|
+
);
|
|
2961
|
+
const orderedNames = [];
|
|
2962
|
+
const used = new Set();
|
|
2963
|
+
const saved = layout && Array.isArray(layout.columns) ? layout.columns : [];
|
|
2964
|
+
saved.forEach(function (entry) {
|
|
2965
|
+
if (!entry || !entry.name || !byName.has(entry.name)) {
|
|
2966
|
+
return;
|
|
2967
|
+
}
|
|
2968
|
+
const col = byName.get(entry.name);
|
|
2969
|
+
col.userHidden = !!entry.hidden && !col.locked;
|
|
2970
|
+
orderedNames.push(entry.name);
|
|
2971
|
+
used.add(entry.name);
|
|
2972
|
+
});
|
|
2973
|
+
visible.forEach(function (col) {
|
|
2974
|
+
if (!used.has(col.name)) {
|
|
2975
|
+
orderedNames.push(col.name);
|
|
2976
|
+
}
|
|
2977
|
+
});
|
|
2978
|
+
const merged = CT.reorderColumns(list, orderedNames);
|
|
2979
|
+
const chooser = CT.chooserColumns(merged);
|
|
2980
|
+
if (chooser.length && chooser.every(function (col) { return col.userHidden; })) {
|
|
2981
|
+
const unlock = chooser.find(function (col) { return !col.locked; }) || chooser[0];
|
|
2982
|
+
unlock.userHidden = false;
|
|
2983
|
+
}
|
|
2984
|
+
return merged;
|
|
2985
|
+
};
|
|
2986
|
+
|
|
2987
|
+
CT.applyLayoutToDom = function ($table, columns, options) {
|
|
2988
|
+
if (!$table || !$table.length) {
|
|
2989
|
+
return;
|
|
2990
|
+
}
|
|
2991
|
+
const order = CT.chooserColumns(columns).map(function (col) {
|
|
2992
|
+
return col.name;
|
|
2993
|
+
});
|
|
2994
|
+
const hidden = {};
|
|
2995
|
+
CT.chooserColumns(columns).forEach(function (col) {
|
|
2996
|
+
if (col.userHidden) {
|
|
2997
|
+
hidden[col.name] = true;
|
|
2998
|
+
}
|
|
2999
|
+
});
|
|
3000
|
+
const $rows = $table.find(
|
|
3001
|
+
".thead-labels tr, .thead-filters tr, .before-main-tbody tr, .main-tbody tr, .after-main-tbody tr"
|
|
3002
|
+
);
|
|
3003
|
+
$rows.each(function () {
|
|
3004
|
+
const $row = $(this);
|
|
3005
|
+
const $action = $row.children(".kgrid-row-actions");
|
|
3006
|
+
const byName = {};
|
|
3007
|
+
$row.children("[data-name]").each(function () {
|
|
3008
|
+
byName[this.getAttribute("data-name")] = this;
|
|
3009
|
+
});
|
|
3010
|
+
order.forEach(function (name) {
|
|
3011
|
+
const el = byName[name];
|
|
3012
|
+
if (!el) {
|
|
3013
|
+
return;
|
|
3014
|
+
}
|
|
3015
|
+
if ($action.length) {
|
|
3016
|
+
$(el).insertBefore($action);
|
|
3017
|
+
} else {
|
|
3018
|
+
$row.append(el);
|
|
3019
|
+
}
|
|
3020
|
+
el.classList.toggle("kgrid-user-hidden", !!hidden[name]);
|
|
3021
|
+
});
|
|
3022
|
+
});
|
|
3023
|
+
const hasActions = $table.find(".kgrid-row-actions").length > 0;
|
|
3024
|
+
CT.syncActionColumnColgroup(
|
|
3025
|
+
$table,
|
|
3026
|
+
order.length,
|
|
3027
|
+
hasActions,
|
|
3028
|
+
options,
|
|
3029
|
+
CT.chooserColumns(columns)
|
|
3030
|
+
);
|
|
3031
|
+
};
|
|
3032
|
+
|
|
3033
|
+
CT.refreshCollectionTemplate = function (api, options) {
|
|
3034
|
+
if (!api || !api.instance || typeof CT.fillDataRow !== "function") {
|
|
3035
|
+
return;
|
|
3036
|
+
}
|
|
3037
|
+
const KViews = CT.getKViews(options && options.kviews);
|
|
3038
|
+
if (!KViews || typeof KViews.template !== "function") {
|
|
3039
|
+
return;
|
|
3040
|
+
}
|
|
3041
|
+
const $tr = $("<tr>");
|
|
3042
|
+
if (options.dataRowAttrs && CT.isPlainObject(options.dataRowAttrs)) {
|
|
3043
|
+
Object.keys(options.dataRowAttrs).forEach(function (attr) {
|
|
3044
|
+
$tr.attr(attr, options.dataRowAttrs[attr]);
|
|
3045
|
+
});
|
|
3046
|
+
}
|
|
3047
|
+
CT.fillDataRow($tr, options);
|
|
3048
|
+
const html = $("<div>").append($tr).html();
|
|
3049
|
+
const compiled = KViews.template(html);
|
|
3050
|
+
api.instance.template = compiled;
|
|
3051
|
+
(api.instance.items || []).forEach(function (item) {
|
|
3052
|
+
(item.views || []).forEach(function (view) {
|
|
3053
|
+
view.template = compiled;
|
|
3054
|
+
});
|
|
3055
|
+
});
|
|
3056
|
+
};
|
|
3057
|
+
|
|
3058
|
+
CT.setupFilterPersistence = function (form, options) {
|
|
3059
|
+
if (!form || !options || !options.storageKey) {
|
|
3060
|
+
return;
|
|
3061
|
+
}
|
|
3062
|
+
if (!options.features || !options.features.filtering) {
|
|
3063
|
+
return;
|
|
3064
|
+
}
|
|
3065
|
+
$(form)
|
|
3066
|
+
.off("submit.kgridFilterPrefs")
|
|
3067
|
+
.on("submit.kgridFilterPrefs", function () {
|
|
3068
|
+
CT.preferencesSaveFilters(options, CT.readUserFilters(form, options.columns));
|
|
3069
|
+
});
|
|
3070
|
+
};
|
|
3071
|
+
|
|
3072
|
+
CT.applyColumnLayout = function (api, options, layout) {
|
|
3073
|
+
options.columns = CT.mergeLayoutIntoColumns(options.columns, layout);
|
|
3074
|
+
const $table = api.$host.find("table").first();
|
|
3075
|
+
CT.applyLayoutToDom($table, options.columns, options);
|
|
3076
|
+
CT.refreshCollectionTemplate(api, options);
|
|
3077
|
+
if (typeof CT.renderColumnChooserPanel === "function") {
|
|
3078
|
+
const $panel = api.$host.find(".kgrid-column-chooser-panel");
|
|
3079
|
+
if ($panel.length) {
|
|
3080
|
+
CT.renderColumnChooserPanel($panel, options, api);
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
3083
|
+
return CT.layoutFromColumns(options.columns);
|
|
3084
|
+
};
|
|
3085
|
+
})(window.KGrid);
|
|
3086
|
+
|
|
3087
|
+
|
|
3088
|
+
/* --- column-chooser.js --- */
|
|
3089
|
+
/**
|
|
3090
|
+
* Column chooser: checkbox visibility + HTML5 drag reorder.
|
|
3091
|
+
*/
|
|
3092
|
+
(function (CT) {
|
|
3093
|
+
function layoutFromPanel($panel) {
|
|
3094
|
+
const columns = [];
|
|
3095
|
+
$panel.find(".kgrid-column-chooser-list li[data-name]").each(function () {
|
|
3096
|
+
const name = this.getAttribute("data-name");
|
|
3097
|
+
const checked = $(this).find("input[type='checkbox']").prop("checked");
|
|
3098
|
+
columns.push({ name: name, hidden: !checked });
|
|
3099
|
+
});
|
|
3100
|
+
return { v: CT.PREFERENCES_VERSION, columns: columns };
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
function visibleCount(layout) {
|
|
3104
|
+
return layout.columns.filter(function (c) {
|
|
3105
|
+
return !c.hidden;
|
|
3106
|
+
}).length;
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
CT.renderColumnChooserPanel = function ($panel, options, api) {
|
|
3110
|
+
$panel.empty();
|
|
3111
|
+
const $list = $("<ul>").addClass("kgrid-column-chooser-list").appendTo($panel);
|
|
3112
|
+
CT.chooserColumns(options.columns).forEach(function (col) {
|
|
3113
|
+
const $li = $("<li>")
|
|
3114
|
+
.attr("draggable", "true")
|
|
3115
|
+
.attr("data-name", col.name)
|
|
3116
|
+
.appendTo($list);
|
|
3117
|
+
$("<span>")
|
|
3118
|
+
.addClass("kgrid-column-chooser-handle")
|
|
3119
|
+
.attr("aria-hidden", "true")
|
|
3120
|
+
.text("⋮⋮")
|
|
3121
|
+
.appendTo($li);
|
|
3122
|
+
const $label = $("<label>").appendTo($li);
|
|
3123
|
+
const $cb = $("<input>")
|
|
3124
|
+
.attr("type", "checkbox")
|
|
3125
|
+
.prop("checked", !col.userHidden)
|
|
3126
|
+
.appendTo($label);
|
|
3127
|
+
if (col.locked) {
|
|
3128
|
+
$cb.prop("disabled", true).attr("title", "This column cannot be hidden");
|
|
3129
|
+
}
|
|
3130
|
+
$label.append(document.createTextNode(" " + (col.label || col.name)));
|
|
3131
|
+
});
|
|
3132
|
+
$("<button>")
|
|
3133
|
+
.attr("type", "button")
|
|
3134
|
+
.addClass("btn btn-sm btn-outline-secondary kgrid-column-chooser-reset")
|
|
3135
|
+
.text(options.columnChooserResetLabel || "Reset columns")
|
|
3136
|
+
.appendTo($panel);
|
|
3137
|
+
|
|
3138
|
+
$panel
|
|
3139
|
+
.off("change.kgridChooser")
|
|
3140
|
+
.on("change.kgridChooser", "input[type='checkbox']", function () {
|
|
3141
|
+
const layout = layoutFromPanel($panel);
|
|
3142
|
+
if (visibleCount(layout) < 1) {
|
|
3143
|
+
this.checked = true;
|
|
3144
|
+
return;
|
|
3145
|
+
}
|
|
3146
|
+
api.setLayout(layout);
|
|
3147
|
+
});
|
|
3148
|
+
|
|
3149
|
+
$panel
|
|
3150
|
+
.off("click.kgridChooserReset")
|
|
3151
|
+
.on("click.kgridChooserReset", ".kgrid-column-chooser-reset", function () {
|
|
3152
|
+
api.resetLayout();
|
|
3153
|
+
});
|
|
3154
|
+
|
|
3155
|
+
let dragEl = null;
|
|
3156
|
+
$list.off(".kgridChooserDrag");
|
|
3157
|
+
$list.on("dragstart.kgridChooserDrag", "li", function (e) {
|
|
3158
|
+
dragEl = this;
|
|
3159
|
+
$(this).addClass("kgrid-column-chooser-dragging");
|
|
3160
|
+
if (e.originalEvent && e.originalEvent.dataTransfer) {
|
|
3161
|
+
e.originalEvent.dataTransfer.effectAllowed = "move";
|
|
3162
|
+
e.originalEvent.dataTransfer.setData("text/plain", this.getAttribute("data-name"));
|
|
3163
|
+
}
|
|
3164
|
+
});
|
|
3165
|
+
$list.on("dragend.kgridChooserDrag", "li", function () {
|
|
3166
|
+
$(this).removeClass("kgrid-column-chooser-dragging");
|
|
3167
|
+
dragEl = null;
|
|
3168
|
+
});
|
|
3169
|
+
$list.on("dragover.kgridChooserDrag", "li", function (e) {
|
|
3170
|
+
e.preventDefault();
|
|
3171
|
+
if (!dragEl || dragEl === this) {
|
|
3172
|
+
return;
|
|
3173
|
+
}
|
|
3174
|
+
const rect = this.getBoundingClientRect();
|
|
3175
|
+
const mid = rect.top + rect.height / 2;
|
|
3176
|
+
const clientY = e.originalEvent ? e.originalEvent.clientY : 0;
|
|
3177
|
+
if (clientY < mid) {
|
|
3178
|
+
this.parentNode.insertBefore(dragEl, this);
|
|
3179
|
+
} else {
|
|
3180
|
+
this.parentNode.insertBefore(dragEl, this.nextSibling);
|
|
3181
|
+
}
|
|
3182
|
+
});
|
|
3183
|
+
$list.on("drop.kgridChooserDrag", "li", function (e) {
|
|
3184
|
+
e.preventDefault();
|
|
3185
|
+
api.setLayout(layoutFromPanel($panel));
|
|
3186
|
+
});
|
|
3187
|
+
};
|
|
3188
|
+
|
|
3189
|
+
CT.setupColumnChooser = function ($host, options, api) {
|
|
3190
|
+
if (!options.features || !options.features.columnChooser) {
|
|
3191
|
+
return;
|
|
3192
|
+
}
|
|
3193
|
+
const $shell = CT.getTableInteractionHost($host);
|
|
3194
|
+
$shell.find(".kgrid-column-chooser").remove();
|
|
3195
|
+
const label = options.columnChooserLabel || "Columns";
|
|
3196
|
+
const $wrap = $("<div>").addClass("kgrid-column-chooser");
|
|
3197
|
+
const $btn = $("<button>")
|
|
3198
|
+
.attr("type", "button")
|
|
3199
|
+
.addClass("kgrid-column-chooser-toggle btn btn-sm btn-outline-secondary")
|
|
3200
|
+
.attr("title", label)
|
|
3201
|
+
.attr("aria-expanded", "false")
|
|
3202
|
+
.attr("aria-haspopup", "true")
|
|
3203
|
+
.html(
|
|
3204
|
+
'<i class="fas fa-table-columns" aria-hidden="true"></i>' +
|
|
3205
|
+
'<span class="kgrid-column-chooser-toggle-label"> ' +
|
|
3206
|
+
$("<div>").text(label).html() +
|
|
3207
|
+
"</span>"
|
|
3208
|
+
);
|
|
3209
|
+
const $panel = $("<div>")
|
|
3210
|
+
.addClass("kgrid-column-chooser-panel")
|
|
3211
|
+
.attr("hidden", "hidden");
|
|
3212
|
+
$wrap.append($btn, $panel);
|
|
3213
|
+
$shell.prepend($wrap);
|
|
3214
|
+
CT.renderColumnChooserPanel($panel, options, api);
|
|
3215
|
+
|
|
3216
|
+
function close() {
|
|
3217
|
+
$panel.attr("hidden", "hidden");
|
|
3218
|
+
$btn.attr("aria-expanded", "false");
|
|
3219
|
+
}
|
|
3220
|
+
|
|
3221
|
+
$btn.on("click", function (e) {
|
|
3222
|
+
e.stopPropagation();
|
|
3223
|
+
const open = !$panel.attr("hidden");
|
|
3224
|
+
if (open) {
|
|
3225
|
+
close();
|
|
3226
|
+
} else {
|
|
3227
|
+
$panel.removeAttr("hidden");
|
|
3228
|
+
$btn.attr("aria-expanded", "true");
|
|
3229
|
+
}
|
|
3230
|
+
});
|
|
3231
|
+
|
|
3232
|
+
const ns = "kgridChooser" + CT.uuid();
|
|
3233
|
+
$(document).on("pointerdown." + ns, function (e) {
|
|
3234
|
+
if (!document.body.contains($wrap[0])) {
|
|
3235
|
+
$(document).off("pointerdown." + ns);
|
|
3236
|
+
return;
|
|
3237
|
+
}
|
|
3238
|
+
if (!$wrap[0].contains(e.target)) {
|
|
3239
|
+
close();
|
|
3240
|
+
}
|
|
3241
|
+
});
|
|
3242
|
+
};
|
|
3243
|
+
})(window.KGrid);
|
|
3244
|
+
|
|
3245
|
+
|
|
1871
3246
|
/* --- init.js --- */
|
|
1872
3247
|
(function (CT) {
|
|
1873
3248
|
/**
|
|
@@ -1928,9 +3303,40 @@
|
|
|
1928
3303
|
}
|
|
1929
3304
|
return api.setInteraction(api.getInteraction() === "edit" ? "view" : "edit");
|
|
1930
3305
|
},
|
|
3306
|
+
getLayout() {
|
|
3307
|
+
return CT.layoutFromColumns(options.columns);
|
|
3308
|
+
},
|
|
3309
|
+
setLayout(layout) {
|
|
3310
|
+
CT.applyColumnLayout(api, options, layout);
|
|
3311
|
+
CT.preferencesSaveLayout(options, api.getLayout());
|
|
3312
|
+
return api.getLayout();
|
|
3313
|
+
},
|
|
3314
|
+
resetLayout() {
|
|
3315
|
+
const byName = new Map();
|
|
3316
|
+
options.columns.forEach(function (col) {
|
|
3317
|
+
if (col && col.name) {
|
|
3318
|
+
byName.set(col.name, col);
|
|
3319
|
+
}
|
|
3320
|
+
});
|
|
3321
|
+
options.columns = schemaOrder
|
|
3322
|
+
.map(function (name) {
|
|
3323
|
+
return byName.get(name);
|
|
3324
|
+
})
|
|
3325
|
+
.filter(Boolean);
|
|
3326
|
+
CT.preferencesSaveLayout(options, null);
|
|
3327
|
+
CT.applyColumnLayout(api, options, null);
|
|
3328
|
+
return api.getLayout();
|
|
3329
|
+
},
|
|
1931
3330
|
};
|
|
1932
3331
|
|
|
1933
|
-
options.columns = options.columns.map((col) => CT.normalizeColumnConfig(col));
|
|
3332
|
+
options.columns = (options.columns || []).map((col) => CT.normalizeColumnConfig(col));
|
|
3333
|
+
const schemaOrder = options.columns.map(function (col) {
|
|
3334
|
+
return col.name;
|
|
3335
|
+
});
|
|
3336
|
+
options.columns = CT.mergeLayoutIntoColumns(
|
|
3337
|
+
options.columns,
|
|
3338
|
+
CT.preferencesLoadLayout(options)
|
|
3339
|
+
);
|
|
1934
3340
|
|
|
1935
3341
|
const handlers = options.handlers ?? {};
|
|
1936
3342
|
delete options.handlers;
|
|
@@ -1945,6 +3351,14 @@
|
|
|
1945
3351
|
}
|
|
1946
3352
|
options.onClone = fn;
|
|
1947
3353
|
}
|
|
3354
|
+
CT.resolveRowActions(options, handlers);
|
|
3355
|
+
{
|
|
3356
|
+
const ra = options._resolvedRowActions;
|
|
3357
|
+
CT.getTableInteractionHost($host).attr(
|
|
3358
|
+
"data-has-row-menu",
|
|
3359
|
+
ra && ra.menuItems && ra.menuItems.length ? "true" : "false"
|
|
3360
|
+
);
|
|
3361
|
+
}
|
|
1948
3362
|
options.columns.forEach((col) => {
|
|
1949
3363
|
["insert", "update", "display"].forEach((mode) => {
|
|
1950
3364
|
const events = col[mode].events;
|
|
@@ -1998,7 +3412,13 @@
|
|
|
1998
3412
|
const hasActionColumn = CT.hasActionColumn(options);
|
|
1999
3413
|
const visibleColumnsCount = labelsRow.find("th").length;
|
|
2000
3414
|
const dataColumnCount = visibleColumnsCount - (hasActionColumn ? 1 : 0);
|
|
2001
|
-
CT.syncActionColumnColgroup(
|
|
3415
|
+
CT.syncActionColumnColgroup(
|
|
3416
|
+
table,
|
|
3417
|
+
dataColumnCount,
|
|
3418
|
+
hasActionColumn,
|
|
3419
|
+
options,
|
|
3420
|
+
CT.chooserColumns(options.columns)
|
|
3421
|
+
);
|
|
2002
3422
|
|
|
2003
3423
|
const filterForm = options.filterForm ?? CT.setupFilterHeader(table, options);
|
|
2004
3424
|
|
|
@@ -2062,7 +3482,24 @@
|
|
|
2062
3482
|
if (options.insertUrl) {
|
|
2063
3483
|
api.instance.setUrl(options.insertUrl, "insert");
|
|
2064
3484
|
}
|
|
3485
|
+
}
|
|
3486
|
+
|
|
3487
|
+
CT.setupDefaultFilters(filterForm, options, api.instance, { skipInitSubmit: true });
|
|
3488
|
+
const filterFormEl = filterForm && (filterForm.jquery ? filterForm[0] : filterForm);
|
|
3489
|
+
CT.applyUserFilters(
|
|
3490
|
+
filterFormEl,
|
|
3491
|
+
options.columns,
|
|
3492
|
+
CT.preferencesLoadFilters(options)
|
|
3493
|
+
);
|
|
3494
|
+
CT.ensureUrlFiltersOnForm(filterFormEl, api.instance);
|
|
3495
|
+
CT.setupFilterPersistence(filterFormEl, options);
|
|
3496
|
+
CT.setupColumnChooser($host, options, api);
|
|
3497
|
+
|
|
3498
|
+
if (options.url) {
|
|
2065
3499
|
try {
|
|
3500
|
+
if (options.features && options.features.filtering && filterFormEl) {
|
|
3501
|
+
CT.syncFormFiltersToCollectionUrl(filterFormEl, api.instance);
|
|
3502
|
+
}
|
|
2066
3503
|
await api.instance.loadFromRemote();
|
|
2067
3504
|
} catch (error) {
|
|
2068
3505
|
CT.onError(error);
|
|
@@ -2074,8 +3511,6 @@
|
|
|
2074
3511
|
throw new Error("Invalid data: missing datasource url or data for table");
|
|
2075
3512
|
}
|
|
2076
3513
|
|
|
2077
|
-
CT.setupDefaultFilters(filterForm, options, api.instance);
|
|
2078
|
-
|
|
2079
3514
|
return api;
|
|
2080
3515
|
};
|
|
2081
3516
|
})(window.KGrid);
|