@logimaxx/kgrid 0.4.0 → 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/dist/kgrid.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @logimaxx/kgrid | (c) Logimaxx System SRL — proprietary | https://logimaxx.ro | built 2026-09-02T08:17:18.911Z */
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
  /**
@@ -205,10 +205,17 @@
205
205
  "paging": false,
206
206
  "create": false,
207
207
  "update": false,
208
+ /** @deprecated use rowActions items [{ action: "delete" }] */
208
209
  "delete": false,
210
+ /** @deprecated use rowActions items [{ action: "clone" }] */
209
211
  "clone": false,
210
212
  "columnChooser": false
211
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,
212
219
  /** Persist key for layout (and filters). Required for localStorage. */
213
220
  storageKey: null,
214
221
  /** Extra suffix for saved filters only (e.g. company id). Layout ignores this. */
@@ -243,6 +250,11 @@
243
250
  hidden: false,
244
251
  /** When true, column chooser cannot hide this column (still reorderable). */
245
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,
246
258
  /** Runtime: user hid this column via chooser. Not a schema flag. */
247
259
  userHidden: false,
248
260
  /** CSS class(es) on header/filter/data/insert cells (alias: columnClass) */
@@ -413,35 +425,6 @@
413
425
  return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
414
426
  };
415
427
 
416
- /**
417
- * Whether the table needs a trailing row-actions column (header, filters, data rows, colspan).
418
- * @param {Object} options table options with features
419
- * @returns {boolean}
420
- */
421
- CT.hasActionColumn = function (options) {
422
- const f = options && options.features;
423
- if (!f) {
424
- return false;
425
- }
426
- return !!(f.delete || f.update || f.create || f.clone);
427
- };
428
-
429
- /**
430
- * Compact width for the row-actions column under table-layout:fixed
431
- * (fixed layout ignores content; 1% caused overflow). Sized from max buttons
432
- * shown in any mode (idle clone/delete vs editing save/cancel).
433
- * @param {Object} [options]
434
- * @returns {string} CSS width
435
- */
436
- CT.actionColumnWidth = function (options) {
437
- const f = (options && options.features) || {};
438
- const idle = (f.clone ? 1 : 0) + (f.delete ? 1 : 0);
439
- const editing = f.update ? 2 : 0;
440
- const insert = f.create ? 1 : 0;
441
- const n = Math.max(idle, editing, insert, 1);
442
- return (2.5 * n + 0.75).toFixed(2) + "rem";
443
- };
444
-
445
428
  /**
446
429
  * Sync <colgroup> so row-actions width can collapse in view (table-layout: fixed).
447
430
  * @param {JQuery} $table
@@ -542,6 +525,356 @@
542
525
  })(window.KGrid);
543
526
 
544
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, "&amp;")
793
+ .replace(/</g, "&lt;")
794
+ .replace(/>/g, "&gt;")
795
+ .replace(/"/g, "&quot;");
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
+
545
878
  /* --- table-shell.js --- */
546
879
  /**
547
880
  * Build the KGrid table DOM skeleton (self-contained; no external HTML file).
@@ -933,16 +1266,307 @@
933
1266
  * Built-in field types with no external library dependency (plain HTML / jQuery DOM).
934
1267
  */
935
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
+
936
1548
  CT.registerFieldType("multi_select", {
1549
+ filterEvents: "change",
1550
+ filterDebounceMs: 0,
1551
+ validate(config, mode) {
1552
+ assertMultiSelectOptions(config, mode);
1553
+ },
937
1554
  create({ config }) {
938
- const $input = $("<select class='form-select form-select-sm' multiple>");
939
- if (Array.isArray(config.options)) {
940
- config.options.forEach((opt) => {
941
- $("<option>").text(opt.label).attr("value", opt.value).appendTo($input);
942
- });
1555
+ const $input = $("<input type='hidden'>").addClass(MULTI_SELECT_VALUE_CLASS);
1556
+ if (config.separator) {
1557
+ $input.data("kgridMultiSep", config.separator);
943
1558
  }
944
1559
  return { $input, skipValueAttr: true };
945
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
+ },
946
1570
  });
947
1571
 
948
1572
  CT.registerFieldType("date_range", {
@@ -1384,16 +2008,25 @@
1384
2008
  }
1385
2009
  }
1386
2010
 
1387
- input.attr("data-operator", filter.operator);
2011
+ const operator =
2012
+ filter.operator ||
2013
+ (filter.type === "multi_select" ? "><" : undefined);
2014
+ if (operator != null) {
2015
+ input.attr("data-operator", operator);
2016
+ }
1388
2017
  input.attr("form", filterFormId);
1389
2018
  input.attr("name", col.name);
1390
2019
 
1391
2020
  const defVal = CT.filterDefaultValue(filter.default);
1392
2021
  if (defVal != null && defVal !== "" && !input.val()) {
1393
- input.val(String(defVal));
1394
- input.attr("data-default", String(defVal));
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);
1395
2028
  if (input[0]) {
1396
- input[0].defaultValue = String(defVal);
2029
+ input[0].defaultValue = normalized;
1397
2030
  }
1398
2031
  }
1399
2032
 
@@ -1657,39 +2290,7 @@
1657
2290
 
