@gridnexa/angular 0.0.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/README.md +31 -0
- package/dist/index.cjs +711 -0
- package/dist/index.d.cts +93 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +693 -0
- package/package.json +37 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
21
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
22
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
23
|
+
if (decorator = decorators[i])
|
|
24
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
25
|
+
if (kind && result) __defProp(target, key, result);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var index_exports = {};
|
|
31
|
+
__export(index_exports, {
|
|
32
|
+
GridNexaAngularComponent: () => GridNexaAngularComponent
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
var import_core = require("@angular/core");
|
|
36
|
+
__reExport(index_exports, require("@gridnexa/core"), module.exports);
|
|
37
|
+
function rawValue(row, column) {
|
|
38
|
+
return column.valueGetter ? column.valueGetter(row) : row[column.field];
|
|
39
|
+
}
|
|
40
|
+
function evaluateFormula(row, columns, expression) {
|
|
41
|
+
const formula = expression.trim().slice(1);
|
|
42
|
+
if (!/^[\w\s.+\-*/()%]+$/.test(formula)) return expression;
|
|
43
|
+
const resolved = columns.reduce((current, column) => {
|
|
44
|
+
const value2 = Number(rawValue(row, column));
|
|
45
|
+
return current.replace(
|
|
46
|
+
new RegExp(`\\b${column.id}\\b|\\b${String(column.field)}\\b`, "g"),
|
|
47
|
+
Number.isFinite(value2) ? String(value2) : "0"
|
|
48
|
+
);
|
|
49
|
+
}, formula);
|
|
50
|
+
try {
|
|
51
|
+
return Function(`"use strict"; return (${resolved});`)();
|
|
52
|
+
} catch {
|
|
53
|
+
return expression;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function value(row, column, columns) {
|
|
57
|
+
const current = rawValue(row, column);
|
|
58
|
+
return typeof current === "string" && current.trim().startsWith("=") ? evaluateFormula(row, columns, current) : current;
|
|
59
|
+
}
|
|
60
|
+
function format(row, column, columns) {
|
|
61
|
+
const current = value(row, column, columns);
|
|
62
|
+
return column.valueFormatter ? column.valueFormatter(current) : String(current ?? "");
|
|
63
|
+
}
|
|
64
|
+
function matches(row, column, filter, columns) {
|
|
65
|
+
const raw = value(row, column, columns);
|
|
66
|
+
const text = String(raw ?? "").toLowerCase();
|
|
67
|
+
const needle = String(filter.value ?? "").toLowerCase();
|
|
68
|
+
const numeric = Number(raw);
|
|
69
|
+
const from = Number(filter.value);
|
|
70
|
+
const to = Number(filter.valueTo);
|
|
71
|
+
if (filter.operator === "blank") return !text.trim();
|
|
72
|
+
if (filter.operator === "notBlank") return Boolean(text.trim());
|
|
73
|
+
if (filter.operator === "in") return (filter.values ?? []).map(String).includes(String(raw ?? ""));
|
|
74
|
+
if (!needle && filter.operator !== "between") return true;
|
|
75
|
+
if (filter.operator === "equals") return text === needle;
|
|
76
|
+
if (filter.operator === "startsWith") return text.startsWith(needle);
|
|
77
|
+
if (filter.operator === "endsWith") return text.endsWith(needle);
|
|
78
|
+
if (filter.operator === "gt") return numeric > from;
|
|
79
|
+
if (filter.operator === "gte") return numeric >= from;
|
|
80
|
+
if (filter.operator === "lt") return numeric < from;
|
|
81
|
+
if (filter.operator === "lte") return numeric <= from;
|
|
82
|
+
if (filter.operator === "between") return numeric >= from && numeric <= to;
|
|
83
|
+
return text.includes(needle);
|
|
84
|
+
}
|
|
85
|
+
function activeAdvanced(model) {
|
|
86
|
+
if (!model) return false;
|
|
87
|
+
if (model.kind === "group") return model.conditions.some(activeAdvanced);
|
|
88
|
+
if (model.operator === "blank" || model.operator === "notBlank") return true;
|
|
89
|
+
if (model.operator === "in") return Boolean(model.values?.length);
|
|
90
|
+
return model.value != null && String(model.value).trim() !== "";
|
|
91
|
+
}
|
|
92
|
+
function matchesAdvanced(row, columns, model) {
|
|
93
|
+
if (!model || !activeAdvanced(model)) return true;
|
|
94
|
+
if (model.kind === "group") {
|
|
95
|
+
const active = model.conditions.filter(activeAdvanced);
|
|
96
|
+
return model.joinOperator === "or" ? active.some((condition) => matchesAdvanced(row, columns, condition)) : active.every((condition) => matchesAdvanced(row, columns, condition));
|
|
97
|
+
}
|
|
98
|
+
const column = columns.find((entry) => entry.id === model.columnId);
|
|
99
|
+
return column ? matches(row, column, { operator: model.operator, value: model.value, valueTo: model.valueTo, values: model.values }, columns) : true;
|
|
100
|
+
}
|
|
101
|
+
function aggregate(values, aggregation) {
|
|
102
|
+
if (aggregation === "count") return values.length;
|
|
103
|
+
const numbers = values.map(Number).filter((entry) => !Number.isNaN(entry));
|
|
104
|
+
if (!numbers.length) return 0;
|
|
105
|
+
if (aggregation === "avg") return numbers.reduce((sum, entry) => sum + entry, 0) / numbers.length;
|
|
106
|
+
if (aggregation === "min") return Math.min(...numbers);
|
|
107
|
+
if (aggregation === "max") return Math.max(...numbers);
|
|
108
|
+
return numbers.reduce((sum, entry) => sum + entry, 0);
|
|
109
|
+
}
|
|
110
|
+
function buildPivot(rows, columns, groupBy, pivotBy, pivotValueColumns, pivotAggregation = "sum") {
|
|
111
|
+
if (!pivotBy) return { columns, rows, active: false };
|
|
112
|
+
const valueFields = pivotValueColumns?.length ? pivotValueColumns : columns.filter((column) => rows.some((row) => typeof value(row, column, columns) === "number")).map((column) => column.field);
|
|
113
|
+
const pivotLabels = Array.from(new Set(rows.map((row) => String(row[pivotBy] ?? "Blank"))));
|
|
114
|
+
const groupLabels = Array.from(new Set(rows.map((row) => String(groupBy ? row[groupBy] : "Total"))));
|
|
115
|
+
const pivotColumns = [
|
|
116
|
+
{ id: "__group", field: "__group", headerName: groupBy ?? "Group", width: 180 },
|
|
117
|
+
...pivotLabels.flatMap(
|
|
118
|
+
(label) => valueFields.map((field) => ({
|
|
119
|
+
id: `${label}_${String(field)}`,
|
|
120
|
+
field: `${label}_${String(field)}`,
|
|
121
|
+
headerName: `${label} ${String(field)}`,
|
|
122
|
+
width: 140
|
|
123
|
+
}))
|
|
124
|
+
)
|
|
125
|
+
];
|
|
126
|
+
const pivotRows = groupLabels.map((group) => {
|
|
127
|
+
const output = { __group: group };
|
|
128
|
+
pivotLabels.forEach((pivot) => {
|
|
129
|
+
const bucket = rows.filter((row) => String(row[pivotBy] ?? "Blank") === pivot && String(groupBy ? row[groupBy] : "Total") === group);
|
|
130
|
+
valueFields.forEach((field) => {
|
|
131
|
+
output[`${pivot}_${String(field)}`] = aggregate(bucket.map((row) => row[field]), pivotAggregation);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
return output;
|
|
135
|
+
});
|
|
136
|
+
return { columns: pivotColumns, rows: pivotRows, active: true };
|
|
137
|
+
}
|
|
138
|
+
function cell(text, tag = "td") {
|
|
139
|
+
const element = document.createElement(tag);
|
|
140
|
+
element.textContent = text;
|
|
141
|
+
return element;
|
|
142
|
+
}
|
|
143
|
+
var GridNexaAngularComponent = class {
|
|
144
|
+
columns = [];
|
|
145
|
+
rows = [];
|
|
146
|
+
mergedHeaders;
|
|
147
|
+
rowNumbers = false;
|
|
148
|
+
checkboxSelection = false;
|
|
149
|
+
enableRangeSelection = true;
|
|
150
|
+
enableFillHandle = true;
|
|
151
|
+
enableUndoRedo = true;
|
|
152
|
+
quickFilterText = "";
|
|
153
|
+
columnFilters;
|
|
154
|
+
externalFilter;
|
|
155
|
+
advancedFilter;
|
|
156
|
+
advancedFilterModel;
|
|
157
|
+
pageSize;
|
|
158
|
+
groupBy;
|
|
159
|
+
pivotBy;
|
|
160
|
+
pivotValueColumns;
|
|
161
|
+
pivotAggregation = "sum";
|
|
162
|
+
getRowId;
|
|
163
|
+
getTreeDataPath;
|
|
164
|
+
masterDetailRenderer;
|
|
165
|
+
transaction;
|
|
166
|
+
localeText;
|
|
167
|
+
rowSelectionChange = new import_core.EventEmitter();
|
|
168
|
+
cellClick = new import_core.EventEmitter();
|
|
169
|
+
cellValueChange = new import_core.EventEmitter();
|
|
170
|
+
advancedFilterModelChange = new import_core.EventEmitter();
|
|
171
|
+
pivotModelChange = new import_core.EventEmitter();
|
|
172
|
+
serverSideOperation = new import_core.EventEmitter();
|
|
173
|
+
host;
|
|
174
|
+
selected = /* @__PURE__ */ new Set();
|
|
175
|
+
pageIndex = 0;
|
|
176
|
+
sortState = null;
|
|
177
|
+
hiddenColumnIds = /* @__PURE__ */ new Set();
|
|
178
|
+
activeCell = null;
|
|
179
|
+
findText = "";
|
|
180
|
+
toolsOpen = false;
|
|
181
|
+
draggedColumnId = null;
|
|
182
|
+
undoStack = [];
|
|
183
|
+
redoStack = [];
|
|
184
|
+
ngAfterViewInit() {
|
|
185
|
+
this.render();
|
|
186
|
+
}
|
|
187
|
+
ngOnChanges() {
|
|
188
|
+
this.hiddenColumnIds = new Set(this.columns.filter((column) => column.hidden).map((column) => column.id));
|
|
189
|
+
this.applyTransaction();
|
|
190
|
+
this.render();
|
|
191
|
+
}
|
|
192
|
+
rowId(row, index) {
|
|
193
|
+
return this.getRowId?.(row, index) ?? index;
|
|
194
|
+
}
|
|
195
|
+
applyTransaction() {
|
|
196
|
+
if (!this.transaction) return;
|
|
197
|
+
const removeIds = new Set((this.transaction.remove ?? []).map((row, index) => this.rowId(row, index)));
|
|
198
|
+
const updates = new Map((this.transaction.update ?? []).map((row, index) => [this.rowId(row, index), row]));
|
|
199
|
+
this.rows = [
|
|
200
|
+
...this.rows.filter((row, index) => !removeIds.has(this.rowId(row, index))).map((row, index) => updates.get(this.rowId(row, index)) ?? row),
|
|
201
|
+
...this.transaction.add ?? []
|
|
202
|
+
];
|
|
203
|
+
this.transaction = void 0;
|
|
204
|
+
}
|
|
205
|
+
visibleRows() {
|
|
206
|
+
const query = this.quickFilterText.trim().toLowerCase();
|
|
207
|
+
const rows = this.rows.filter((row) => {
|
|
208
|
+
if (this.externalFilter && !this.externalFilter(row)) return false;
|
|
209
|
+
if (this.advancedFilter && !this.advancedFilter(row)) return false;
|
|
210
|
+
if (!matchesAdvanced(row, this.columns, this.advancedFilterModel)) return false;
|
|
211
|
+
if (query && !this.columns.some((column2) => String(value(row, column2, this.columns) ?? "").toLowerCase().includes(query))) return false;
|
|
212
|
+
return Object.entries(this.columnFilters ?? {}).every(([columnId, filter]) => {
|
|
213
|
+
const column2 = this.columns.find((entry) => entry.id === columnId);
|
|
214
|
+
return column2 ? matches(row, column2, filter, this.columns) : true;
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
if (!this.sortState) return rows;
|
|
218
|
+
const column = this.columns.find((entry) => entry.id === this.sortState?.columnId);
|
|
219
|
+
if (!column) return rows;
|
|
220
|
+
return [...rows].sort((left, right) => {
|
|
221
|
+
const comparison = String(value(left, column, this.columns) ?? "").localeCompare(String(value(right, column, this.columns) ?? ""), void 0, { numeric: true });
|
|
222
|
+
return this.sortState?.direction === "asc" ? comparison : -comparison;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
exportRows(columns, rows, excel = false) {
|
|
226
|
+
const content = excel ? `<table><tr>${columns.map((column) => `<th>${column.headerName}</th>`).join("")}</tr>${rows.map((row) => `<tr>${columns.map((column) => `<td>${format(row, column, this.columns)}</td>`).join("")}</tr>`).join("")}</table>` : [columns.map((column) => JSON.stringify(column.headerName)).join(","), ...rows.map((row) => columns.map((column) => JSON.stringify(format(row, column, this.columns))).join(","))].join("\n");
|
|
227
|
+
const blob = new Blob([content], { type: excel ? "application/vnd.ms-excel" : "text/csv;charset=utf-8" });
|
|
228
|
+
const link = document.createElement("a");
|
|
229
|
+
link.href = URL.createObjectURL(blob);
|
|
230
|
+
link.download = excel ? "gridnexa-export.xls" : "gridnexa-export.csv";
|
|
231
|
+
link.click();
|
|
232
|
+
URL.revokeObjectURL(link.href);
|
|
233
|
+
}
|
|
234
|
+
setCellValue(row, rowIndex, column, nextValue, trackHistory = true) {
|
|
235
|
+
const oldValue = rawValue(row, column);
|
|
236
|
+
const newValue = typeof oldValue === "number" ? Number(nextValue) : nextValue;
|
|
237
|
+
if (trackHistory && this.enableUndoRedo) {
|
|
238
|
+
this.undoStack.push({ row, rowIndex, column, oldValue, newValue });
|
|
239
|
+
this.redoStack = [];
|
|
240
|
+
}
|
|
241
|
+
row[column.field] = newValue;
|
|
242
|
+
this.cellValueChange.emit({ row, rowIndex, column, oldValue, newValue });
|
|
243
|
+
}
|
|
244
|
+
undo() {
|
|
245
|
+
const edit = this.undoStack.pop();
|
|
246
|
+
if (!edit) return;
|
|
247
|
+
this.setCellValue(edit.row, edit.rowIndex, edit.column, edit.oldValue, false);
|
|
248
|
+
this.redoStack.push(edit);
|
|
249
|
+
this.render();
|
|
250
|
+
}
|
|
251
|
+
redo() {
|
|
252
|
+
const edit = this.redoStack.pop();
|
|
253
|
+
if (!edit) return;
|
|
254
|
+
this.setCellValue(edit.row, edit.rowIndex, edit.column, edit.newValue, false);
|
|
255
|
+
this.undoStack.push(edit);
|
|
256
|
+
this.render();
|
|
257
|
+
}
|
|
258
|
+
fillDown() {
|
|
259
|
+
if (!this.activeCell || !this.enableFillHandle) return;
|
|
260
|
+
const sourceRow = this.rows[this.activeCell.rowIndex];
|
|
261
|
+
const targetRow = this.rows[this.activeCell.rowIndex + 1];
|
|
262
|
+
const column = this.columns.find((entry) => entry.id === this.activeCell?.columnId);
|
|
263
|
+
if (!sourceRow || !targetRow || !column || column.editable === false) return;
|
|
264
|
+
this.setCellValue(targetRow, this.activeCell.rowIndex + 1, column, rawValue(sourceRow, column));
|
|
265
|
+
this.render();
|
|
266
|
+
}
|
|
267
|
+
async copyActiveCell() {
|
|
268
|
+
if (!this.activeCell || typeof navigator === "undefined") return;
|
|
269
|
+
const row = this.rows[this.activeCell.rowIndex];
|
|
270
|
+
const column = this.columns.find((entry) => entry.id === this.activeCell?.columnId);
|
|
271
|
+
if (!row || !column) return;
|
|
272
|
+
await navigator.clipboard?.writeText(format(row, column, this.columns));
|
|
273
|
+
}
|
|
274
|
+
async pasteActiveCell() {
|
|
275
|
+
if (!this.activeCell || typeof navigator === "undefined") return;
|
|
276
|
+
const row = this.rows[this.activeCell.rowIndex];
|
|
277
|
+
const column = this.columns.find((entry) => entry.id === this.activeCell?.columnId);
|
|
278
|
+
if (!row || !column || column.editable === false) return;
|
|
279
|
+
const text = await navigator.clipboard?.readText();
|
|
280
|
+
this.setCellValue(row, this.activeCell.rowIndex, column, text);
|
|
281
|
+
this.render();
|
|
282
|
+
}
|
|
283
|
+
moveRow(rowIndex, direction) {
|
|
284
|
+
const nextIndex = rowIndex + direction;
|
|
285
|
+
if (nextIndex < 0 || nextIndex >= this.rows.length) return;
|
|
286
|
+
const rows = [...this.rows];
|
|
287
|
+
const [row] = rows.splice(rowIndex, 1);
|
|
288
|
+
rows.splice(nextIndex, 0, row);
|
|
289
|
+
this.rows = rows;
|
|
290
|
+
this.render();
|
|
291
|
+
}
|
|
292
|
+
moveColumn(sourceId, targetId) {
|
|
293
|
+
if (sourceId === targetId) return;
|
|
294
|
+
const columns = [...this.columns];
|
|
295
|
+
const sourceIndex = columns.findIndex((column2) => column2.id === sourceId);
|
|
296
|
+
const targetIndex = columns.findIndex((column2) => column2.id === targetId);
|
|
297
|
+
if (sourceIndex < 0 || targetIndex < 0) return;
|
|
298
|
+
const [column] = columns.splice(sourceIndex, 1);
|
|
299
|
+
columns.splice(targetIndex, 0, column);
|
|
300
|
+
this.columns = columns;
|
|
301
|
+
this.render();
|
|
302
|
+
}
|
|
303
|
+
updateAdvancedFilter(columnId, operator, filterValue) {
|
|
304
|
+
const model = {
|
|
305
|
+
kind: "group",
|
|
306
|
+
joinOperator: "and",
|
|
307
|
+
conditions: [{ kind: "rule", columnId, operator, value: filterValue }]
|
|
308
|
+
};
|
|
309
|
+
this.advancedFilterModel = model;
|
|
310
|
+
this.advancedFilterModelChange.emit(model);
|
|
311
|
+
this.render();
|
|
312
|
+
}
|
|
313
|
+
updatePivot(next) {
|
|
314
|
+
if ("groupBy" in next) this.groupBy = next.groupBy;
|
|
315
|
+
if ("pivotBy" in next) this.pivotBy = next.pivotBy;
|
|
316
|
+
if ("pivotValueColumns" in next) this.pivotValueColumns = next.pivotValueColumns;
|
|
317
|
+
if ("pivotAggregation" in next && next.pivotAggregation) this.pivotAggregation = next.pivotAggregation;
|
|
318
|
+
this.pivotModelChange.emit({
|
|
319
|
+
groupBy: this.groupBy,
|
|
320
|
+
pivotBy: this.pivotBy,
|
|
321
|
+
pivotValueColumns: this.pivotValueColumns ?? [],
|
|
322
|
+
pivotAggregation: this.pivotAggregation
|
|
323
|
+
});
|
|
324
|
+
this.pageIndex = 0;
|
|
325
|
+
this.render();
|
|
326
|
+
}
|
|
327
|
+
render() {
|
|
328
|
+
if (!this.host) return;
|
|
329
|
+
const sourceRows = this.visibleRows();
|
|
330
|
+
const pivot = buildPivot(sourceRows, this.columns, this.groupBy, this.pivotBy, this.pivotValueColumns, this.pivotAggregation);
|
|
331
|
+
const columns = pivot.columns.filter((column) => !this.hiddenColumnIds.has(column.id) && !column.hidden);
|
|
332
|
+
const pageRows = this.pageSize ? pivot.rows.slice(this.pageIndex * this.pageSize, this.pageIndex * this.pageSize + this.pageSize) : pivot.rows;
|
|
333
|
+
const root = document.createElement("div");
|
|
334
|
+
root.className = "gridnexa-angular-grid";
|
|
335
|
+
root.append(this.renderToolbar(columns, pivot.rows), this.renderTable(columns, pageRows));
|
|
336
|
+
if (this.toolsOpen) root.appendChild(this.renderToolsPanel());
|
|
337
|
+
root.appendChild(this.renderStatus(pivot.rows.length));
|
|
338
|
+
this.host.nativeElement.replaceChildren(root);
|
|
339
|
+
this.serverSideOperation.emit({
|
|
340
|
+
sortModel: this.sortState ? [this.sortState] : [],
|
|
341
|
+
filterModel: this.columnFilters,
|
|
342
|
+
advancedFilterModel: this.advancedFilterModel,
|
|
343
|
+
selectedRowIds: Array.from(this.selected),
|
|
344
|
+
pageIndex: this.pageIndex,
|
|
345
|
+
pageSize: this.pageSize,
|
|
346
|
+
groupBy: this.groupBy,
|
|
347
|
+
pivotBy: this.pivotBy,
|
|
348
|
+
pivotValueColumns: this.pivotValueColumns,
|
|
349
|
+
pivotAggregation: this.pivotAggregation,
|
|
350
|
+
treeData: Boolean(this.getTreeDataPath),
|
|
351
|
+
masterDetail: Boolean(this.masterDetailRenderer)
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
renderToolbar(columns, rows) {
|
|
355
|
+
const toolbar = document.createElement("div");
|
|
356
|
+
toolbar.style.cssText = "display:flex;gap:8px;justify-content:space-between;align-items:center;padding:10px;background:#f8fbff;border:1px solid #dbe3ef";
|
|
357
|
+
toolbar.append(`${rows.length} rows`);
|
|
358
|
+
const actions = document.createElement("div");
|
|
359
|
+
actions.style.cssText = "display:flex;gap:6px;flex-wrap:wrap";
|
|
360
|
+
const find = document.createElement("input");
|
|
361
|
+
find.type = "search";
|
|
362
|
+
find.placeholder = "Find cell";
|
|
363
|
+
find.value = this.findText;
|
|
364
|
+
find.style.cssText = "min-height:32px;padding:0 10px;border:1px solid #bfdbfe;border-radius:8px";
|
|
365
|
+
find.addEventListener("input", () => {
|
|
366
|
+
this.findText = find.value;
|
|
367
|
+
this.render();
|
|
368
|
+
});
|
|
369
|
+
const pageCount = this.pageSize ? Math.max(1, Math.ceil(rows.length / this.pageSize)) : 1;
|
|
370
|
+
if (this.pageSize) {
|
|
371
|
+
const prev = this.button("Prev", () => {
|
|
372
|
+
this.pageIndex = Math.max(0, this.pageIndex - 1);
|
|
373
|
+
this.render();
|
|
374
|
+
});
|
|
375
|
+
prev.disabled = this.pageIndex <= 0;
|
|
376
|
+
const next = this.button("Next", () => {
|
|
377
|
+
this.pageIndex = Math.min(pageCount - 1, this.pageIndex + 1);
|
|
378
|
+
this.render();
|
|
379
|
+
});
|
|
380
|
+
next.disabled = this.pageIndex >= pageCount - 1;
|
|
381
|
+
actions.append(prev, ` Page ${this.pageIndex + 1} `, next);
|
|
382
|
+
}
|
|
383
|
+
actions.appendChild(find);
|
|
384
|
+
if (this.enableUndoRedo) {
|
|
385
|
+
const undo = this.button("Undo", () => this.undo());
|
|
386
|
+
undo.disabled = !this.undoStack.length;
|
|
387
|
+
const redo = this.button("Redo", () => this.redo());
|
|
388
|
+
redo.disabled = !this.redoStack.length;
|
|
389
|
+
actions.append(undo, redo);
|
|
390
|
+
}
|
|
391
|
+
if (this.enableFillHandle) actions.appendChild(this.button("Fill", () => this.fillDown()));
|
|
392
|
+
actions.append(
|
|
393
|
+
this.button("Copy", () => void this.copyActiveCell()),
|
|
394
|
+
this.button("Paste", () => void this.pasteActiveCell()),
|
|
395
|
+
this.button(this.toolsOpen ? "Hide tools" : "Tools", () => {
|
|
396
|
+
this.toolsOpen = !this.toolsOpen;
|
|
397
|
+
this.render();
|
|
398
|
+
}),
|
|
399
|
+
this.button("Export CSV", () => this.exportRows(columns, rows)),
|
|
400
|
+
this.button("Export Excel", () => this.exportRows(columns, rows, true))
|
|
401
|
+
);
|
|
402
|
+
toolbar.appendChild(actions);
|
|
403
|
+
return toolbar;
|
|
404
|
+
}
|
|
405
|
+
renderTable(columns, rows) {
|
|
406
|
+
const table = document.createElement("table");
|
|
407
|
+
table.style.cssText = "width:100%;border-collapse:collapse";
|
|
408
|
+
const thead = document.createElement("thead");
|
|
409
|
+
const leading = Number(this.checkboxSelection) + Number(this.rowNumbers);
|
|
410
|
+
if (this.mergedHeaders?.length) thead.appendChild(this.renderMergedHeaders(columns, leading));
|
|
411
|
+
const header = document.createElement("tr");
|
|
412
|
+
if (this.checkboxSelection) header.appendChild(cell("", "th"));
|
|
413
|
+
if (this.rowNumbers) header.appendChild(cell("#", "th"));
|
|
414
|
+
columns.forEach((column) => {
|
|
415
|
+
const th = cell(`${column.headerName}${this.sortState?.columnId === column.id ? this.sortState.direction === "asc" ? " \u2191" : " \u2193" : ""}`, "th");
|
|
416
|
+
th.style.cssText = "padding:10px;border:1px solid #dbe3ef;background:#f8fbff;text-align:left";
|
|
417
|
+
th.draggable = true;
|
|
418
|
+
th.addEventListener("dragstart", () => {
|
|
419
|
+
this.draggedColumnId = column.id;
|
|
420
|
+
});
|
|
421
|
+
th.addEventListener("dragover", (event) => event.preventDefault());
|
|
422
|
+
th.addEventListener("drop", (event) => {
|
|
423
|
+
event.preventDefault();
|
|
424
|
+
if (this.draggedColumnId) this.moveColumn(this.draggedColumnId, column.id);
|
|
425
|
+
this.draggedColumnId = null;
|
|
426
|
+
});
|
|
427
|
+
th.addEventListener("click", () => {
|
|
428
|
+
if (column.sortable === false) return;
|
|
429
|
+
this.sortState = this.sortState?.columnId !== column.id ? { columnId: column.id, direction: "asc" } : this.sortState.direction === "asc" ? { columnId: column.id, direction: "desc" } : null;
|
|
430
|
+
this.render();
|
|
431
|
+
});
|
|
432
|
+
header.appendChild(th);
|
|
433
|
+
});
|
|
434
|
+
thead.appendChild(header);
|
|
435
|
+
table.appendChild(thead);
|
|
436
|
+
const tbody = document.createElement("tbody");
|
|
437
|
+
rows.forEach((row, rowIndex) => this.appendRow(tbody, row, rowIndex, columns, leading));
|
|
438
|
+
table.appendChild(tbody);
|
|
439
|
+
return table;
|
|
440
|
+
}
|
|
441
|
+
renderMergedHeaders(columns, leading) {
|
|
442
|
+
const row = document.createElement("tr");
|
|
443
|
+
if (leading) {
|
|
444
|
+
const spacer = cell("", "th");
|
|
445
|
+
spacer.colSpan = leading;
|
|
446
|
+
row.appendChild(spacer);
|
|
447
|
+
}
|
|
448
|
+
(this.mergedHeaders ?? []).forEach((header) => {
|
|
449
|
+
const count = header.columnIds.filter((columnId) => columns.some((column) => column.id === columnId)).length;
|
|
450
|
+
if (!count) return;
|
|
451
|
+
const th = cell(header.headerName, "th");
|
|
452
|
+
th.colSpan = count;
|
|
453
|
+
th.style.cssText = "padding:8px;border:1px solid #bfdbfe;background:#e8f1ff;text-align:center";
|
|
454
|
+
row.appendChild(th);
|
|
455
|
+
});
|
|
456
|
+
return row;
|
|
457
|
+
}
|
|
458
|
+
appendRow(tbody, row, rowIndex, columns, leading) {
|
|
459
|
+
const tr = document.createElement("tr");
|
|
460
|
+
if (this.checkboxSelection) {
|
|
461
|
+
const td = document.createElement("td");
|
|
462
|
+
const checkbox = document.createElement("input");
|
|
463
|
+
checkbox.type = "checkbox";
|
|
464
|
+
checkbox.checked = this.selected.has(this.rowId(row, rowIndex));
|
|
465
|
+
checkbox.addEventListener("change", () => {
|
|
466
|
+
checkbox.checked ? this.selected.add(this.rowId(row, rowIndex)) : this.selected.delete(this.rowId(row, rowIndex));
|
|
467
|
+
this.rowSelectionChange.emit(this.rows.filter((entry, index) => this.selected.has(this.rowId(entry, index))));
|
|
468
|
+
this.render();
|
|
469
|
+
});
|
|
470
|
+
td.appendChild(checkbox);
|
|
471
|
+
tr.appendChild(td);
|
|
472
|
+
}
|
|
473
|
+
if (this.rowNumbers) {
|
|
474
|
+
const rowNumber = cell(String(rowIndex + 1));
|
|
475
|
+
const up = this.button("\u2191", () => this.moveRow(rowIndex, -1));
|
|
476
|
+
up.disabled = rowIndex <= 0;
|
|
477
|
+
const down = this.button("\u2193", () => this.moveRow(rowIndex, 1));
|
|
478
|
+
down.disabled = rowIndex >= this.rows.length - 1;
|
|
479
|
+
rowNumber.append(" ", up, down);
|
|
480
|
+
tr.appendChild(rowNumber);
|
|
481
|
+
}
|
|
482
|
+
columns.forEach((column, columnIndex) => {
|
|
483
|
+
const td = cell(format(row, column, this.columns));
|
|
484
|
+
td.style.cssText = "padding:10px;border:1px solid #dbe3ef";
|
|
485
|
+
if (this.activeCell?.rowIndex === rowIndex && this.activeCell.columnId === column.id) {
|
|
486
|
+
td.style.outline = "2px solid #2563eb";
|
|
487
|
+
td.style.outlineOffset = "-2px";
|
|
488
|
+
}
|
|
489
|
+
if (this.findText && format(row, column, this.columns).toLowerCase().includes(this.findText.toLowerCase())) {
|
|
490
|
+
td.style.background = "rgba(37,99,235,.1)";
|
|
491
|
+
}
|
|
492
|
+
if (this.getTreeDataPath && columnIndex === 0) td.style.paddingLeft = `${12 + Math.max(0, this.getTreeDataPath(row).length - 1) * 24}px`;
|
|
493
|
+
td.addEventListener("click", () => {
|
|
494
|
+
this.activeCell = { rowIndex, columnId: column.id };
|
|
495
|
+
this.cellClick.emit({ row, rowIndex, column });
|
|
496
|
+
this.render();
|
|
497
|
+
});
|
|
498
|
+
if (column.editable) td.addEventListener("dblclick", () => this.editCell(td, row, rowIndex, column));
|
|
499
|
+
tr.appendChild(td);
|
|
500
|
+
});
|
|
501
|
+
tbody.appendChild(tr);
|
|
502
|
+
if (this.masterDetailRenderer) {
|
|
503
|
+
const detailRow = document.createElement("tr");
|
|
504
|
+
const detail = document.createElement("td");
|
|
505
|
+
detail.colSpan = columns.length + leading;
|
|
506
|
+
const content = this.masterDetailRenderer(row);
|
|
507
|
+
content instanceof Node ? detail.appendChild(content) : detail.textContent = String(content ?? "");
|
|
508
|
+
detailRow.appendChild(detail);
|
|
509
|
+
tbody.appendChild(detailRow);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
editCell(td, row, rowIndex, column) {
|
|
513
|
+
const oldValue = rawValue(row, column);
|
|
514
|
+
const input = document.createElement("input");
|
|
515
|
+
input.value = String(oldValue ?? "");
|
|
516
|
+
td.replaceChildren(input);
|
|
517
|
+
input.focus();
|
|
518
|
+
input.addEventListener("blur", () => {
|
|
519
|
+
this.setCellValue(row, rowIndex, column, input.value);
|
|
520
|
+
this.render();
|
|
521
|
+
}, { once: true });
|
|
522
|
+
}
|
|
523
|
+
renderToolsPanel() {
|
|
524
|
+
const panel = document.createElement("div");
|
|
525
|
+
panel.style.cssText = "display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px;padding:12px;border:1px solid #dbe3ef;border-top:0;background:#f8fbff";
|
|
526
|
+
const columnsSection = document.createElement("section");
|
|
527
|
+
columnsSection.appendChild(document.createElement("strong")).textContent = "Columns";
|
|
528
|
+
this.columns.forEach((column) => {
|
|
529
|
+
const label = document.createElement("label");
|
|
530
|
+
label.style.cssText = "display:flex;gap:8px;align-items:center;margin-top:6px";
|
|
531
|
+
const checkbox = document.createElement("input");
|
|
532
|
+
checkbox.type = "checkbox";
|
|
533
|
+
checkbox.checked = !this.hiddenColumnIds.has(column.id);
|
|
534
|
+
checkbox.addEventListener("change", () => {
|
|
535
|
+
checkbox.checked ? this.hiddenColumnIds.delete(column.id) : this.hiddenColumnIds.add(column.id);
|
|
536
|
+
this.render();
|
|
537
|
+
});
|
|
538
|
+
label.append(checkbox, column.headerName);
|
|
539
|
+
columnsSection.appendChild(label);
|
|
540
|
+
});
|
|
541
|
+
const pivotSection = document.createElement("section");
|
|
542
|
+
pivotSection.appendChild(document.createElement("strong")).textContent = "Pivot";
|
|
543
|
+
pivotSection.append(
|
|
544
|
+
this.select("Row group", this.groupBy, "No group", (value2) => this.updatePivot({ groupBy: value2 })),
|
|
545
|
+
this.select("Pivot by", this.pivotBy, "Pivot off", (value2) => this.updatePivot({ pivotBy: value2 })),
|
|
546
|
+
this.select("Value", this.pivotValueColumns?.[0], "No value", (value2) => this.updatePivot({ pivotValueColumns: value2 ? [value2] : [] })),
|
|
547
|
+
this.select("Aggregation", this.pivotAggregation, "", (value2) => this.updatePivot({ pivotAggregation: value2 }), ["sum", "avg", "count", "min", "max"])
|
|
548
|
+
);
|
|
549
|
+
const filterSection = document.createElement("section");
|
|
550
|
+
filterSection.appendChild(document.createElement("strong")).textContent = "Advanced filter";
|
|
551
|
+
const columnSelect = this.select("", this.columns[0]?.id, "", () => void 0, this.columns.map((column) => column.id));
|
|
552
|
+
const operatorSelect = this.select("", "contains", "", () => void 0, ["contains", "equals", "gt", "gte", "lt", "lte", "blank", "notBlank"]);
|
|
553
|
+
const valueInput = document.createElement("input");
|
|
554
|
+
valueInput.placeholder = "Value";
|
|
555
|
+
valueInput.style.cssText = "min-height:32px;padding:0 10px;border:1px solid #bfdbfe;border-radius:8px";
|
|
556
|
+
const apply = this.button("Apply", () => {
|
|
557
|
+
this.updateAdvancedFilter(
|
|
558
|
+
columnSelect.querySelector("select").value,
|
|
559
|
+
operatorSelect.querySelector("select").value,
|
|
560
|
+
valueInput.value
|
|
561
|
+
);
|
|
562
|
+
});
|
|
563
|
+
const clear = this.button("Clear", () => {
|
|
564
|
+
this.advancedFilterModel = null;
|
|
565
|
+
this.advancedFilterModelChange.emit(null);
|
|
566
|
+
this.render();
|
|
567
|
+
});
|
|
568
|
+
filterSection.append(columnSelect, operatorSelect, valueInput, apply, clear);
|
|
569
|
+
panel.append(columnsSection, pivotSection, filterSection);
|
|
570
|
+
return panel;
|
|
571
|
+
}
|
|
572
|
+
select(labelText, value2, emptyLabel, onChange, fixedOptions) {
|
|
573
|
+
const label = document.createElement("label");
|
|
574
|
+
label.style.cssText = "display:flex;gap:8px;align-items:center;margin-top:6px";
|
|
575
|
+
if (labelText) label.append(`${labelText} `);
|
|
576
|
+
const select = document.createElement("select");
|
|
577
|
+
select.style.cssText = "min-height:32px;padding:0 8px;border:1px solid #bfdbfe;border-radius:8px";
|
|
578
|
+
if (emptyLabel) {
|
|
579
|
+
const option = document.createElement("option");
|
|
580
|
+
option.value = "";
|
|
581
|
+
option.textContent = emptyLabel;
|
|
582
|
+
select.appendChild(option);
|
|
583
|
+
}
|
|
584
|
+
(fixedOptions ?? this.columns.map((column) => String(column.field))).forEach((entry) => {
|
|
585
|
+
const option = document.createElement("option");
|
|
586
|
+
option.value = entry;
|
|
587
|
+
option.textContent = this.columns.find((column) => column.id === entry || column.field === entry)?.headerName ?? entry;
|
|
588
|
+
select.appendChild(option);
|
|
589
|
+
});
|
|
590
|
+
select.value = value2 ?? "";
|
|
591
|
+
select.addEventListener("change", () => onChange(select.value || void 0));
|
|
592
|
+
label.appendChild(select);
|
|
593
|
+
return label;
|
|
594
|
+
}
|
|
595
|
+
renderStatus(totalRows) {
|
|
596
|
+
const status = document.createElement("div");
|
|
597
|
+
status.style.cssText = "display:flex;gap:16px;padding:10px;border:1px solid #dbe3ef;border-top:0;font-weight:700";
|
|
598
|
+
status.append(`${totalRows} rows`, `${this.selected.size} selected`, this.sortState ? `Sorted ${this.sortState.direction}` : "Unsorted");
|
|
599
|
+
return status;
|
|
600
|
+
}
|
|
601
|
+
button(text, onClick) {
|
|
602
|
+
const button = document.createElement("button");
|
|
603
|
+
button.type = "button";
|
|
604
|
+
button.textContent = text;
|
|
605
|
+
button.style.cssText = "min-height:32px;padding:0 10px;border:1px solid #bfdbfe;border-radius:8px;background:#fff;color:#1d4ed8;font-weight:800";
|
|
606
|
+
button.addEventListener("click", onClick);
|
|
607
|
+
return button;
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
__decorateClass([
|
|
611
|
+
(0, import_core.Input)({ required: true })
|
|
612
|
+
], GridNexaAngularComponent.prototype, "columns", 2);
|
|
613
|
+
__decorateClass([
|
|
614
|
+
(0, import_core.Input)({ required: true })
|
|
615
|
+
], GridNexaAngularComponent.prototype, "rows", 2);
|
|
616
|
+
__decorateClass([
|
|
617
|
+
(0, import_core.Input)()
|
|
618
|
+
], GridNexaAngularComponent.prototype, "mergedHeaders", 2);
|
|
619
|
+
__decorateClass([
|
|
620
|
+
(0, import_core.Input)()
|
|
621
|
+
], GridNexaAngularComponent.prototype, "rowNumbers", 2);
|
|
622
|
+
__decorateClass([
|
|
623
|
+
(0, import_core.Input)()
|
|
624
|
+
], GridNexaAngularComponent.prototype, "checkboxSelection", 2);
|
|
625
|
+
__decorateClass([
|
|
626
|
+
(0, import_core.Input)()
|
|
627
|
+
], GridNexaAngularComponent.prototype, "enableRangeSelection", 2);
|
|
628
|
+
__decorateClass([
|
|
629
|
+
(0, import_core.Input)()
|
|
630
|
+
], GridNexaAngularComponent.prototype, "enableFillHandle", 2);
|
|
631
|
+
__decorateClass([
|
|
632
|
+
(0, import_core.Input)()
|
|
633
|
+
], GridNexaAngularComponent.prototype, "enableUndoRedo", 2);
|
|
634
|
+
__decorateClass([
|
|
635
|
+
(0, import_core.Input)()
|
|
636
|
+
], GridNexaAngularComponent.prototype, "quickFilterText", 2);
|
|
637
|
+
__decorateClass([
|
|
638
|
+
(0, import_core.Input)()
|
|
639
|
+
], GridNexaAngularComponent.prototype, "columnFilters", 2);
|
|
640
|
+
__decorateClass([
|
|
641
|
+
(0, import_core.Input)()
|
|
642
|
+
], GridNexaAngularComponent.prototype, "externalFilter", 2);
|
|
643
|
+
__decorateClass([
|
|
644
|
+
(0, import_core.Input)()
|
|
645
|
+
], GridNexaAngularComponent.prototype, "advancedFilter", 2);
|
|
646
|
+
__decorateClass([
|
|
647
|
+
(0, import_core.Input)()
|
|
648
|
+
], GridNexaAngularComponent.prototype, "advancedFilterModel", 2);
|
|
649
|
+
__decorateClass([
|
|
650
|
+
(0, import_core.Input)()
|
|
651
|
+
], GridNexaAngularComponent.prototype, "pageSize", 2);
|
|
652
|
+
__decorateClass([
|
|
653
|
+
(0, import_core.Input)()
|
|
654
|
+
], GridNexaAngularComponent.prototype, "groupBy", 2);
|
|
655
|
+
__decorateClass([
|
|
656
|
+
(0, import_core.Input)()
|
|
657
|
+
], GridNexaAngularComponent.prototype, "pivotBy", 2);
|
|
658
|
+
__decorateClass([
|
|
659
|
+
(0, import_core.Input)()
|
|
660
|
+
], GridNexaAngularComponent.prototype, "pivotValueColumns", 2);
|
|
661
|
+
__decorateClass([
|
|
662
|
+
(0, import_core.Input)()
|
|
663
|
+
], GridNexaAngularComponent.prototype, "pivotAggregation", 2);
|
|
664
|
+
__decorateClass([
|
|
665
|
+
(0, import_core.Input)()
|
|
666
|
+
], GridNexaAngularComponent.prototype, "getRowId", 2);
|
|
667
|
+
__decorateClass([
|
|
668
|
+
(0, import_core.Input)()
|
|
669
|
+
], GridNexaAngularComponent.prototype, "getTreeDataPath", 2);
|
|
670
|
+
__decorateClass([
|
|
671
|
+
(0, import_core.Input)()
|
|
672
|
+
], GridNexaAngularComponent.prototype, "masterDetailRenderer", 2);
|
|
673
|
+
__decorateClass([
|
|
674
|
+
(0, import_core.Input)()
|
|
675
|
+
], GridNexaAngularComponent.prototype, "transaction", 2);
|
|
676
|
+
__decorateClass([
|
|
677
|
+
(0, import_core.Input)()
|
|
678
|
+
], GridNexaAngularComponent.prototype, "localeText", 2);
|
|
679
|
+
__decorateClass([
|
|
680
|
+
(0, import_core.Output)()
|
|
681
|
+
], GridNexaAngularComponent.prototype, "rowSelectionChange", 2);
|
|
682
|
+
__decorateClass([
|
|
683
|
+
(0, import_core.Output)()
|
|
684
|
+
], GridNexaAngularComponent.prototype, "cellClick", 2);
|
|
685
|
+
__decorateClass([
|
|
686
|
+
(0, import_core.Output)()
|
|
687
|
+
], GridNexaAngularComponent.prototype, "cellValueChange", 2);
|
|
688
|
+
__decorateClass([
|
|
689
|
+
(0, import_core.Output)()
|
|
690
|
+
], GridNexaAngularComponent.prototype, "advancedFilterModelChange", 2);
|
|
691
|
+
__decorateClass([
|
|
692
|
+
(0, import_core.Output)()
|
|
693
|
+
], GridNexaAngularComponent.prototype, "pivotModelChange", 2);
|
|
694
|
+
__decorateClass([
|
|
695
|
+
(0, import_core.Output)()
|
|
696
|
+
], GridNexaAngularComponent.prototype, "serverSideOperation", 2);
|
|
697
|
+
__decorateClass([
|
|
698
|
+
(0, import_core.ViewChild)("host", { static: true })
|
|
699
|
+
], GridNexaAngularComponent.prototype, "host", 2);
|
|
700
|
+
GridNexaAngularComponent = __decorateClass([
|
|
701
|
+
(0, import_core.Component)({
|
|
702
|
+
selector: "grid-nexa",
|
|
703
|
+
standalone: true,
|
|
704
|
+
template: '<div #host class="gridnexa-angular-host"></div>'
|
|
705
|
+
})
|
|
706
|
+
], GridNexaAngularComponent);
|
|
707
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
708
|
+
0 && (module.exports = {
|
|
709
|
+
GridNexaAngularComponent,
|
|
710
|
+
...require("@gridnexa/core")
|
|
711
|
+
});
|