@logimaxx/kgrid 0.4.0 → 0.5.1

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:47:39.173Z */
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,365 @@
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
+ "data-bs-popper-config": JSON.stringify({ strategy: "fixed" }),
823
+ "aria-expanded": "false",
824
+ title: "Actions",
825
+ })
826
+ .html("<i class='fas fa-ellipsis-v'></i>")
827
+ .appendTo($menuWrap);
828
+ const $menu = $("<ul>")
829
+ .addClass("dropdown-menu dropdown-menu-end")
830
+ .appendTo($menuWrap);
831
+ idleItems.forEach(function (item) {
832
+ const $li = $("<li>").appendTo($menu);
833
+ const $a = $("<button>")
834
+ .addClass("dropdown-item")
835
+ .attr("type", "button")
836
+ .appendTo($li);
837
+ if (item.action === "clone") {
838
+ $a.addClass("clone-item");
839
+ } else if (item.action === "delete") {
840
+ $a.addClass("delete-item text-danger");
841
+ }
842
+ if (item.id) {
843
+ $a.attr("data-kgrid-action", item.id);
844
+ }
845
+ if (item.action) {
846
+ $a.attr("data-kgrid-builtin", item.action);
847
+ }
848
+ if (item.class) {
849
+ $a.addClass(item.class);
850
+ }
851
+ if (item.btnClass && !item.action) {
852
+ // Custom items may pass btnClass meant for button mode; keep danger etc. as text color hints.
853
+ if (/\bbtn-danger\b|\btext-danger\b|\boutline-danger\b/.test(item.btnClass)) {
854
+ $a.addClass("text-danger");
855
+ }
856
+ }
857
+ const label = item.label || item.title || item.action || item.id;
858
+ if (item.icon) {
859
+ $a.html(iconHtml(item.icon) + " " + CT.escapeHtml(label));
860
+ } else {
861
+ $a.text(label);
862
+ }
863
+ });
864
+ } else {
865
+ idleItems.forEach(function (item) {
866
+ const $grp = $("<div>")
867
+ .addClass(item.groupClass || "btn-group kgrid-custom-action-grp")
868
+ .appendTo($buttonColumn);
869
+ if (item.when === "always") {
870
+ $grp.addClass("kgrid-action-always");
871
+ }
872
+ appendButton($grp, item, dataRowFormId);
873
+ });
874
+ }
875
+
876
+ const editingAll = ra.editingItems.concat(editingExtras);
877
+ if (editingAll.length) {
878
+ const $grp = $("<div>").addClass("btn-group edit-item-grp").appendTo($buttonColumn);
879
+ editingAll.forEach(function (item) {
880
+ appendButton($grp, item, dataRowFormId);
881
+ });
882
+ }
883
+ };
884
+ })(window.KGrid);
885
+
886
+
545
887
  /* --- table-shell.js --- */
546
888
  /**
547
889
  * Build the KGrid table DOM skeleton (self-contained; no external HTML file).
@@ -933,16 +1275,307 @@
933
1275
  * Built-in field types with no external library dependency (plain HTML / jQuery DOM).
934
1276
  */