1658
2291
  if (CT.hasActionColumn(options)) {
1659
2292
  const buttonColumn = $("<td>").addClass("kgrid-row-actions").appendTo(dataRow);
1660
- if(options.features.clone) {
1661
- $("<div>").addClass("btn-group clone-item-grp").appendTo(buttonColumn).append(
1662
- $("<button>").addClass("btn btn-sm btn-outline-secondary clone-item")
1663
- .attr("type","button")
1664
- .attr("title","Clone item")
1665
- .append("<i class='fa-regular fa-copy'></i>"));
1666
- }
1667
- if(options.features.delete) {
1668
- $("<div>").addClass("btn-group delete-item-grp").appendTo(buttonColumn).append(
1669
- $("<button>").addClass("btn btn-sm btn-danger delete-item")
1670
- .attr("type","button")
1671
- .attr("title","Delete item")
1672
- .append("<i class='fas fa-trash'></i>"));
1673
- }
1674
-
1675
- if(options.features.update) {
1676
- const grp = $("<div>").addClass("btn-group edit-item-grp").appendTo(buttonColumn);
1677
- $("<button>").addClass("btn btn-sm btn-success save-item")
1678
- .attr("type","submit")
1679
- .attr("name","save")
1680
- .attr("title","Save item")
1681
- .attr("form",dataRowFormId)
1682
- .html("<i class='fas fa-save'></i>")
1683
- .appendTo(grp);
1684
- $("<button>").addClass("btn btn-sm btn-secondary cancel-edit")
1685
- .attr("type","button")
1686
- .attr("name","cancel")
1687
- .attr("title","Cancel edit")
1688
- .attr("form",dataRowFormId)
1689
- .attr("onclick","$(this).parents('[data-type=item]').data().instance.loadFromRemote()")
1690
- .html("<i class='fas fa-undo'></i>")
1691
- .appendTo(grp);
1692
- }
2293
+ CT.renderRowActions(buttonColumn, options, dataRowFormId);
1693
2294
  }
1694
2295
  if (editForm) {
1695
2296
  CT.anchorRowForm(editForm, dataRow);
@@ -1781,7 +2382,7 @@
1781
2382
  grid.instance.newItem(data).then(()=>{
1782
2383
  event.target.reset();
1783
2384
  if(typeof options.onNewItemCreated=="function") {
1784
- options.onNewItemCreated(data);
2385
+ options.onNewItemCreated(data, event.target);
1785
2386
  }
1786
2387
  }).catch(CT.onError);
1787
2388
  });
@@ -1857,10 +2458,14 @@
1857
2458
  ? insertConfig.default.value
1858
2459
  : insertConfig.default;
1859
2460
  if (insertType === "checkbox") {
1860
- input.prop("checked", CT.isFlagOn(rawDefault));
2461
+ const on = CT.isFlagOn(rawDefault);
2462
+ input.prop("checked", on).prop("defaultChecked", on);
1861
2463
  } else if(insertConfig.default != null && insertConfig.default !== "" && !input.val()) {
1862
2464
  if(String(rawDefault).trim()) {
1863
2465
  input.val(rawDefault).trigger("change");
2466
+ if (input[0] && "defaultValue" in input[0]) {
2467
+ input[0].defaultValue = input[0].value;
2468
+ }
1864
2469
  }
1865
2470
  }
1866
2471
 
@@ -2013,8 +2618,12 @@
2013
2618
  });
2014
2619
  }
2015
2620
 
2016
- if(options.features.clone) {
2017
- view.el.find("button.clone-item").off("click").on("click",(event)=>{
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) => {
2018
2627
  event.preventDefault();
2019
2628
  if (typeof options.onClone === "function") {
2020
2629
  options.onClone(item, view, event);
@@ -2022,8 +2631,8 @@
2022
2631
  });
2023
2632
  }
2024
2633
 
2025
- if(options.features.delete) {
2026
- view.el.find("button.delete-item").off("click").on("click",(event)=>{
2634
+ if (hasDelete) {
2635
+ view.el.find(".delete-item").off("click").on("click", (event) => {
2027
2636
  event.preventDefault();
2028
2637
  view.el.addClass("confirm-delete");
2029
2638
  const clearConfirmState = () => view.el.removeClass("confirm-delete");
@@ -2037,6 +2646,27 @@
2037
2646
  });
2038
2647
  }
2039
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
+
2040
2670
  if (typeof options.onRowFields === "function") {
2041
2671
  options.onRowFields(item, view, table);
2042
2672
  }
@@ -2311,11 +2941,15 @@
2311
2941
  return result;
2312
2942
  };
2313
2943
 
2944
+ CT.columnDefaultUserHidden = function (col) {
2945
+ return !!(col && col.defaultHidden && !col.locked && !col.hidden);
2946
+ };
2947
+
2314
2948
  CT.mergeLayoutIntoColumns = function (columns, layout) {
2315
2949
  const list = (columns || []).slice();
2316
2950
  list.forEach(function (col) {
2317
2951
  if (col && !col.hidden) {
2318
- col.userHidden = false;
2952
+ col.userHidden = CT.columnDefaultUserHidden(col);
2319
2953
  }
2320
2954
  });
2321
2955
  const visible = CT.chooserColumns(list);
@@ -2717,6 +3351,14 @@
2717
3351
  }
2718
3352
  options.onClone = fn;
2719
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
+ }
2720
3362
  options.columns.forEach((col) => {
2721
3363
  ["insert", "update", "display"].forEach((mode) => {
2722
3364
  const events = col[mode].events;