@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.
@@ -81,7 +81,58 @@ KGrid.configure({
81
81
 
82
82
  ## Native HTML & built-ins
83
83
 
84
- See previous sections in this file for `select`, `multi_select`, `date_range`. Native types need no registration.
84
+ Native HTML types (`text`, `select`, …) and DOM built-ins (`multi_select`, `date_range`) need no `customInputTypes` registration.
85
+
86
+ ### `multi_select` — checkbox list (IN filter)
87
+
88
+ Friendly multi-value control: a compact toggle in the filter row opens a panel of checkboxes (insert/update show the list inline). Values are stored as a **semicolon-joined** string on a hidden input.
89
+
90
+ | Concern | Default |
91
+ |---------|---------|
92
+ | Operator | `><` (dbAPI IN) when `filter.operator` omitted |
93
+ | Value encoding | `a;b;c` (`filter.separator` overrides, default `";"`) |
94
+ | Empty | no filter (same as clearing all checkboxes) |
95
+ | Label | `filter.placeholder` or `"All"` when nothing selected |
96
+
97
+ ```javascript
98
+ {
99
+ name: "state",
100
+ filter: {
101
+ type: "multi_select",
102
+ // operator defaults to "><"
103
+ options: [
104
+ { label: "Draft", value: "DRAFT" },
105
+ { label: "Picked", value: "PICKED" },
106
+ { label: "Shipped", value: "SHIPPED" },
107
+ ],
108
+ default: ["DRAFT", "PICKED"], // or "DRAFT;PICKED"
109
+ },
110
+ }
111
+ ```
112
+
113
+ Produces filter expressions like `state><DRAFT;PICKED`.
114
+
115
+ ### `checkbox` — boolean flag toggle
116
+
117
+ `filter` / `insert` / `update` `{ type: "checkbox" }` is always a **flag**, not a multi-value checkbox group.
118
+
119
+ - UI: Bootstrap `form-check form-switch` (`role="switch"`).
120
+ - Serialized value is always `"1"` or `"0"`. Unchecked still appears in the payload (unlike `FormData`).
121
+ - On if the record value is `true`, `1`, or `"1"`; everything else is off.
122
+ - Do not set `update.value` from the field (`value: "{{flag}}"`). KGrid sets `checked` from `item.attributes` after render.
123
+
124
+ ```javascript
125
+ {
126
+ name: "lot_tracked",
127
+ display: { template: "{{#if (equals lot_tracked '1')}}Da{{else}}—{{/if}}" },
128
+ insert: { type: "checkbox", default: "0" },
129
+ update: { type: "checkbox" },
130
+ }
131
+ ```
132
+
133
+ `KGrid.isFlagOn(v)` is the same on/off rule used for `checked` and insert defaults.
134
+
135
+ Filter checkboxes are not coerced to `"0"` when empty — filter submit is separate and unchecked means “no filter”.
85
136
 
86
137
  ## Direct API
87
138
 
@@ -16,6 +16,7 @@ After `npm install`, the template is inside the built bundle (`dist/kgrid.js`).
16
16
 
17
17
  ```
18
18
  .custom-table-shell ← class added on host if missing
19
+ .kgrid-column-chooser ← when features.columnChooser
19
20
  table.custom-table
20
21
  colgroup.kgrid-colgroup ← injected at init (data cols + optional row-actions col)
21
22
  thead.thead-labels ← one <th> template; cloned per column in labels.js
@@ -6,7 +6,6 @@ KGrid.configure({
6
6
  log: typeof klog === "function" ? klog : console.log.bind(console),
7
7
  onError: modal_error,
8
8
  confirm: modal_confirm,
9
- serializeForm: serializeFormData2,
10
9
  customInputTypes: {
11
10
  select2: KGrid.select2(select2wrapper),
12
11
  autosuggest: KGrid.autosuggest(function ($input, options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logimaxx/kgrid",
3
- "version": "0.3.1",
3
+ "version": "0.5.0",
4
4
  "description": "KGrid — declarative data table for KViews (filter, sort, paging, inline CRUD). Proprietary — Logimaxx System SRL.",
5
5
  "main": "dist/kgrid.js",
6
6
  "homepage": "https://logimaxx.ro",
package/src/cells.js CHANGED
@@ -1,4 +1,17 @@
1
1
  (function (CT) {
2
+ /**
3
+ * Bootstrap switch wrapper around a checkbox used as a boolean flag.
4
+ * @param {JQuery} $input
5
+ * @returns {JQuery} wrapper
6
+ */
7
+ CT.wrapFlagSwitch = function ($input) {
8
+ $input
9
+ .attr({ type: "checkbox", role: "switch", value: "1" })
10
+ .removeClass("form-control form-input form-control-sm")
11
+ .addClass("form-check-input");
12
+ return $("<div class='form-check form-switch kgrid-flag-switch mb-0'>").append($input);
13
+ };
14
+
2
15
  /**
3
16
  * Setup data cell
4
17
  * @param {Object} col
@@ -68,6 +81,10 @@
68
81
  $("<div>").addClass("cell-input").append(tpl).appendTo($cell);
69
82
  return $cell;
70
83
  }
84
+ case "checkbox":
85
+ input = $("<input autocomplete='off' type='checkbox' class='form-check-input'/>");
86
+ skipValueAttr = true;
87
+ break;
71
88
  default:
72
89
  if(CT.isValidInputType(updateType)) {
73
90
  input = $(`<input autocomplete='off' type='${updateType}' class='form-input form-control form-control-sm'/>`);
@@ -107,7 +124,8 @@
107
124
  if(!updateConfig.disabled && !updateConfig.readonly)
108
125
  input.attr("onchange","$(this).parents('tr').addClass('editing')");
109
126
 
110
- $("<div>").addClass("cell-input").append(input).appendTo($cell);
127
+ const $control = updateType === "checkbox" ? CT.wrapFlagSwitch(input) : input;
128
+ $("<div>").addClass("cell-input").append($control).appendTo($cell);
111
129
  return $cell;
112
130
  };
113
131
  })(window.KGrid);
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Column chooser: checkbox visibility + HTML5 drag reorder.
3
+ */
4
+ (function (CT) {
5
+ function layoutFromPanel($panel) {
6
+ const columns = [];
7
+ $panel.find(".kgrid-column-chooser-list li[data-name]").each(function () {
8
+ const name = this.getAttribute("data-name");
9
+ const checked = $(this).find("input[type='checkbox']").prop("checked");
10
+ columns.push({ name: name, hidden: !checked });
11
+ });
12
+ return { v: CT.PREFERENCES_VERSION, columns: columns };
13
+ }
14
+
15
+ function visibleCount(layout) {
16
+ return layout.columns.filter(function (c) {
17
+ return !c.hidden;
18
+ }).length;
19
+ }
20
+
21
+ CT.renderColumnChooserPanel = function ($panel, options, api) {
22
+ $panel.empty();
23
+ const $list = $("<ul>").addClass("kgrid-column-chooser-list").appendTo($panel);
24
+ CT.chooserColumns(options.columns).forEach(function (col) {
25
+ const $li = $("<li>")
26
+ .attr("draggable", "true")
27
+ .attr("data-name", col.name)
28
+ .appendTo($list);
29
+ $("<span>")
30
+ .addClass("kgrid-column-chooser-handle")
31
+ .attr("aria-hidden", "true")
32
+ .text("⋮⋮")
33
+ .appendTo($li);
34
+ const $label = $("<label>").appendTo($li);
35
+ const $cb = $("<input>")
36
+ .attr("type", "checkbox")
37
+ .prop("checked", !col.userHidden)
38
+ .appendTo($label);
39
+ if (col.locked) {
40
+ $cb.prop("disabled", true).attr("title", "This column cannot be hidden");
41
+ }
42
+ $label.append(document.createTextNode(" " + (col.label || col.name)));
43
+ });
44
+ $("<button>")
45
+ .attr("type", "button")
46
+ .addClass("btn btn-sm btn-outline-secondary kgrid-column-chooser-reset")
47
+ .text(options.columnChooserResetLabel || "Reset columns")
48
+ .appendTo($panel);
49
+
50
+ $panel
51
+ .off("change.kgridChooser")
52
+ .on("change.kgridChooser", "input[type='checkbox']", function () {
53
+ const layout = layoutFromPanel($panel);
54
+ if (visibleCount(layout) < 1) {
55
+ this.checked = true;
56
+ return;
57
+ }
58
+ api.setLayout(layout);
59
+ });
60
+
61
+ $panel
62
+ .off("click.kgridChooserReset")
63
+ .on("click.kgridChooserReset", ".kgrid-column-chooser-reset", function () {
64
+ api.resetLayout();
65
+ });
66
+
67
+ let dragEl = null;
68
+ $list.off(".kgridChooserDrag");
69
+ $list.on("dragstart.kgridChooserDrag", "li", function (e) {
70
+ dragEl = this;
71
+ $(this).addClass("kgrid-column-chooser-dragging");
72
+ if (e.originalEvent && e.originalEvent.dataTransfer) {
73
+ e.originalEvent.dataTransfer.effectAllowed = "move";
74
+ e.originalEvent.dataTransfer.setData("text/plain", this.getAttribute("data-name"));
75
+ }
76
+ });
77
+ $list.on("dragend.kgridChooserDrag", "li", function () {
78
+ $(this).removeClass("kgrid-column-chooser-dragging");
79
+ dragEl = null;
80
+ });
81
+ $list.on("dragover.kgridChooserDrag", "li", function (e) {
82
+ e.preventDefault();
83
+ if (!dragEl || dragEl === this) {
84
+ return;
85
+ }
86
+ const rect = this.getBoundingClientRect();
87
+ const mid = rect.top + rect.height / 2;
88
+ const clientY = e.originalEvent ? e.originalEvent.clientY : 0;
89
+ if (clientY < mid) {
90
+ this.parentNode.insertBefore(dragEl, this);
91
+ } else {
92
+ this.parentNode.insertBefore(dragEl, this.nextSibling);
93
+ }
94
+ });
95
+ $list.on("drop.kgridChooserDrag", "li", function (e) {
96
+ e.preventDefault();
97
+ api.setLayout(layoutFromPanel($panel));
98
+ });
99
+ };
100
+
101
+ CT.setupColumnChooser = function ($host, options, api) {
102
+ if (!options.features || !options.features.columnChooser) {
103
+ return;
104
+ }
105
+ const $shell = CT.getTableInteractionHost($host);
106
+ $shell.find(".kgrid-column-chooser").remove();
107
+ const label = options.columnChooserLabel || "Columns";
108
+ const $wrap = $("<div>").addClass("kgrid-column-chooser");
109
+ const $btn = $("<button>")
110
+ .attr("type", "button")
111
+ .addClass("kgrid-column-chooser-toggle btn btn-sm btn-outline-secondary")
112
+ .attr("title", label)
113
+ .attr("aria-expanded", "false")
114
+ .attr("aria-haspopup", "true")
115
+ .html(
116
+ '<i class="fas fa-table-columns" aria-hidden="true"></i>' +
117
+ '<span class="kgrid-column-chooser-toggle-label"> ' +
118
+ $("<div>").text(label).html() +
119
+ "</span>"
120
+ );
121
+ const $panel = $("<div>")
122
+ .addClass("kgrid-column-chooser-panel")
123
+ .attr("hidden", "hidden");
124
+ $wrap.append($btn, $panel);
125
+ $shell.prepend($wrap);
126
+ CT.renderColumnChooserPanel($panel, options, api);
127
+
128
+ function close() {
129
+ $panel.attr("hidden", "hidden");
130
+ $btn.attr("aria-expanded", "false");
131
+ }
132
+
133
+ $btn.on("click", function (e) {
134
+ e.stopPropagation();
135
+ const open = !$panel.attr("hidden");
136
+ if (open) {
137
+ close();
138
+ } else {
139
+ $panel.removeAttr("hidden");
140
+ $btn.attr("aria-expanded", "true");
141
+ }
142
+ });
143
+
144
+ const ns = "kgridChooser" + CT.uuid();
145
+ $(document).on("pointerdown." + ns, function (e) {
146
+ if (!document.body.contains($wrap[0])) {
147
+ $(document).off("pointerdown." + ns);
148
+ return;
149
+ }
150
+ if (!$wrap[0].contains(e.target)) {
151
+ close();
152
+ }
153
+ });
154
+ };
155
+ })(window.KGrid);
package/src/configure.js CHANGED
@@ -2,6 +2,69 @@
2
2
  * Host-app integration: call KGrid.configure({ ... }) before mounting tables.
3
3
  */
4
4
  (function (CT) {
5
+ /**
6
+ * Flag is on when the API/form value is true, 1, or "1".
7
+ * @param {*} v
8
+ * @returns {boolean}
9
+ */
10
+ CT.isFlagOn = function (v) {
11
+ return v === true || v === 1 || v === "1";
12
+ };
13
+
14
+ /**
15
+ * Walk form.elements (includes fields associated via form="id").
16
+ * Checkboxes always emit "1" or "0" — FormData omits unchecked boxes.
17
+ * @param {HTMLFormElement} form
18
+ * @returns {Record<string, *>}
19
+ */
20
+ function defaultSerializeForm(form) {
21
+ const out = {};
22
+ const els = form && form.elements;
23
+ if (!els) {
24
+ return out;
25
+ }
26
+ for (let i = 0; i < els.length; i++) {
27
+ const el = els[i];
28
+ const name = el.name;
29
+ if (!name || el.disabled) {
30
+ continue;
31
+ }
32
+ const type = el.type;
33
+ if (type === "submit" || type === "button" || type === "reset" || type === "file") {
34
+ continue;
35
+ }
36
+ if (type === "checkbox") {
37
+ out[name] = el.checked ? "1" : "0";
38
+ continue;
39
+ }
40
+ if (type === "radio") {
41
+ if (!el.checked) {
42
+ continue;
43
+ }
44
+ out[name] = el.value;
45
+ continue;
46
+ }
47
+ if (el.tagName === "SELECT" && el.multiple) {
48
+ out[name] = Array.from(el.selectedOptions).map(function (o) {
49
+ return o.value;
50
+ });
51
+ continue;
52
+ }
53
+ const value = el.value;
54
+ if (Object.prototype.hasOwnProperty.call(out, name)) {
55
+ if (!Array.isArray(out[name])) {
56
+ out[name] = [out[name]];
57
+ }
58
+ out[name].push(value);
59
+ } else {
60
+ out[name] = value;
61
+ }
62
+ }
63
+ return out;
64
+ }
65
+
66
+ CT.serializeFormDefault = defaultSerializeForm;
67
+
5
68
  const defaultConfig = {
6
69
  log: function () {},
7
70
  onError: function (err) {
@@ -16,21 +79,7 @@
16
79
  },
17
80
  /** @type {((context: object, onConfirm: Function, onCancel?: Function) => void)|null} */
18
81
  deleteConfirm: null,
19
- serializeForm: function (form, columns) {
20
- const fd = new FormData(form);
21
- const out = {};
22
- for (const [key, value] of fd.entries()) {
23
- if (Object.prototype.hasOwnProperty.call(out, key)) {
24
- if (!Array.isArray(out[key])) {
25
- out[key] = [out[key]];
26
- }
27
- out[key].push(value);
28
- } else {
29
- out[key] = value;
30
- }
31
- }
32
- return out;
33
- },
82
+ serializeForm: defaultSerializeForm,
34
83
  /** @type {Record<string, Function|object>|null} name → wrapper fn or field type plugin */
35
84
  customInputTypes: null,
36
85
  /** @deprecated use customInputTypes */
@@ -39,6 +88,8 @@
39
88
  kviews: null,
40
89
  /** Default delay (ms) before filter submit; 0 = immediate. Applies to the resolved filter-submit event. */
41
90
  filterDebounceMs: 300,
91
+ /** { get(key), set(key, value|null) } — null uses localStorage */
92
+ preferencesStorage: null,
42
93
  };
43
94
 
44
95
  CT._config = Object.assign({}, defaultConfig);
package/src/constants.js CHANGED
@@ -12,9 +12,23 @@
12
12
  "paging": false,
13
13
  "create": false,
14
14
  "update": false,
15
+ /** @deprecated use rowActions items [{ action: "delete" }] */
15
16
  "delete": false,
16
- "clone": false
17
+ /** @deprecated use rowActions items [{ action: "clone" }] */
18
+ "clone": false,
19
+ "columnChooser": false
17
20
  },
21
+ /**
22
+ * Row action chrome: { display: "buttons"|"dropdown", items: [...] }.
23
+ * Built-ins: delete, clone. Save/cancel come from features.update.
24
+ */
25
+ rowActions: null,
26
+ /** Persist key for layout (and filters). Required for localStorage. */
27
+ storageKey: null,
28
+ /** Extra suffix for saved filters only (e.g. company id). Layout ignores this. */
29
+ filterStorageScope: null,
30
+ columnChooserLabel: "Columns",
31
+ columnChooserResetLabel: "Reset columns",
18
32
  "defaultInteraction": "view",
19
33
  "insertFormRow": {
20
34
  "position": "top"
@@ -41,6 +55,15 @@
41
55
  label: null,
42
56
  name: null,
43
57
  hidden: false,
58
+ /** When true, column chooser cannot hide this column (still reorderable). */
59
+ locked: false,
60
+ /**
61
+ * Schema: start user-hidden (collapsed) until the user shows it in the chooser.
62
+ * Unlike `hidden`, the column stays in the chooser / DOM. Ignored when `locked`.
63
+ */
64
+ defaultHidden: false,
65
+ /** Runtime: user hid this column via chooser. Not a schema flag. */
66
+ userHidden: false,
44
67
  /** CSS class(es) on header/filter/data/insert cells (alias: columnClass) */
45
68
  class: null,
46
69
  columnClass: null,
package/src/data-body.js CHANGED
@@ -9,8 +9,37 @@
9
9
  return td;
10
10
  };
11
11
 
12
- CT.setupDataBody = function (dataBody, options, labelsRow, filterForm, pagingFooter, noDataTbody) {
12
+ /**
13
+ * Fill a data <tr> with cells + optional row-actions (KViews item template).
14
+ * @param {JQuery} dataRow
15
+ * @param {Object} options
16
+ * @returns {JQuery} dataRow
17
+ */
18
+ CT.fillDataRow = function (dataRow, options) {
13
19
  const columns = [...options.columns];
20
+ const dataRowFormId = "data_row_form_"+CT.uuid()+"_{{this.id}}";
21
+ const editForm = options.features && options.features.update
22
+ ? $("<form class='edit-form table-row-form'>").attr("id", dataRowFormId)
23
+ : null;
24
+
25
+ columns.forEach(col => {
26
+ const dataCell = CT.setupCell(col,editForm);
27
+ if(!col.hidden) {
28
+ dataCell.appendTo(dataRow);
29
+ }
30
+ });
31
+
32
+ if (CT.hasActionColumn(options)) {
33
+ const buttonColumn = $("<td>").addClass("kgrid-row-actions").appendTo(dataRow);
34
+ CT.renderRowActions(buttonColumn, options, dataRowFormId);
35
+ }
36
+ if (editForm) {
37
+ CT.anchorRowForm(editForm, dataRow);
38
+ }
39
+ return dataRow;
40
+ };
41
+
42
+ CT.setupDataBody = function (dataBody, options, labelsRow, filterForm, pagingFooter, noDataTbody) {
14
43
  const dataRow = $("<tr>").appendTo(dataBody);
15
44
  if(options.dataRowAttrs && typeof options.dataRowAttrs!=="object") {
16
45
  throw new Error("options.dataRowAttrs must be an object");
@@ -39,58 +68,7 @@
39
68
  }
40
69
  }
41
70
 
42
- const dataRowFormId = "data_row_form_"+CT.uuid()+"_{{this.id}}";
43
- const editForm = options.features.update
44
- ? $("<form class='edit-form table-row-form'>").attr("id", dataRowFormId)
45
- : null;
46
-
47
- columns.forEach(col => {
48
- const dataCell = CT.setupCell(col,editForm);
49
- if(!col.hidden) {
50
- dataCell.appendTo(dataRow);
51
- }
52
- });
53
-
54
- if (CT.hasActionColumn(options)) {
55
- const buttonColumn = $("<td>").addClass("kgrid-row-actions").appendTo(dataRow);
56
- if(options.features.clone) {
57
- $("<div>").addClass("btn-group clone-item-grp").appendTo(buttonColumn).append(
58
- $("<button>").addClass("btn btn-sm btn-outline-secondary clone-item")
59
- .attr("type","button")
60
- .attr("title","Clone item")
61
- .append("<i class='fa-regular fa-copy'></i>"));
62
- }
63
- if(options.features.delete) {
64
- $("<div>").addClass("btn-group delete-item-grp").appendTo(buttonColumn).append(
65
- $("<button>").addClass("btn btn-sm btn-danger delete-item")
66
- .attr("type","button")
67
- .attr("title","Delete item")
68
- .append("<i class='fas fa-trash'></i>"));
69
- }
70
-
71
- if(options.features.update) {
72
- const grp = $("<div>").addClass("btn-group edit-item-grp").appendTo(buttonColumn);
73
- $("<button>").addClass("btn btn-sm btn-success save-item")
74
- .attr("type","submit")
75
- .attr("name","save")
76
- .attr("title","Save item")
77
- .attr("form",dataRowFormId)
78
- .html("<i class='fas fa-save'></i>")
79
- .appendTo(grp);
80
- $("<button>").addClass("btn btn-sm btn-secondary cancel-edit")
81
- .attr("type","button")
82
- .attr("name","cancel")
83
- .attr("title","Cancel edit")
84
- .attr("form",dataRowFormId)
85
- .attr("onclick","$(this).parents('[data-type=item]').data().instance.loadFromRemote()")
86
- .html("<i class='fas fa-undo'></i>")
87
- .appendTo(grp);
88
- }
89
- }
90
- if (editForm) {
91
- CT.anchorRowForm(editForm, dataRow);
92
- }
93
-
71
+ CT.fillDataRow(dataRow, options);
94
72
  return dataBody;
95
73
  };
96
74
 
package/src/dom.js CHANGED
@@ -30,36 +30,42 @@
30
30
  return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
31
31
  };
32
32
 
33
- /**
34
- * Whether the table needs a trailing row-actions column (header, filters, data rows, colspan).
35
- * @param {Object} options table options with features
36
- * @returns {boolean}
37
- */
38
- CT.hasActionColumn = function (options) {
39
- const f = options && options.features;
40
- if (!f) {
41
- return false;
42
- }
43
- return !!(f.delete || f.update || f.create || f.clone);
44
- };
45
-
46
33
  /**
47
34
  * Sync <colgroup> so row-actions width can collapse in view (table-layout: fixed).
48
35
  * @param {JQuery} $table
49
36
  * @param {number} dataColumnCount visible data columns (no row-actions)
50
37
  * @param {boolean} hasActions
38
+ * @param {Object} [options] table options (for action column width)
51
39
  */
52
- CT.syncActionColumnColgroup = function ($table, dataColumnCount, hasActions) {
40
+ CT.syncActionColumnColgroup = function ($table, dataColumnCount, hasActions, options, layoutColumns) {
53
41
  let $colgroup = $table.children("colgroup.kgrid-colgroup");
54
42
  if (!$colgroup.length) {
55
43
  $colgroup = $("<colgroup>").addClass("kgrid-colgroup").prependTo($table);
56
44
  }
57
45
  $colgroup.empty();
58
- for (let i = 0; i < dataColumnCount; i++) {
59
- $colgroup.append($("<col>"));
46
+ const named = Array.isArray(layoutColumns) ? layoutColumns : null;
47
+ if (named && named.length) {
48
+ named.forEach(function (col) {
49
+ const $col = $("<col>");
50
+ if (col && col.name) {
51
+ $col.attr("data-name", col.name);
52
+ }
53
+ if (col && col.userHidden) {
54
+ $col.addClass("kgrid-user-hidden");
55
+ }
56
+ $colgroup.append($col);
57
+ });
58
+ } else {
59
+ for (let i = 0; i < dataColumnCount; i++) {
60
+ $colgroup.append($("<col>"));
61
+ }
60
62
  }
61
63
  if (hasActions) {
62
- $colgroup.append($("<col>").addClass("kgrid-row-actions-col"));
64
+ $colgroup.append(
65
+ $("<col>")
66
+ .addClass("kgrid-row-actions-col")
67
+ .css("width", CT.actionColumnWidth(options))
68
+ );
63
69
  }
64
70
  };
65
71
 
@@ -118,6 +124,7 @@
118
124
  if (cls) {
119
125
  $el.addClass(cls);
120
126
  }
127
+ $el.toggleClass("kgrid-user-hidden", !!col.userHidden);
121
128
  return $el;
122
129
  };
123
130
  })(window.KGrid);
package/src/events.js CHANGED
@@ -64,6 +64,14 @@
64
64
  $(input).val(typeof val === "boolean" ? String(val) : val);
65
65
  });
66
66
 
67
+ view.el.find("input[type='checkbox']").each((index, input) => {
68
+ const col = colMap.get(input.name);
69
+ if (!col) {
70
+ return;
71
+ }
72
+ input.checked = CT.isFlagOn(item.attributes[col.name]);
73
+ });
74
+
67
75
  view.el.find("form.edit-form").off("submit").on("submit",(event)=>{
68
76
  const form = event.target;
69
77
  event.preventDefault();
@@ -78,8 +86,12 @@
78
86
  });
79
87
  }
80
88
 
81
- if(options.features.clone) {
82
- view.el.find("button.clone-item").off("click").on("click",(event)=>{
89
+ const ra = CT.resolveRowActions(options);
90
+ const hasClone = ra.menuItems.some((it) => it.action === "clone");
91
+ const hasDelete = ra.menuItems.some((it) => it.action === "delete");
92
+
93
+ if (hasClone) {
94
+ view.el.find(".clone-item").off("click").on("click", (event) => {
83
95
  event.preventDefault();
84
96
  if (typeof options.onClone === "function") {
85
97
  options.onClone(item, view, event);
@@ -87,8 +99,8 @@
87
99
  });
88
100
  }
89
101
 
90
- if(options.features.delete) {
91
- view.el.find("button.delete-item").off("click").on("click",(event)=>{
102
+ if (hasDelete) {
103
+ view.el.find(".delete-item").off("click").on("click", (event) => {
92
104
  event.preventDefault();
93
105
  view.el.addClass("confirm-delete");
94
106
  const clearConfirmState = () => view.el.removeClass("confirm-delete");
@@ -102,6 +114,27 @@
102
114
  });
103
115
  }
104
116
 
117
+ const customById = new Map();
118
+ ra.menuItems.forEach((it) => {
119
+ if (it.id && typeof it.callback === "function") {
120
+ customById.set(it.id, it.callback);
121
+ }
122
+ });
123
+ if (customById.size) {
124
+ view.el
125
+ .find("[data-kgrid-action]")
126
+ .off("click.kgridAction")
127
+ .on("click.kgridAction", (event) => {
128
+ const id = event.currentTarget.getAttribute("data-kgrid-action");
129
+ const cb = customById.get(id);
130
+ if (!cb) {
131
+ return;
132
+ }
133
+ event.preventDefault();
134
+ cb(event, item, view);
135
+ });
136
+ }
137
+
105
138
  if (typeof options.onRowFields === "function") {
106
139
  options.onRowFields(item, view, table);
107
140
  }