935
1277
  (function (CT) {
1278
+ const MULTI_SELECT_VALUE_CLASS = "kgrid-multi-select-value";
1279
+ const MULTI_SELECT_SEP = ";";
1280
+
1281
+ /**
1282
+ * Normalize multi_select values to a semicolon-joined string (dbAPI `><` / IN).
1283
+ * @param {*} value
1284
+ * @param {string} [sep]
1285
+ * @returns {string}
1286
+ */
1287
+ CT.normalizeMultiSelectValue = function (value, sep) {
1288
+ const separator = sep || MULTI_SELECT_SEP;
1289
+ if (value == null || value === "") {
1290
+ return "";
1291
+ }
1292
+ if (Array.isArray(value)) {
1293
+ return value
1294
+ .filter(function (v) {
1295
+ return v != null && v !== "";
1296
+ })
1297
+ .map(String)
1298
+ .join(separator);
1299
+ }
1300
+ return String(value);
1301
+ };
1302
+
1303
+ CT.parseMultiSelectValue = function (value, sep) {
1304
+ const str = CT.normalizeMultiSelectValue(value, sep);
1305
+ if (!str) {
1306
+ return [];
1307
+ }
1308
+ return str.split(sep || MULTI_SELECT_SEP).filter(Boolean);
1309
+ };
1310
+
1311
+ (function installMultiSelectValHooks() {
1312
+ const prev = $.valHooks.hidden || {};
1313
+ $.valHooks.hidden = {
1314
+ get: function (elem) {
1315
+ if (elem && elem.classList && elem.classList.contains(MULTI_SELECT_VALUE_CLASS)) {
1316
+ return elem.value;
1317
+ }
1318
+ return prev.get ? prev.get(elem) : undefined;
1319
+ },
1320
+ set: function (elem, value) {
1321
+ if (elem && elem.classList && elem.classList.contains(MULTI_SELECT_VALUE_CLASS)) {
1322
+ const sep = $(elem).data("kgridMultiSep") || MULTI_SELECT_SEP;
1323
+ elem.value = CT.normalizeMultiSelectValue(value, sep);
1324
+ $(elem).triggerHandler("kgrid:multiselect:set");
1325
+ return true;
1326
+ }
1327
+ return prev.set ? prev.set(elem, value) : undefined;
1328
+ },
1329
+ };
1330
+ })();
1331
+
1332
+ function assertMultiSelectOptions(config, mode) {
1333
+ if (!Array.isArray(config.options)) {
1334
+ throw new Error(
1335
+ "multi_select requires an options array (" +
1336
+ mode +
1337
+ "): " +
1338
+ JSON.stringify(config, null, 2)
1339
+ );
1340
+ }
1341
+ config.options.forEach(function (opt) {
1342
+ if (!opt || typeof opt.label !== "string" || typeof opt.value !== "string") {
1343
+ throw new Error(
1344
+ "multi_select options need string label and value: " +
1345
+ JSON.stringify(config, null, 2)
1346
+ );
1347
+ }
1348
+ });
1349
+ }
1350
+
1351
+ function multiSelectEmptyLabel(config) {
1352
+ if (config.placeholder != null && config.placeholder !== "") {
1353
+ return String(config.placeholder);
1354
+ }
1355
+ return "All";
1356
+ }
1357
+
1358
+ function multiSelectSummary(selected, options, emptyLabel) {
1359
+ if (!selected.length) {
1360
+ return emptyLabel;
1361
+ }
1362
+ if (selected.length === 1) {
1363
+ const match = options.find(function (opt) {
1364
+ return opt.value === selected[0];
1365
+ });
1366
+ return match ? match.label : selected[0];
1367
+ }
1368
+ return selected.length + " selected";
1369
+ }
1370
+
1371
+ function buildMultiSelectUi($input, config, mode) {
1372
+ const sep = config.separator || MULTI_SELECT_SEP;
1373
+ const options = config.options || [];
1374
+ const emptyLabel = multiSelectEmptyLabel(config);
1375
+ const compact = mode === "filter";
1376
+
1377
+ $input.data("kgridMultiSep", sep);
1378
+ $input.addClass(MULTI_SELECT_VALUE_CLASS);
1379
+
1380
+ const $root = $("<div>")
1381
+ .addClass("kgrid-multi-select")
1382
+ .attr("data-mode", mode);
1383
+ const $panel = $("<div>").addClass("kgrid-multi-select-panel");
1384
+ let $toggle = null;
1385
+
1386
+ if (compact) {
1387
+ $toggle = $("<button>")
1388
+ .attr({ type: "button", "aria-expanded": "false" })
1389
+ .addClass("kgrid-multi-select-toggle form-select form-select-sm");
1390
+ $panel.attr("hidden", "hidden");
1391
+ $root.append($toggle, $panel);
1392
+ } else {
1393
+ $root.addClass("kgrid-multi-select-open");
1394
+ $root.append($panel);
1395
+ }
1396
+
1397
+ options.forEach(function (opt, index) {
1398
+ const uid = "kgrid_ms_" + CT.uuid() + "_" + index;
1399
+ const $label = $("<label>")
1400
+ .addClass("kgrid-multi-select-option")
1401
+ .attr("for", uid);
1402
+ $("<input>")
1403
+ .attr({
1404
+ type: "checkbox",
1405
+ id: uid,
1406
+ value: opt.value,
1407
+ class: "kgrid-multi-select-check",
1408
+ })
1409
+ .appendTo($label);
1410
+ $("<span>").addClass("kgrid-multi-select-label").text(opt.label).appendTo($label);
1411
+ $panel.append($label);
1412
+ });
1413
+
1414
+ $input.before($root);
1415
+ $root.append($input);
1416
+
1417
+ function selectedValues() {
1418
+ return CT.parseMultiSelectValue($input[0].value, sep);
1419
+ }
1420
+
1421
+ function syncCheckboxesFromInput() {
1422
+ const selected = selectedValues();
1423
+ $panel.find("input[type='checkbox']").each(function () {
1424
+ this.checked = selected.indexOf(this.value) !== -1;
1425
+ });
1426
+ if ($toggle) {
1427
+ $toggle.text(multiSelectSummary(selected, options, emptyLabel));
1428
+ }
1429
+ }
1430
+
1431
+ function syncInputFromCheckboxes(triggerChange) {
1432
+ const vals = [];
1433
+ $panel.find("input[type='checkbox']:checked").each(function () {
1434
+ vals.push(this.value);
1435
+ });
1436
+ const next = vals.join(sep);
1437
+ if ($input[0].value !== next) {
1438
+ $input[0].value = next;
1439
+ if (triggerChange) {
1440
+ $input.trigger("change");
1441
+ }
1442
+ }
1443
+ if ($toggle) {
1444
+ $toggle.text(multiSelectSummary(vals, options, emptyLabel));
1445
+ }
1446
+ }
1447
+
1448
+ function setOpen(open) {
1449
+ if (!$toggle) {
1450
+ return;
1451
+ }
1452
+ if (open) {
1453
+ // Leave the table/card overflow context so the list is fully visible.
1454
+ $panel.appendTo(document.body);
1455
+ $panel.addClass("kgrid-multi-select-panel-floating");
1456
+ $panel.removeAttr("hidden");
1457
+ $root.addClass("kgrid-multi-select-open");
1458
+ $toggle.attr("aria-expanded", "true");
1459
+ positionFilterPanel();
1460
+ } else {
1461
+ $panel.attr("hidden", "hidden");
1462
+ $root.removeClass("kgrid-multi-select-open");
1463
+ $toggle.attr("aria-expanded", "false");
1464
+ clearFilterPanelPosition();
1465
+ $panel.removeClass("kgrid-multi-select-panel-floating");
1466
+ $panel.insertAfter($toggle);
1467
+ }
1468
+ }
1469
+
1470
+ function positionFilterPanel() {
1471
+ if (!$toggle) {
1472
+ return;
1473
+ }
1474
+ const rect = $toggle[0].getBoundingClientRect();
1475
+ const width = Math.max(rect.width, 12 * 16);
1476
+ let left = rect.left;
1477
+ const maxLeft = window.innerWidth - width - 8;
1478
+ if (left > maxLeft) {
1479
+ left = Math.max(8, maxLeft);
1480
+ }
1481
+ let top = rect.bottom + 2;
1482
+ const approxHeight = Math.min(14 * 16, options.length * 28 + 16);
1483
+ if (top + approxHeight > window.innerHeight - 8 && rect.top > approxHeight + 8) {
1484
+ top = rect.top - approxHeight - 2;
1485
+ }
1486
+ $panel.css({
1487
+ position: "fixed",
1488
+ top: top + "px",
1489
+ left: left + "px",
1490
+ width: width + "px",
1491
+ minWidth: width + "px",
1492
+ maxWidth: "min(18rem, calc(100vw - 16px))",
1493
+ zIndex: 1080,
1494
+ });
1495
+ }
1496
+
1497
+ function clearFilterPanelPosition() {
1498
+ $panel.css({
1499
+ position: "",
1500
+ top: "",
1501
+ left: "",
1502
+ width: "",
1503
+ minWidth: "",
1504
+ maxWidth: "",
1505
+ zIndex: "",
1506
+ });
1507
+ }
1508
+
1509
+ const ns = ".kgridMultiSelect_" + CT.uuid();
1510
+
1511
+ $panel.on("change", "input[type='checkbox']", function () {
1512
+ syncInputFromCheckboxes(true);
1513
+ });
1514
+
1515
+ $input.on("kgrid:multiselect:set", function () {
1516
+ syncCheckboxesFromInput();
1517
+ });
1518
+
1519
+ if ($toggle) {
1520
+ $toggle.on("click", function (e) {
1521
+ e.preventDefault();
1522
+ e.stopPropagation();
1523
+ setOpen(!$root.hasClass("kgrid-multi-select-open"));
1524
+ });
1525
+ $(document).on("mousedown" + ns, function (e) {
1526
+ if (!$root.hasClass("kgrid-multi-select-open")) {
1527
+ return;
1528
+ }
1529
+ if ($(e.target).closest($root).length || $(e.target).closest($panel).length) {
1530
+ return;
1531
+ }
1532
+ setOpen(false);
1533
+ });
1534
+ $(window).on("resize" + ns + " scroll" + ns, function () {
1535
+ if ($root.hasClass("kgrid-multi-select-open")) {
1536
+ positionFilterPanel();
1537
+ }
1538
+ });
1539
+ }
1540
+
1541
+ const formBind = function () {
1542
+ const formEl = $input.prop("form") || ($input[0] && $input[0].form);
1543
+ if (!formEl) {
1544
+ return;
1545
+ }
1546
+ $(formEl).off("reset" + ns).on("reset" + ns, function () {
1547
+ setTimeout(syncCheckboxesFromInput, 0);
1548
+ });
1549
+ };
1550
+ formBind();
1551
+ setTimeout(formBind, 0);
1552
+
1553
+ syncCheckboxesFromInput();
1554
+ return $root;
1555
+ }
1556
+
936
1557
  CT.registerFieldType("multi_select", {
1558
+ filterEvents: "change",
1559
+ filterDebounceMs: 0,
1560
+ validate(config, mode) {
1561
+ assertMultiSelectOptions(config, mode);
1562
+ },
937
1563
  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
- });
1564
+ const $input = $("<input type='hidden'>").addClass(MULTI_SELECT_VALUE_CLASS);
1565
+ if (config.separator) {
1566
+ $input.data("kgridMultiSep", config.separator);
943
1567
  }
944
1568
  return { $input, skipValueAttr: true };
945
1569
  },
1570
+ mount(ctx) {
1571
+ buildMultiSelectUi(ctx.$input, ctx.config || {}, ctx.mode);
1572
+ if (ctx.mode === "update" && ctx.item && ctx.col && ctx.col.name) {
1573
+ const raw = ctx.item.attributes ? ctx.item.attributes[ctx.col.name] : null;
1574
+ if (raw != null && raw !== "") {
1575
+ ctx.$input.val(raw);
1576
+ }
1577
+ }
1578
+ },
946
1579
  });
947
1580
 
948
1581
  CT.registerFieldType("date_range", {
@@ -1384,16 +2017,25 @@
1384
2017
  }
1385
2018
  }
1386
2019
 
1387
- input.attr("data-operator", filter.operator);
2020
+ const operator =
2021
+ filter.operator ||
2022
+ (filter.type === "multi_select" ? "><" : undefined);
2023
+ if (operator != null) {
2024
+ input.attr("data-operator", operator);
2025
+ }
1388
2026
  input.attr("form", filterFormId);
1389
2027
  input.attr("name", col.name);
1390
2028
 
1391
2029
  const defVal = CT.filterDefaultValue(filter.default);
1392
2030
  if (defVal != null && defVal !== "" && !input.val()) {
1393
- input.val(String(defVal));
1394
- input.attr("data-default", String(defVal));
2031
+ const normalized =
2032
+ filter.type === "multi_select"
2033
+ ? CT.normalizeMultiSelectValue(defVal, filter.separator)
2034
+ : String(defVal);
2035
+ input.val(normalized);
2036
+ input.attr("data-default", normalized);
1395
2037
  if (input[0]) {
1396
- input[0].defaultValue = String(defVal);
2038
+ input[0].defaultValue = normalized;
1397
2039
  }
1398
2040
  }
1399
2041
 
@@ -1657,39 +2299,7 @@
1657
2299
 
1658
2300
  if (CT.hasActionColumn(options)) {
1659
2301
  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
- }
2302
+ CT.renderRowActions(buttonColumn, options, dataRowFormId);
1693
2303
  }
1694
2304
  if (editForm) {
1695
2305
  CT.anchorRowForm(editForm, dataRow);
@@ -1781,7 +2391,7 @@
1781
2391
  grid.instance.newItem(data).then(()=>{
1782
2392
  event.target.reset();
1783
2393
  if(typeof options.onNewItemCreated=="function") {
1784
- options.onNewItemCreated(data);
2394
+ options.onNewItemCreated(data, event.target);
1785
2395
  }
1786
2396
  }).catch(CT.onError);
1787
2397
  });
@@ -1857,10 +2467,14 @@
1857
2467
  ? insertConfig.default.value
1858
2468
  : insertConfig.default;
1859
2469
  if (insertType === "checkbox") {
1860
- input.prop("checked", CT.isFlagOn(rawDefault));
2470
+ const on = CT.isFlagOn(rawDefault);
2471
+ input.prop("checked", on).prop("defaultChecked", on);
1861
2472
  } else if(insertConfig.default != null && insertConfig.default !== "" && !input.val()) {
1862
2473
  if(String(rawDefault).trim()) {
1863
2474
  input.val(rawDefault).trigger("change");
2475
+ if (input[0] && "defaultValue" in input[0]) {
2476
+ input[0].defaultValue = input[0].value;
2477
+ }
1864
2478
  }
1865
2479
  }
1866
2480
 
@@ -2013,8 +2627,12 @@
2013
2627
  });
2014
2628
  }
2015
2629
 
2016
- if(options.features.clone) {
2017
- view.el.find("button.clone-item").off("click").on("click",(event)=>{
2630
+ const ra = CT.resolveRowActions(options);
2631
+ const hasClone = ra.menuItems.some((it) => it.action === "clone");
2632
+ const hasDelete = ra.menuItems.some((it) => it.action === "delete");
2633
+
2634
+ if (hasClone) {
2635
+ view.el.find(".clone-item").off("click").on("click", (event) => {
2018
2636
  event.preventDefault();
2019
2637
  if (typeof options.onClone === "function") {
2020
2638
  options.onClone(item, view, event);
@@ -2022,8 +2640,8 @@
2022
2640
  });
2023
2641
  }
2024
2642
 
2025
- if(options.features.delete) {
2026
- view.el.find("button.delete-item").off("click").on("click",(event)=>{
2643
+ if (hasDelete) {
2644
+ view.el.find(".delete-item").off("click").on("click", (event) => {
2027
2645
  event.preventDefault();
2028
2646
  view.el.addClass("confirm-delete");
2029
2647
  const clearConfirmState = () => view.el.removeClass("confirm-delete");
@@ -2037,6 +2655,27 @@
2037
2655
  });
2038
2656
  }
2039
2657
 
2658
+ const customById = new Map();
2659
+ ra.menuItems.forEach((it) => {
2660
+ if (it.id && typeof it.callback === "function") {
2661
+ customById.set(it.id, it.callback);
2662
+ }
2663
+ });
2664
+ if (customById.size) {
2665
+ view.el
2666
+ .find("[data-kgrid-action]")
2667
+ .off("click.kgridAction")
2668
+ .on("click.kgridAction", (event) => {
2669
+ const id = event.currentTarget.getAttribute("data-kgrid-action");
2670
+ const cb = customById.get(id);
2671
+ if (!cb) {
2672
+ return;
2673
+ }
2674
+ event.preventDefault();
2675
+ cb(event, item, view);
2676
+ });
2677
+ }
2678
+
2040
2679
  if (typeof options.onRowFields === "function") {
2041
2680
  options.onRowFields(item, view, table);
2042
2681
  }
@@ -2311,11 +2950,15 @@
2311
2950
  return result;
2312
2951
  };
2313
2952
 
2953
+ CT.columnDefaultUserHidden = function (col) {
2954
+ return !!(col && col.defaultHidden && !col.locked && !col.hidden);
2955
+ };
2956
+
2314
2957
  CT.mergeLayoutIntoColumns = function (columns, layout) {
2315
2958
  const list = (columns || []).slice();
2316
2959
  list.forEach(function (col) {
2317
2960
  if (col && !col.hidden) {
2318
- col.userHidden = false;
2961
+ col.userHidden = CT.columnDefaultUserHidden(col);
2319
2962
  }
2320
2963
  });
2321
2964
  const visible = CT.chooserColumns(list);
@@ -2717,6 +3360,14 @@
2717
3360
  }
2718
3361
  options.onClone = fn;
2719
3362
  }
3363
+ CT.resolveRowActions(options, handlers);
3364
+ {
3365
+ const ra = options._resolvedRowActions;
3366
+ CT.getTableInteractionHost($host).attr(
3367
+ "data-has-row-menu",
3368
+ ra && ra.menuItems && ra.menuItems.length ? "true" : "false"
3369
+ );
3370
+ }
2720
3371
  options.columns.forEach((col) => {
2721
3372
  ["insert", "update", "display"].forEach((mode) => {
2722
3373
  const events = col[mode].events;