@omegagrid/grid-core 0.10.2 → 0.10.4
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/__generated/functions.d.ts +4 -0
- package/dist/__generated/functions.d.ts.map +1 -0
- package/dist/__generated/functions.js +45 -0
- package/dist/__generated/functions.js.map +1 -0
- package/dist/calculations/autofill.d.ts +7 -0
- package/dist/calculations/autofill.d.ts.map +1 -0
- package/dist/calculations/autofill.js +84 -0
- package/dist/calculations/autofill.js.map +1 -0
- package/dist/calculations/conditions.d.ts +4 -0
- package/dist/calculations/conditions.d.ts.map +1 -0
- package/dist/calculations/conditions.js +41 -0
- package/dist/calculations/conditions.js.map +1 -0
- package/dist/calculations/context.d.ts +53 -0
- package/dist/calculations/context.d.ts.map +1 -0
- package/dist/calculations/context.js +85 -0
- package/dist/calculations/context.js.map +1 -0
- package/dist/calculations/formula.d.ts +89 -0
- package/dist/calculations/formula.d.ts.map +1 -0
- package/dist/calculations/formula.js +443 -0
- package/dist/calculations/formula.js.map +1 -0
- package/dist/calculations/functions/dates.d.ts +13 -0
- package/dist/calculations/functions/dates.d.ts.map +1 -0
- package/dist/calculations/functions/dates.js +58 -0
- package/dist/calculations/functions/dates.js.map +1 -0
- package/dist/calculations/functions/index.d.ts +11 -0
- package/dist/calculations/functions/index.d.ts.map +1 -0
- package/dist/calculations/functions/index.js +21 -0
- package/dist/calculations/functions/index.js.map +1 -0
- package/dist/calculations/functions/logical.d.ts +11 -0
- package/dist/calculations/functions/logical.d.ts.map +1 -0
- package/dist/calculations/functions/logical.js +50 -0
- package/dist/calculations/functions/logical.js.map +1 -0
- package/dist/calculations/functions/lookup.d.ts +18 -0
- package/dist/calculations/functions/lookup.d.ts.map +1 -0
- package/dist/calculations/functions/lookup.js +169 -0
- package/dist/calculations/functions/lookup.js.map +1 -0
- package/dist/calculations/functions/math.d.ts +72 -0
- package/dist/calculations/functions/math.d.ts.map +1 -0
- package/dist/calculations/functions/math.js +182 -0
- package/dist/calculations/functions/math.js.map +1 -0
- package/dist/calculations/functions/special.d.ts +2 -0
- package/dist/calculations/functions/special.d.ts.map +1 -0
- package/dist/calculations/functions/special.js +51 -0
- package/dist/calculations/functions/special.js.map +1 -0
- package/dist/calculations/functions/statistical.d.ts +7 -0
- package/dist/calculations/functions/statistical.d.ts.map +1 -0
- package/dist/calculations/functions/statistical.js +47 -0
- package/dist/calculations/functions/statistical.js.map +1 -0
- package/dist/calculations/functions/text.d.ts +29 -0
- package/dist/calculations/functions/text.d.ts.map +1 -0
- package/dist/calculations/functions/text.js +58 -0
- package/dist/calculations/functions/text.js.map +1 -0
- package/dist/calculations/helpers.d.ts +13 -0
- package/dist/calculations/helpers.d.ts.map +1 -0
- package/dist/calculations/helpers.js +32 -0
- package/dist/calculations/helpers.js.map +1 -0
- package/dist/calculations/index.d.ts +7 -0
- package/dist/calculations/index.d.ts.map +1 -0
- package/dist/calculations/index.js +7 -0
- package/dist/calculations/index.js.map +1 -0
- package/dist/calculations/operators.d.ts +19 -0
- package/dist/calculations/operators.d.ts.map +1 -0
- package/dist/calculations/operators.js +58 -0
- package/dist/calculations/operators.js.map +1 -0
- package/dist/calculations/tokenization.d.ts +36 -0
- package/dist/calculations/tokenization.d.ts.map +1 -0
- package/dist/calculations/tokenization.js +203 -0
- package/dist/calculations/tokenization.js.map +1 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +2 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/range.d.ts +66 -0
- package/dist/common/range.d.ts.map +1 -0
- package/dist/common/range.js +222 -0
- package/dist/common/range.js.map +1 -0
- package/dist/constants.d.ts +68 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +127 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/model/calculationModel.d.ts +30 -0
- package/dist/model/calculationModel.d.ts.map +1 -0
- package/dist/model/calculationModel.js +206 -0
- package/dist/model/calculationModel.js.map +1 -0
- package/dist/model/cellModel.d.ts +134 -0
- package/dist/model/cellModel.d.ts.map +1 -0
- package/dist/model/cellModel.js +371 -0
- package/dist/model/cellModel.js.map +1 -0
- package/dist/model/columnModel.d.ts +160 -0
- package/dist/model/columnModel.d.ts.map +1 -0
- package/dist/model/columnModel.js +159 -0
- package/dist/model/columnModel.js.map +1 -0
- package/dist/model/commentModel.d.ts +58 -0
- package/dist/model/commentModel.d.ts.map +1 -0
- package/dist/model/commentModel.js +81 -0
- package/dist/model/commentModel.js.map +1 -0
- package/dist/model/conditionalFormats.d.ts +104 -0
- package/dist/model/conditionalFormats.d.ts.map +1 -0
- package/dist/model/conditionalFormats.js +414 -0
- package/dist/model/conditionalFormats.js.map +1 -0
- package/dist/model/cssStyle.d.ts +20 -0
- package/dist/model/cssStyle.d.ts.map +1 -0
- package/dist/model/cssStyle.js +301 -0
- package/dist/model/cssStyle.js.map +1 -0
- package/dist/model/dependencies.d.ts +30 -0
- package/dist/model/dependencies.d.ts.map +1 -0
- package/dist/model/dependencies.js +139 -0
- package/dist/model/dependencies.js.map +1 -0
- package/dist/model/dependencyModel.d.ts +9 -0
- package/dist/model/dependencyModel.d.ts.map +1 -0
- package/dist/model/dependencyModel.js +9 -0
- package/dist/model/dependencyModel.js.map +1 -0
- package/dist/model/elementModel.d.ts +103 -0
- package/dist/model/elementModel.d.ts.map +1 -0
- package/dist/model/elementModel.js +181 -0
- package/dist/model/elementModel.js.map +1 -0
- package/dist/model/filterModel.d.ts +35 -0
- package/dist/model/filterModel.d.ts.map +1 -0
- package/dist/model/filterModel.js +153 -0
- package/dist/model/filterModel.js.map +1 -0
- package/dist/model/gridModel.d.ts +181 -0
- package/dist/model/gridModel.d.ts.map +1 -0
- package/dist/model/gridModel.js +797 -0
- package/dist/model/gridModel.js.map +1 -0
- package/dist/model/groupModel.d.ts +26 -0
- package/dist/model/groupModel.d.ts.map +1 -0
- package/dist/model/groupModel.js +112 -0
- package/dist/model/groupModel.js.map +1 -0
- package/dist/model/history.d.ts +24 -0
- package/dist/model/history.d.ts.map +1 -0
- package/dist/model/history.js +35 -0
- package/dist/model/history.js.map +1 -0
- package/dist/model/index.d.ts +23 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +23 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/iterableRange.d.ts +49 -0
- package/dist/model/iterableRange.d.ts.map +1 -0
- package/dist/model/iterableRange.js +108 -0
- package/dist/model/iterableRange.js.map +1 -0
- package/dist/model/merges.d.ts +34 -0
- package/dist/model/merges.d.ts.map +1 -0
- package/dist/model/merges.js +123 -0
- package/dist/model/merges.js.map +1 -0
- package/dist/model/namingModel.d.ts +25 -0
- package/dist/model/namingModel.d.ts.map +1 -0
- package/dist/model/namingModel.js +77 -0
- package/dist/model/namingModel.js.map +1 -0
- package/dist/model/options.d.ts +257 -0
- package/dist/model/options.d.ts.map +1 -0
- package/dist/model/options.js +35 -0
- package/dist/model/options.js.map +1 -0
- package/dist/model/rowModel.d.ts +104 -0
- package/dist/model/rowModel.d.ts.map +1 -0
- package/dist/model/rowModel.js +155 -0
- package/dist/model/rowModel.js.map +1 -0
- package/dist/model/selectionModel.d.ts +19 -0
- package/dist/model/selectionModel.d.ts.map +1 -0
- package/dist/model/selectionModel.js +40 -0
- package/dist/model/selectionModel.js.map +1 -0
- package/dist/model/sortingModel.d.ts +46 -0
- package/dist/model/sortingModel.d.ts.map +1 -0
- package/dist/model/sortingModel.js +157 -0
- package/dist/model/sortingModel.js.map +1 -0
- package/dist/model/style.d.ts +90 -0
- package/dist/model/style.d.ts.map +1 -0
- package/dist/model/style.js +34 -0
- package/dist/model/style.js.map +1 -0
- package/dist/model/styleModel.d.ts +22 -0
- package/dist/model/styleModel.d.ts.map +1 -0
- package/dist/model/styleModel.js +91 -0
- package/dist/model/styleModel.js.map +1 -0
- package/dist/model/tableTheme.d.ts +46 -0
- package/dist/model/tableTheme.d.ts.map +1 -0
- package/dist/model/tableTheme.js +93 -0
- package/dist/model/tableTheme.js.map +1 -0
- package/dist/model/validations.d.ts +5 -0
- package/dist/model/validations.d.ts.map +1 -0
- package/dist/model/validations.js +24 -0
- package/dist/model/validations.js.map +1 -0
- package/dist/sparklines/index.d.ts +2 -0
- package/dist/sparklines/index.d.ts.map +1 -0
- package/dist/sparklines/index.js +2 -0
- package/dist/sparklines/index.js.map +1 -0
- package/dist/sparklines/sparklines.d.ts +59 -0
- package/dist/sparklines/sparklines.d.ts.map +1 -0
- package/dist/sparklines/sparklines.js +176 -0
- package/dist/sparklines/sparklines.js.map +1 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +11 -0
- package/dist/utils.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { CellRange } from "../common/range";
|
|
2
|
+
import { CellModel, CellSource } from "./cellModel";
|
|
3
|
+
import { GridModel } from "./gridModel";
|
|
4
|
+
import { tree } from "@omegagrid/core";
|
|
5
|
+
import { ElementModel, ElementSource } from "./elementModel";
|
|
6
|
+
/** Source object type for grid row */
|
|
7
|
+
export type RowSource = {
|
|
8
|
+
h?: number | 'auto';
|
|
9
|
+
data?: Record<string | number, any>;
|
|
10
|
+
/** if row priority is higher then column priority, row properties has precedence over column properties */
|
|
11
|
+
priority?: number;
|
|
12
|
+
} & tree.TreeNodeSource & ElementSource;
|
|
13
|
+
declare const RowModel_base: (new (...input: any[]) => {
|
|
14
|
+
index: number;
|
|
15
|
+
parentIndex: number;
|
|
16
|
+
level: number;
|
|
17
|
+
visibleIndex: number;
|
|
18
|
+
_children: any[];
|
|
19
|
+
_count: number;
|
|
20
|
+
_parent: any;
|
|
21
|
+
_collapsed: boolean;
|
|
22
|
+
_hidden: boolean;
|
|
23
|
+
_filterState: tree.FilterState;
|
|
24
|
+
_filterable: boolean;
|
|
25
|
+
_sortable: boolean;
|
|
26
|
+
populate(source: tree.TreeNodeSource): void;
|
|
27
|
+
getSourceData(): tree.TreeNodeSource;
|
|
28
|
+
get filterable(): boolean;
|
|
29
|
+
get sortable(): boolean;
|
|
30
|
+
get filterState(): tree.FilterState;
|
|
31
|
+
set filterState(v: tree.FilterState): any;
|
|
32
|
+
get hidden(): boolean;
|
|
33
|
+
set hidden(value: boolean): any;
|
|
34
|
+
get visible(): boolean;
|
|
35
|
+
get collapsed(): boolean;
|
|
36
|
+
set collapsed(value: boolean): any;
|
|
37
|
+
get parent(): any;
|
|
38
|
+
set parent(parent: any): any;
|
|
39
|
+
get children(): any[];
|
|
40
|
+
set children(value: any[]): any;
|
|
41
|
+
get hasChildren(): boolean;
|
|
42
|
+
set count(value: number): any;
|
|
43
|
+
get isLoaded(): boolean;
|
|
44
|
+
get isPartialyLoaded(): boolean;
|
|
45
|
+
get hasParent(): boolean;
|
|
46
|
+
get firstChild(): any;
|
|
47
|
+
get lastChild(): any;
|
|
48
|
+
addChild(child: any): void;
|
|
49
|
+
insertChildren(children: any[], index: number): void;
|
|
50
|
+
deleteChildren(index: number | any[], count?: number): void;
|
|
51
|
+
expand(unhide?: boolean): void;
|
|
52
|
+
collapse(): void;
|
|
53
|
+
toggleCollapse(recursive?: boolean, unhide?: boolean): void;
|
|
54
|
+
clearChildren(): void;
|
|
55
|
+
walk(cb: (m: any) => unknown | void): void;
|
|
56
|
+
walkVisible(cb: (m: any) => unknown | void): void;
|
|
57
|
+
walkUp(cb: (m: any) => unknown | void): void;
|
|
58
|
+
_sort(comparer: (a: any, b: any) => number): void;
|
|
59
|
+
sort(comparer: (a: any, b: any) => number): void;
|
|
60
|
+
}) & typeof ElementModel;
|
|
61
|
+
export declare class RowModel extends RowModel_base {
|
|
62
|
+
origIndex: number;
|
|
63
|
+
private _singleCell;
|
|
64
|
+
private _cells;
|
|
65
|
+
get cells(): CellModel[];
|
|
66
|
+
private _data;
|
|
67
|
+
get data(): Record<string | number, any>;
|
|
68
|
+
set data(v: Record<string | number, any>);
|
|
69
|
+
private _height;
|
|
70
|
+
get height(): number;
|
|
71
|
+
set height(value: number);
|
|
72
|
+
private _priority;
|
|
73
|
+
get priority(): number;
|
|
74
|
+
set priority(value: number);
|
|
75
|
+
get address(): string;
|
|
76
|
+
get range(): CellRange;
|
|
77
|
+
get hasFormula(): boolean;
|
|
78
|
+
get formula(): string;
|
|
79
|
+
set formula(v: string);
|
|
80
|
+
get values(): unknown[];
|
|
81
|
+
isCellInitialized: (c: number) => boolean;
|
|
82
|
+
cell(c: number, source?: CellSource): CellModel;
|
|
83
|
+
constructor(model: GridModel, source?: RowSource);
|
|
84
|
+
populate(source: RowSource): void;
|
|
85
|
+
getSourceData(): RowSource;
|
|
86
|
+
expand(unhide?: boolean): void;
|
|
87
|
+
collapse(): void;
|
|
88
|
+
get prev(): RowModel;
|
|
89
|
+
get next(): RowModel;
|
|
90
|
+
get prevVisible(): RowModel;
|
|
91
|
+
get nextVisible(): RowModel;
|
|
92
|
+
/**
|
|
93
|
+
* Checks if cell has formula, even for uninitialized cells
|
|
94
|
+
* @param c number
|
|
95
|
+
* @returns boolean
|
|
96
|
+
*/
|
|
97
|
+
hasCellFormula(c: number): any;
|
|
98
|
+
hasCellName(c: number): boolean;
|
|
99
|
+
insertColumns(index: number, count: number, shiftFormulas?: boolean): void;
|
|
100
|
+
deleteColumns(index: number, count: number, shiftFormulas?: boolean): CellModel[];
|
|
101
|
+
clearCalculatedValues(): void;
|
|
102
|
+
}
|
|
103
|
+
export {};
|
|
104
|
+
//# sourceMappingURL=rowModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rowModel.d.ts","sourceRoot":"","sources":["../../src/model/rowModel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAa,MAAM,iBAAiB,CAAC;AACvD,OAA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K,cAA+D;IAExE,IAAI,UAAU,YAA6B;IAC3C,IAAI,OAAO,IACI,MAAM,CADiB;IACtC,IAAI,OAAO,CAAC,CAAC,EAAE,MAAM,EAGpB;IAED,IAAI,MAAM,cAAuE;IAEjF,iBAAiB,GAAI,GAAG,MAAM,aAAqB;IAEnD,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,GAAI,SAAS;gBA2BpC,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,SAAS;IAMhD,QAAQ,CAAC,MAAM,EAAE,SAAS;IAY1B,aAAa;IAOb,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO;IAKvB,QAAQ;IAKR,IAAI,IAAI,aAA6C;IACrD,IAAI,IAAI,aAA6C;IAErD,IAAI,WAAW,IAAK,QAAQ,CAI3B;IAED,IAAI,WAAW,IAAK,QAAQ,CAI3B;IAED;;;;OAIG;IACH,cAAc,CAAC,CAAC,EAAE,MAAM;IAKxB,WAAW,CAAC,CAAC,EAAE,MAAM;IAKrB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,UAAQ;IAqBjE,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,UAAQ;IAqBjE,qBAAqB;CAIrB"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { CellRange, encodeRow } from "../common/range";
|
|
3
|
+
import { CellModel } from "./cellModel";
|
|
4
|
+
import { tree, utils } from "@omegagrid/core";
|
|
5
|
+
import { ElementModel } from "./elementModel";
|
|
6
|
+
export class RowModel extends tree.TreeNodeMixin(ElementModel) {
|
|
7
|
+
get cells() { return this._cells; }
|
|
8
|
+
get data() { return this._data; }
|
|
9
|
+
set data(v) { this._data = v; }
|
|
10
|
+
get height() { return this._height ?? this.model.options.rowHeight; }
|
|
11
|
+
set height(value) { this._height = value; }
|
|
12
|
+
get priority() { return this._priority; }
|
|
13
|
+
set priority(value) { this._priority = value; }
|
|
14
|
+
get address() { return encodeRow(this.index); }
|
|
15
|
+
get range() { return new CellRange(null, this.index, null, this.index); }
|
|
16
|
+
get hasFormula() { return !!this._formula; }
|
|
17
|
+
get formula() { return this._formula; }
|
|
18
|
+
set formula(v) {
|
|
19
|
+
super.formula = v;
|
|
20
|
+
this.model.columns.forEach(col => this.cell(col.index).refreshFormula());
|
|
21
|
+
}
|
|
22
|
+
get values() { return this.model.columns.map(col => this.cell(col.index).value); }
|
|
23
|
+
cell(c, source) {
|
|
24
|
+
if (this.model.options.singleCellModel) {
|
|
25
|
+
if (!this._singleCell)
|
|
26
|
+
this._singleCell = new CellModel(this.model, { c: c, r: this.index });
|
|
27
|
+
this._singleCell.row = this;
|
|
28
|
+
this._singleCell.column = this.model.columns[c];
|
|
29
|
+
return this._singleCell;
|
|
30
|
+
}
|
|
31
|
+
let cell = this._cells[c];
|
|
32
|
+
if ((source || !cell) && this.model.columns[c]) {
|
|
33
|
+
cell = new CellModel(this.model, source ?? { c: c, r: this.index });
|
|
34
|
+
if (this._data) {
|
|
35
|
+
const dataField = this.model.columns[c].data;
|
|
36
|
+
if (dataField != null) {
|
|
37
|
+
const d = this._data[dataField];
|
|
38
|
+
if (utils.isObject(d)) {
|
|
39
|
+
if (d.comment)
|
|
40
|
+
this.model.comments.set(cell.address, [d.comment]);
|
|
41
|
+
cell.populate(d);
|
|
42
|
+
}
|
|
43
|
+
else if (!cell.hasValue)
|
|
44
|
+
cell.value = d;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (cell.name)
|
|
48
|
+
this.model.names.set(cell.name, cell.range);
|
|
49
|
+
this._cells[c] = cell;
|
|
50
|
+
}
|
|
51
|
+
return cell;
|
|
52
|
+
}
|
|
53
|
+
constructor(model, source) {
|
|
54
|
+
super(model, source);
|
|
55
|
+
this.isCellInitialized = (c) => !!this.cells[c];
|
|
56
|
+
this._cells = [];
|
|
57
|
+
if (this._priority == null)
|
|
58
|
+
this._priority = model.options.rowPriority;
|
|
59
|
+
}
|
|
60
|
+
populate(source) {
|
|
61
|
+
super.populate(source);
|
|
62
|
+
this._height = source.h == null || source.h == 'auto' ? this.model.options.rowHeight : source.h;
|
|
63
|
+
if (source.data) {
|
|
64
|
+
if (Array.isArray(source.data))
|
|
65
|
+
this._data = [...source.data];
|
|
66
|
+
else
|
|
67
|
+
this._data = { ...source.data };
|
|
68
|
+
}
|
|
69
|
+
if (source.priority != null)
|
|
70
|
+
this._priority = source.priority;
|
|
71
|
+
}
|
|
72
|
+
getSourceData() {
|
|
73
|
+
const data = super.getSourceData();
|
|
74
|
+
//if (this._data != null) data.data = this._data;
|
|
75
|
+
if (this._height != null && this._height != this.model.options.rowHeight)
|
|
76
|
+
data.h = this._height;
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
expand(unhide) {
|
|
80
|
+
super.expand(unhide);
|
|
81
|
+
this.model.indexVisibleRows();
|
|
82
|
+
}
|
|
83
|
+
collapse() {
|
|
84
|
+
super.collapse();
|
|
85
|
+
this.model.indexVisibleRows();
|
|
86
|
+
}
|
|
87
|
+
get prev() { return this.model.rows[this.index - 1]; }
|
|
88
|
+
get next() { return this.model.rows[this.index + 1]; }
|
|
89
|
+
get prevVisible() {
|
|
90
|
+
let prev = this.prev;
|
|
91
|
+
while (prev && !prev.visible)
|
|
92
|
+
prev = prev.prev;
|
|
93
|
+
return prev;
|
|
94
|
+
}
|
|
95
|
+
get nextVisible() {
|
|
96
|
+
let next = this.next;
|
|
97
|
+
while (next && !next.visible)
|
|
98
|
+
next = next.next;
|
|
99
|
+
return next;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Checks if cell has formula, even for uninitialized cells
|
|
103
|
+
* @param c number
|
|
104
|
+
* @returns boolean
|
|
105
|
+
*/
|
|
106
|
+
hasCellFormula(c) {
|
|
107
|
+
return (this.cells[c] && this.cells[c].hasFormula)
|
|
108
|
+
|| (this._data && this._data[this.model.columns[c].data] && this._data[this.model.columns[c].data].f);
|
|
109
|
+
}
|
|
110
|
+
hasCellName(c) {
|
|
111
|
+
return (this.cells[c] && this.cells[c].name != null)
|
|
112
|
+
|| (this._data && this._data[this.model.columns[c].data] && this._data[this.model.columns[c].data].name != null);
|
|
113
|
+
}
|
|
114
|
+
insertColumns(index, count, shiftFormulas = false) {
|
|
115
|
+
let cell;
|
|
116
|
+
const columns = this.model.columns.length;
|
|
117
|
+
const calculations = this.model.calculations;
|
|
118
|
+
if (shiftFormulas) {
|
|
119
|
+
for (let c = 0; c < columns; c++) {
|
|
120
|
+
if (this.hasCellFormula(c)) {
|
|
121
|
+
cell = this.cell(c);
|
|
122
|
+
cell.formula = calculations.getFormula(cell).shift({
|
|
123
|
+
index: index,
|
|
124
|
+
offset: count,
|
|
125
|
+
direction: 'right'
|
|
126
|
+
}).createFormulaString(false);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (index < this.cells.length)
|
|
131
|
+
this.cells.splice(index, 0, ...Array(count).fill(null));
|
|
132
|
+
}
|
|
133
|
+
deleteColumns(index, count, shiftFormulas = false) {
|
|
134
|
+
let cell;
|
|
135
|
+
const columns = this.model.columns.length;
|
|
136
|
+
const calculations = this.model.calculations;
|
|
137
|
+
if (shiftFormulas) {
|
|
138
|
+
for (let c = 0; c < columns; c++) {
|
|
139
|
+
if (this.hasCellFormula(c)) {
|
|
140
|
+
cell = this.cell(c);
|
|
141
|
+
cell.formula = calculations.getFormula(cell).shift({
|
|
142
|
+
index: index,
|
|
143
|
+
offset: count,
|
|
144
|
+
direction: 'left'
|
|
145
|
+
}).createFormulaString(false);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return index < this.cells.length ? this.cells.splice(index, count) : null;
|
|
150
|
+
}
|
|
151
|
+
clearCalculatedValues() {
|
|
152
|
+
this.cells.forEach(cell => cell && this.model.calculations.refreshFormula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AC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACxF,CAAC;IAED,aAAa,CAAC,KAAa,EAAE,KAAa,EAAE,aAAa,GAAG,KAAK;QAChE,IAAI,IAAe,CAAC;QACpB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QAC1C,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;QAE7C,IAAI,aAAa,EAAE,CAAC;YACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC;gBAClC,IAAI,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC5B,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBACpB,IAAI,CAAC,OAAO,GAAG,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC;wBAClD,KAAK,EAAE,KAAK;wBACZ,MAAM,EAAE,KAAK;wBACb,SAAS,EAAE,MAAM;qBACjB,CAAC,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;gBAC/B,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3E,CAAC;IAED,qBAAqB;QACpB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;IAClF,CAAC;CAED","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { CellRange, encodeRow } from \"../common/range\";\nimport { CellModel, CellSource } from \"./cellModel\";\nimport { GridModel } from \"./gridModel\";\nimport { tree, utils } from \"@omegagrid/core\";\nimport { ElementModel, ElementSource } from \"./elementModel\";\n\n// /** Source object type for row header item */\n// export type RowHeaderModel = {\n// \tlabel?: string;\n// \tcolspan?: number;\n// \trowspan?: number;\n// \twidth?: number;\n// };\n\n/** Source object type for grid row */\nexport type RowSource = {\n\th?: number|'auto', // height\n\tdata?: Record<string|number, any>,\n\t/** if row priority is higher then column priority, row properties has precedence over column properties */\n\tpriority?: number,\n} & tree.TreeNodeSource & ElementSource\n\nexport class RowModel extends tree.TreeNodeMixin(ElementModel) {\n\n\torigIndex: number;\n\t\n\tprivate _singleCell: CellModel;\n\n\tprivate _cells: CellModel[];\n\tget cells() { return this._cells }\n\t\n\tprivate _data: Record<string|number, any>;\n\tget data() { return this._data }\n\tset data(v : Record<string|number, any>) { this._data = v }\n\t\n\tprivate _height: number;\n\tget height() { return this._height ?? this.model.options.rowHeight }\n\tset height(value: number) { this._height = value }\n\t\n\tprivate _priority: number;\n\tget priority() { return this._priority }\n\tset priority(value: number) { this._priority = value }\n\n\tget address() { return encodeRow(this.index) }\n\tget range() { return new CellRange(null, this.index, null, this.index) }\n\n\tget hasFormula() { return !!this._formula }\n\tget formula() { return this._formula }\n\tset formula(v: string) {\n\t\tsuper.formula = v;\n\t\tthis.model.columns.forEach(col => this.cell(col.index).refreshFormula());\n\t}\n\n\tget values() { return this.model.columns.map(col => this.cell(col.index).value) }\n\n\tisCellInitialized = (c: number) => !!this.cells[c];\n\t\n\tcell(c: number, source?: CellSource) : CellModel {\n\t\tif (this.model.options.singleCellModel) {\n\t\t\tif (!this._singleCell) this._singleCell = new CellModel(this.model, {c: c, r: this.index});\n\t\t\tthis._singleCell.row = this;\n\t\t\tthis._singleCell.column = this.model.columns[c];\n\t\t\treturn this._singleCell;\n\t\t}\n\n\t\tlet cell = this._cells[c];\n\t\tif ((source || !cell) && this.model.columns[c]) {\n\t\t\tcell = new CellModel(this.model, source ?? {c: c, r: this.index});\n\t\t\tif (this._data) {\n\t\t\t\tconst dataField = this.model.columns[c].data;\n\t\t\t\tif (dataField != null) {\n\t\t\t\t\tconst d = this._data[dataField];\n\t\t\t\t\tif (utils.isObject(d)) {\n\t\t\t\t\t\tif ((d as CellSource).comment) this.model.comments.set(cell.address, [(d as CellSource).comment]);\n\t\t\t\t\t\tcell.populate(d);\n\t\t\t\t\t} else if (!cell.hasValue) cell.value = d;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (cell.name) this.model.names.set(cell.name, cell.range);\n\t\t\tthis._cells[c] = cell;\n\t\t}\n\t\treturn cell;\n\t}\n\n\tconstructor(model: GridModel, source?: RowSource) {\n\t\tsuper(model, source);\n\t\tthis._cells = [];\n\t\tif (this._priority == null) this._priority = model.options.rowPriority;\n\t}\n\n\tpopulate(source: RowSource) {\n\t\tsuper.populate(source);\n\t\tthis._height = source.h == null || source.h == 'auto' ? this.model.options.rowHeight : source.h;\n\n\t\tif (source.data) {\n\t\t\tif (Array.isArray(source.data)) this._data = [...source.data];\n\t\t\telse this._data = {...source.data};\n\t\t}\n\n\t\tif (source.priority != null) this._priority = source.priority;\n\t}\n\n\tgetSourceData() {\n\t\tconst data = super.getSourceData() as RowSource;\n\t\t//if (this._data != null) data.data = this._data;\n\t\tif (this._height != null && this._height != this.model.options.rowHeight) data.h = this._height;\n\t\treturn data;\n\t}\n\n\texpand(unhide?: boolean) {\n\t\tsuper.expand(unhide);\n\t\tthis.model.indexVisibleRows();\n\t}\n\n\tcollapse() {\n\t\tsuper.collapse();\n\t\tthis.model.indexVisibleRows();\n\t}\n\n\tget prev() { return this.model.rows[this.index - 1] }\n\tget next() { return this.model.rows[this.index + 1] }\n\n\tget prevVisible() : RowModel {\n\t\tlet prev = this.prev;\n\t\twhile (prev && !prev.visible) prev = prev.prev;\n\t\treturn prev;\n\t}\n\n\tget nextVisible() : RowModel {\n\t\tlet next = this.next;\n\t\twhile (next && !next.visible) next = next.next;\n\t\treturn next;\n\t}\n\n\t/**\n\t * Checks if cell has formula, even for uninitialized cells\n\t * @param c number\n\t * @returns boolean\n\t */\n\thasCellFormula(c: number) {\n\t\treturn (this.cells[c] && this.cells[c].hasFormula)\n\t\t\t|| (this._data && this._data[this.model.columns[c].data] && this._data[this.model.columns[c].data].f);\n\t}\n\n\thasCellName(c: number) {\n\t\treturn (this.cells[c] && this.cells[c].name != null)\n\t\t\t|| (this._data && this._data[this.model.columns[c].data] && this._data[this.model.columns[c].data].name != null);\n\t}\n\n\tinsertColumns(index: number, count: number, shiftFormulas = false) {\n\t\tlet cell: CellModel;\n\t\tconst columns = this.model.columns.length;\n\t\tconst calculations = this.model.calculations;\n\n\t\tif (shiftFormulas) {\n\t\t\tfor (let c = 0; c < columns; c++) {\n\t\t\t\tif (this.hasCellFormula(c)) {\n\t\t\t\t\tcell = this.cell(c);\n\t\t\t\t\tcell.formula = calculations.getFormula(cell).shift({\n\t\t\t\t\t\tindex: index, \n\t\t\t\t\t\toffset: count, \n\t\t\t\t\t\tdirection: 'right'\n\t\t\t\t\t}).createFormulaString(false);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (index < this.cells.length) this.cells.splice(index, 0, ...Array(count).fill(null));\n\t}\n\n\tdeleteColumns(index: number, count: number, shiftFormulas = false) {\n\t\tlet cell: CellModel;\n\t\tconst columns = this.model.columns.length;\n\t\tconst calculations = this.model.calculations;\n\n\t\tif (shiftFormulas) {\n\t\t\tfor (let c = 0; c < columns; c++) {\n\t\t\t\tif (this.hasCellFormula(c)) {\n\t\t\t\t\tcell = this.cell(c);\n\t\t\t\t\tcell.formula = calculations.getFormula(cell).shift({\n\t\t\t\t\t\tindex: index, \n\t\t\t\t\t\toffset: count,\n\t\t\t\t\t\tdirection: 'left'\n\t\t\t\t\t}).createFormulaString(false);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn index < this.cells.length ? this.cells.splice(index, count) : null;\n\t}\n\n\tclearCalculatedValues() {\n\t\tthis.cells.forEach(cell => cell && this.model.calculations.refreshFormula(cell));\n\t}\n\n}"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CellRange } from "../common/range";
|
|
2
|
+
export declare class SelectionModel {
|
|
3
|
+
range: CellRange;
|
|
4
|
+
activeCell: CellRange;
|
|
5
|
+
color: string;
|
|
6
|
+
hidden: boolean;
|
|
7
|
+
get activeCellCoords(): {
|
|
8
|
+
c: number;
|
|
9
|
+
r: number;
|
|
10
|
+
};
|
|
11
|
+
constructor(c1: number, r1: number, c2?: number, r2?: number);
|
|
12
|
+
static fromRange(r: CellRange): SelectionModel;
|
|
13
|
+
setCoords(c1?: number, r1?: number, c2?: number, r2?: number): void;
|
|
14
|
+
setRange(range: CellRange | string): void;
|
|
15
|
+
move(c: number, r: number, maxColumns?: number, maxRows?: number): void;
|
|
16
|
+
moveRange(c: number, r: number, maxColumns?: number, maxRows?: number): void;
|
|
17
|
+
moveActiveCell(c: number, r: number): void;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=selectionModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectionModel.d.ts","sourceRoot":"","sources":["../../src/model/selectionModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,qBAAa,cAAc;IAE1B,KAAK,EAAE,SAAS,CAAC;IACjB,UAAU,EAAE,SAAS,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,UAAS;IAEf,IAAI,gBAAgB,IAAI;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAC,CAK7C;gBAEW,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM;IAK5D,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS;IAI7B,SAAS,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM;IAK5D,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAC,MAAM;IAMhC,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAWhE,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;IAIrE,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM;CAKnC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CellRange } from "../common/range";
|
|
2
|
+
export class SelectionModel {
|
|
3
|
+
get activeCellCoords() {
|
|
4
|
+
return {
|
|
5
|
+
c: this.range.c1 + this.activeCell.c1,
|
|
6
|
+
r: this.range.r1 + this.activeCell.r1
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
constructor(c1, r1, c2, r2) {
|
|
10
|
+
this.hidden = false;
|
|
11
|
+
this.range = new CellRange(c1, r1, c2, r2);
|
|
12
|
+
this.activeCell = new CellRange(0, 0);
|
|
13
|
+
}
|
|
14
|
+
static fromRange(r) {
|
|
15
|
+
return new SelectionModel(r.c1, r.r1, r.c2, r.r2);
|
|
16
|
+
}
|
|
17
|
+
setCoords(c1, r1, c2, r2) {
|
|
18
|
+
this.range.setCoords(c1, r1, c2, r2);
|
|
19
|
+
this.activeCell.setCoords(0, 0);
|
|
20
|
+
}
|
|
21
|
+
setRange(range) {
|
|
22
|
+
if (typeof range === 'string')
|
|
23
|
+
range = CellRange.fromA1(range);
|
|
24
|
+
this.range.setCoords(range.c1, range.r1, range.c2, range.r2);
|
|
25
|
+
this.activeCell.setCoords(0, 0);
|
|
26
|
+
}
|
|
27
|
+
move(c, r, maxColumns, maxRows) {
|
|
28
|
+
this.range.setCoords(this.range.c1 + this.activeCell.c1, this.range.r1 + this.activeCell.r1, this.range.c1 + this.activeCell.c2, this.range.r1 + this.activeCell.r2);
|
|
29
|
+
this.range.move(c, r, maxColumns, maxRows, false);
|
|
30
|
+
this.activeCell.setCoords(0, 0);
|
|
31
|
+
}
|
|
32
|
+
moveRange(c, r, maxColumns, maxRows) {
|
|
33
|
+
this.range.move(c, r, maxColumns, maxRows, true);
|
|
34
|
+
}
|
|
35
|
+
moveActiveCell(c, r) {
|
|
36
|
+
const { columns, rows } = this.range.size;
|
|
37
|
+
this.activeCell.move(c, r, columns, rows, true);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=selectionModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectionModel.js","sourceRoot":"","sources":["../../src/model/selectionModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,cAAc;IAO1B,IAAI,gBAAgB;QACnB,OAAO;YACN,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE;YACrC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE;SACrC,CAAA;IACF,CAAC;IAED,YAAY,EAAU,EAAE,EAAU,EAAE,EAAW,EAAE,EAAW;QAT5D,WAAM,GAAG,KAAK,CAAC;QAUd,IAAI,CAAC,KAAK,GAAG,IAAI,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,UAAU,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,CAAY;QAC5B,OAAO,IAAI,cAAc,CAAC,CAAC,CAAC,EAA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AAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACjC,CAAC;IAED,SAAS,CAAC,CAAS,EAAE,CAAS,EAAE,UAAmB,EAAE,OAAgB;QACpE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;IAED,cAAc,CAAC,CAAS,EAAE,CAAS;QAClC,MAAM,EAAC,OAAO,EAAE,IAAI,EAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;QACxC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACjD,CAAC;CAED","sourcesContent":["import { CellRange } from \"../common/range\";\n\nexport class SelectionModel {\n\t\n\trange: CellRange;\n\tactiveCell: CellRange;\n\tcolor: string;\n\thidden = false;\n\n\tget activeCellCoords(): {c: number, r: number} {\n\t\treturn {\n\t\t\tc: this.range.c1 + this.activeCell.c1,\n\t\t\tr: this.range.r1 + this.activeCell.r1\n\t\t}\n\t}\n\n\tconstructor(c1: number, r1: number, c2?: number, r2?: number) { \n\t\tthis.range = new CellRange(c1, r1, c2, r2);\n\t\tthis.activeCell = new CellRange(0, 0);\n\t}\n\n\tstatic fromRange(r: CellRange) {\n\t\treturn new SelectionModel(r.c1, r.r1, r.c2, r.r2);\n\t}\n\n\tsetCoords(c1?: number, r1?: number, c2?: number, r2?: number) {\n\t\tthis.range.setCoords(c1, r1, c2, r2);\n\t\tthis.activeCell.setCoords(0, 0);\n\t}\n\n\tsetRange(range: CellRange|string) {\n\t\tif (typeof range === 'string') range = CellRange.fromA1(range);\n\t\tthis.range.setCoords(range.c1, range.r1, range.c2, range.r2);\n\t\tthis.activeCell.setCoords(0, 0);\n\t}\n\n\tmove(c: number, r: number, maxColumns?: number, maxRows?: number) {\n\t\tthis.range.setCoords(\n\t\t\tthis.range.c1 + this.activeCell.c1, \n\t\t\tthis.range.r1 + this.activeCell.r1, \n\t\t\tthis.range.c1 + this.activeCell.c2, \n\t\t\tthis.range.r1 + this.activeCell.r2\n\t\t);\n\t\tthis.range.move(c, r, maxColumns, maxRows, false);\n\t\tthis.activeCell.setCoords(0, 0);\n\t}\n\n\tmoveRange(c: number, r: number, maxColumns?: number, maxRows?: number) {\n\t\tthis.range.move(c, r, maxColumns, maxRows, true);\n\t}\n\n\tmoveActiveCell(c: number, r: number) {\n\t\tconst {columns, rows} = this.range.size;\n\t\tthis.activeCell.move(c, r, columns, rows, true);\n\t}\n\n}"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { GridModel } from "./gridModel";
|
|
2
|
+
export declare enum SortOrder {
|
|
3
|
+
Asc = 1,
|
|
4
|
+
Desc = -1
|
|
5
|
+
}
|
|
6
|
+
export type SortSettings = {
|
|
7
|
+
c: number;
|
|
8
|
+
ord: SortOrder;
|
|
9
|
+
index?: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Class for sorting rows by columns sort settings
|
|
13
|
+
*/
|
|
14
|
+
export declare class SortingModel {
|
|
15
|
+
readonly model: GridModel;
|
|
16
|
+
private colMap;
|
|
17
|
+
private _settings;
|
|
18
|
+
get settings(): SortSettings[] | null;
|
|
19
|
+
set settings(v: SortSettings[] | null);
|
|
20
|
+
constructor(model: GridModel, _settings?: SortSettings[] | null);
|
|
21
|
+
/**
|
|
22
|
+
* Get sorting settings for specified column
|
|
23
|
+
* @param c column index
|
|
24
|
+
*/
|
|
25
|
+
get(c: number): SortSettings;
|
|
26
|
+
/**
|
|
27
|
+
* Add sorting settings for specified column
|
|
28
|
+
* @param c column index
|
|
29
|
+
* @param ord sorting order
|
|
30
|
+
* @param custom if true, sorting will not be automaticaly applied
|
|
31
|
+
*/
|
|
32
|
+
sort(c: number, ord?: SortOrder, custom?: boolean): SortSettings;
|
|
33
|
+
/**
|
|
34
|
+
* Apply current sorting settings to rows
|
|
35
|
+
*/
|
|
36
|
+
applySort(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Reset row order to default state
|
|
39
|
+
*/
|
|
40
|
+
resetSort(): void;
|
|
41
|
+
/**
|
|
42
|
+
* Use current sorting settings as default row order
|
|
43
|
+
*/
|
|
44
|
+
persistSort(): void;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=sortingModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortingModel.d.ts","sourceRoot":"","sources":["../../src/model/sortingModel.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,oBAAY,SAAS;IACpB,GAAG,IAAI;IACP,IAAI,KAAK;CACT;AAED,MAAM,MAAM,YAAY,GAAG;IAC1B,CAAC,EAAE,MAAM,CAAC;IACV,GAAG,EAAE,SAAS,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACd,CAAC;AAgCF;;GAEG;AACH,qBAAa,YAAY;aAiBP,KAAK,EAAE,SAAS;IAfjC,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,SAAS,CAAsB;IAEvC,IAAI,QAAQ,IACI,YAAY,EAAE,GAAC,IAAI,CADK;IACxC,IAAI,QAAQ,CAAC,CAAC,EAAE,YAAY,EAAE,GAAC,IAAI,EAQlC;gBAGgB,KAAK,EAAE,SAAS,EAChC,SAAS,GAAE,YAAY,EAAE,GAAC,IAAW;IAKtC;;;OAGG;IACH,GAAG,CAAC,CAAC,EAAE,MAAM;IAIb;;;;;OAKG;IACH,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,GAAE,SAAgB,EAAE,MAAM,UAAQ,GAAG,YAAY;IAuCpE;;OAEG;IACH,SAAS;IAuCT;;OAEG;IACH,SAAS;IAOT;;OAEG;IACH,WAAW;CAIX"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { log } from "@omegagrid/core";
|
|
2
|
+
export var SortOrder;
|
|
3
|
+
(function (SortOrder) {
|
|
4
|
+
SortOrder[SortOrder["Asc"] = 1] = "Asc";
|
|
5
|
+
SortOrder[SortOrder["Desc"] = -1] = "Desc";
|
|
6
|
+
})(SortOrder || (SortOrder = {}));
|
|
7
|
+
const ascComparers = {
|
|
8
|
+
'g': (a, b) => a.value == b.value ? 0 : (a.value > b.value ? 1 : -1),
|
|
9
|
+
't': (a, b) => (a.value || '').toString().localeCompare((b.value || '').toString()),
|
|
10
|
+
's': (a, b) => a.value == b.value ? 0 : (a.value > b.value ? 1 : -1),
|
|
11
|
+
'm': (a, b) => a.value == b.value ? 0 : (a.value > b.value ? 1 : -1),
|
|
12
|
+
'n': (a, b) => a.value - b.value,
|
|
13
|
+
'd': (a, b) => (a.value instanceof Date ? a.value.getTime() : 0) - (b.value instanceof Date ? b.value.getTime() : 0),
|
|
14
|
+
'tm': (a, b) => (a.value instanceof Date ? a.value.getTime() : 0) - (b.value instanceof Date ? b.value.getTime() : 0),
|
|
15
|
+
'dt': (a, b) => (a.value instanceof Date ? a.value.getTime() : 0) - (b.value instanceof Date ? b.value.getTime() : 0),
|
|
16
|
+
'b': (a, b) => a.value - b.value,
|
|
17
|
+
'h': (a, b) => (a.value || '').localeCompare(b.value),
|
|
18
|
+
'a': () => 0
|
|
19
|
+
};
|
|
20
|
+
const descComparers = {
|
|
21
|
+
'g': (b, a) => a.value == b.value ? 0 : (a.value > b.value ? 1 : -1),
|
|
22
|
+
't': (b, a) => (a.value || '').toString().localeCompare((b.value || '').toString()),
|
|
23
|
+
's': (b, a) => a.value == b.value ? 0 : (a.value > b.value ? 1 : -1),
|
|
24
|
+
'm': (b, a) => a.value == b.value ? 0 : (a.value > b.value ? 1 : -1),
|
|
25
|
+
'n': (b, a) => a.value - b.value,
|
|
26
|
+
'd': (b, a) => (a.value instanceof Date ? a.value.getTime() : 0) - (b.value instanceof Date ? b.value.getTime() : 0),
|
|
27
|
+
'tm': (b, a) => (a.value instanceof Date ? a.value.getTime() : 0) - (b.value instanceof Date ? b.value.getTime() : 0),
|
|
28
|
+
'dt': (b, a) => (a.value instanceof Date ? a.value.getTime() : 0) - (b.value instanceof Date ? b.value.getTime() : 0),
|
|
29
|
+
'b': (b, a) => a.value - b.value,
|
|
30
|
+
'h': (b, a) => (a.value || '').localeCompare(b.value),
|
|
31
|
+
'a': () => 0
|
|
32
|
+
};
|
|
33
|
+
const origComparer = (a, b) => a.origIndex - b.origIndex;
|
|
34
|
+
/**
|
|
35
|
+
* Class for sorting rows by columns sort settings
|
|
36
|
+
*/
|
|
37
|
+
export class SortingModel {
|
|
38
|
+
get settings() { return this._settings; }
|
|
39
|
+
set settings(v) {
|
|
40
|
+
this._settings = v || [];
|
|
41
|
+
this.colMap.clear();
|
|
42
|
+
if (this.settings.length > 0) {
|
|
43
|
+
this.settings.forEach((s, i) => this.colMap.set(s.c, i));
|
|
44
|
+
this.applySort();
|
|
45
|
+
log.getLogger().info(`sorting applied: ${JSON.stringify(this.settings)}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
constructor(model, _settings = null) {
|
|
49
|
+
this.model = model;
|
|
50
|
+
this.colMap = new Map();
|
|
51
|
+
this._settings = [];
|
|
52
|
+
this.settings = _settings;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get sorting settings for specified column
|
|
56
|
+
* @param c column index
|
|
57
|
+
*/
|
|
58
|
+
get(c) {
|
|
59
|
+
return this.colMap.has(c) ? this.settings[this.colMap.get(c)] : null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Add sorting settings for specified column
|
|
63
|
+
* @param c column index
|
|
64
|
+
* @param ord sorting order
|
|
65
|
+
* @param custom if true, sorting will not be automaticaly applied
|
|
66
|
+
*/
|
|
67
|
+
sort(c, ord = null, custom = false) {
|
|
68
|
+
let sortSetting = this.get(c);
|
|
69
|
+
if (sortSetting && sortSetting.ord == SortOrder.Desc && ord === null) {
|
|
70
|
+
this.settings.splice(this.colMap.get(c), 1);
|
|
71
|
+
sortSetting = null;
|
|
72
|
+
}
|
|
73
|
+
else if (sortSetting) {
|
|
74
|
+
sortSetting.ord = SortOrder.Desc;
|
|
75
|
+
this.settings.splice(this.colMap.get(c), 1);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
sortSetting = { c: c, ord: SortOrder.Asc };
|
|
79
|
+
}
|
|
80
|
+
if (sortSetting) {
|
|
81
|
+
if (ord !== null)
|
|
82
|
+
sortSetting.ord = ord;
|
|
83
|
+
this.colMap.set(c, 0);
|
|
84
|
+
this.settings.unshift(sortSetting);
|
|
85
|
+
}
|
|
86
|
+
if (this.settings.length > this.model.options.maxSortingColumns) {
|
|
87
|
+
this.settings.pop();
|
|
88
|
+
}
|
|
89
|
+
this.colMap.clear();
|
|
90
|
+
this.settings.forEach((s, i) => {
|
|
91
|
+
s.index = i;
|
|
92
|
+
this.colMap.set(s.c, i);
|
|
93
|
+
});
|
|
94
|
+
if (!custom) {
|
|
95
|
+
if (this.settings.length > 0) {
|
|
96
|
+
this.applySort();
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
this.resetSort();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return sortSetting;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Apply current sorting settings to rows
|
|
106
|
+
*/
|
|
107
|
+
applySort() {
|
|
108
|
+
const m = this.model;
|
|
109
|
+
const cellComparers = this.settings.map(s => {
|
|
110
|
+
const column = m.columns[s.c];
|
|
111
|
+
if (!column) {
|
|
112
|
+
log.getLogger().warn(`Column sorting: Column with index ${s.c} not found`);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (column.comparer)
|
|
116
|
+
return s.ord == SortOrder.Asc
|
|
117
|
+
? column.comparer
|
|
118
|
+
: (a, b) => -column.comparer(a, b);
|
|
119
|
+
return s.ord == SortOrder.Asc
|
|
120
|
+
? ascComparers[column.type ?? 't']
|
|
121
|
+
: descComparers[column.type ?? 't'];
|
|
122
|
+
}).filter(c => c);
|
|
123
|
+
const len = cellComparers.length;
|
|
124
|
+
let ord, i, c;
|
|
125
|
+
const rowComparer = (a, b) => {
|
|
126
|
+
if (a.sortable === false || b.sortable === false) {
|
|
127
|
+
// if sorting for one of the rows is disabled, use original index for comparison
|
|
128
|
+
return a.origIndex - b.origIndex;
|
|
129
|
+
}
|
|
130
|
+
for (i = 0; i < len; i++) {
|
|
131
|
+
c = this.settings[i].c;
|
|
132
|
+
ord = cellComparers[i](a.cell(c), b.cell(c));
|
|
133
|
+
if (ord != 0)
|
|
134
|
+
return ord;
|
|
135
|
+
}
|
|
136
|
+
return 0;
|
|
137
|
+
};
|
|
138
|
+
m.rowRoot.sort(rowComparer);
|
|
139
|
+
m.indexRowsByTree();
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Reset row order to default state
|
|
143
|
+
*/
|
|
144
|
+
resetSort() {
|
|
145
|
+
this.settings = [];
|
|
146
|
+
this.colMap.clear();
|
|
147
|
+
this.model.rowRoot.sort(origComparer);
|
|
148
|
+
this.model.indexRowsByTree();
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Use current sorting settings as default row order
|
|
152
|
+
*/
|
|
153
|
+
persistSort() {
|
|
154
|
+
this.model.rows.forEach((r, i) => r.origIndex = i);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=sortingModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sortingModel.js","sourceRoot":"","sources":["../../src/model/sortingModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAMnD,MAAM,CAAN,IAAY,SAGX;AAHD,WAAY,SAAS;IACpB,uCAAO,CAAA;IACP,0CAAS,CAAA;AACV,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;AAQD,MAAM,YAAY,GAAuD;IACxE,GAAG,EAAE,CAAC,CAAY,EAAE,C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AAI,CAAC,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC;gBAClD,gFAAgF;gBAChF,OAAO,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;YAClC,CAAC;YAED,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC1B,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACvB,GAAG,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC7C,IAAI,GAAG,IAAI,CAAC;oBAAE,OAAO,GAAG,CAAC;YAC1B,CAAC;YACD,OAAO,CAAC,CAAC;QACV,CAAC,CAAC;QAEF,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC5B,CAAC,CAAC,eAAe,EAAE,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,SAAS;QACR,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtC,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,WAAW;QACV,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;IACpD,CAAC;CAED","sourcesContent":["import { UIValueType, log } from \"@omegagrid/core\";\nimport { AditionalUIValueType, Comparer } from \"../types\";\nimport { CellModel } from \"./cellModel\";\nimport { GridModel } from \"./gridModel\";\nimport { RowModel } from \"./rowModel\";\n\nexport enum SortOrder {\n\tAsc = 1,\n\tDesc = -1\n}\n\nexport type SortSettings = {\n\tc: number,\n\tord: SortOrder,\n\tindex?: number\n};\n\nconst ascComparers: Record<UIValueType|AditionalUIValueType, Comparer> = {\n\t'g': (a: CellModel, b: CellModel) => a.value == b.value ? 0 : (a.value > b.value ? 1 : -1),\n\t't': (a: CellModel, b: CellModel) => (a.value as string || '').toString().localeCompare((b.value as string || '').toString()),\n\t's': (a: CellModel, b: CellModel) => a.value == b.value ? 0 : (a.value > b.value ? 1 : -1),\n\t'm': (a: CellModel, b: CellModel) => a.value == b.value ? 0 : (a.value > b.value ? 1 : -1),\n\t'n': (a: CellModel, b: CellModel) => (a.value as number) - (b.value as number),\n\t'd': (a: CellModel, b: CellModel) => (a.value instanceof Date ? a.value.getTime() : 0) - (b.value instanceof Date ? b.value.getTime() : 0),\n\t'tm': (a: CellModel, b: CellModel) => (a.value instanceof Date ? a.value.getTime() : 0) - (b.value instanceof Date ? b.value.getTime() : 0),\n\t'dt': (a: CellModel, b: CellModel) => (a.value instanceof Date ? a.value.getTime() : 0) - (b.value instanceof Date ? b.value.getTime() : 0),\n\t'b': (a: CellModel, b: CellModel) => (a.value as number) - (b.value as number),\n\t'h': (a: CellModel, b: CellModel) => ((a.value as string) || '').localeCompare(b.value as string),\n\t'a': () => 0\n};\n\nconst descComparers: Record<UIValueType|AditionalUIValueType, Comparer> = {\n\t'g': (b: CellModel, a: CellModel) => a.value == b.value ? 0 : (a.value > b.value ? 1 : -1),\n\t't': (b: CellModel, a: CellModel) => (a.value as string || '').toString().localeCompare((b.value as string || '').toString()),\n\t's': (b: CellModel, a: CellModel) => a.value == b.value ? 0 : (a.value > b.value ? 1 : -1),\n\t'm': (b: CellModel, a: CellModel) => a.value == b.value ? 0 : (a.value > b.value ? 1 : -1),\n\t'n': (b: CellModel, a: CellModel) => (a.value as number) - (b.value as number),\n\t'd': (b: CellModel, a: CellModel) => (a.value instanceof Date ? a.value.getTime() : 0) - (b.value instanceof Date ? b.value.getTime() : 0),\n\t'tm': (b: CellModel, a: CellModel) => (a.value instanceof Date ? a.value.getTime() : 0) - (b.value instanceof Date ? b.value.getTime() : 0),\n\t'dt': (b: CellModel, a: CellModel) => (a.value instanceof Date ? a.value.getTime() : 0) - (b.value instanceof Date ? b.value.getTime() : 0),\n\t'b': (b: CellModel, a: CellModel) => (a.value as number) - (b.value as number),\n\t'h': (b: CellModel, a: CellModel) => ((a.value as string) || '').localeCompare(b.value as string),\n\t'a': () => 0\n};\n\nconst origComparer = (a: RowModel, b: RowModel) => a.origIndex - b.origIndex;\n\n/**\n * Class for sorting rows by columns sort settings\n */\nexport class SortingModel {\n\n\tprivate colMap = new Map<number, number>();\n\tprivate _settings: SortSettings[] = [];\n\n\tget settings() { return this._settings }\n\tset settings(v: SortSettings[]|null) {\n\t\tthis._settings = v || [];\n\t\tthis.colMap.clear();\n\t\tif (this.settings.length > 0) {\n\t\t\tthis.settings.forEach((s, i) => this.colMap.set(s.c, i));\n\t\t\tthis.applySort();\n\t\t\tlog.getLogger().info(`sorting applied: ${JSON.stringify(this.settings)}`);\n\t\t}\n\t}\n\t\n\tconstructor(\n\t\tpublic readonly model: GridModel,\n\t\t_settings: SortSettings[]|null = null\n\t) {\n\t\tthis.settings = _settings;\n\t}\n\n\t/**\n\t * Get sorting settings for specified column\n\t * @param c column index\n\t */\n\tget(c: number) {\n\t\treturn this.colMap.has(c) ? this.settings[this.colMap.get(c)] : null;\n\t}\n\n\t/**\n\t * Add sorting settings for specified column\n\t * @param c column index\n\t * @param ord sorting order\n\t * @param custom if true, sorting will not be automaticaly applied\n\t */\n\tsort(c: number, ord: SortOrder = null, custom = false): SortSettings {\n\t\tlet sortSetting: SortSettings = this.get(c);\n\t\tif (sortSetting && sortSetting.ord == SortOrder.Desc && ord === null) {\n\t\t\tthis.settings.splice(this.colMap.get(c), 1);\n\t\t\tsortSetting = null;\n\t\t} else if (sortSetting) {\n\t\t\tsortSetting.ord = SortOrder.Desc;\n\t\t\tthis.settings.splice(this.colMap.get(c), 1);\n\t\t} else {\n\t\t\tsortSetting = {c: c, ord: SortOrder.Asc};\n\t\t}\n\t\t\n\t\tif (sortSetting) {\n\t\t\tif (ord !== null) sortSetting.ord = ord;\n\t\t\tthis.colMap.set(c, 0);\n\t\t\tthis.settings.unshift(sortSetting);\n\t\t}\n\t\t\n\t\tif (this.settings.length > this.model.options.maxSortingColumns) {\n\t\t\tthis.settings.pop();\n\t\t}\n\n\t\tthis.colMap.clear();\n\t\tthis.settings.forEach((s, i) => {\n\t\t\ts.index = i;\n\t\t\tthis.colMap.set(s.c, i);\n\t\t});\n\n\t\tif (!custom) {\n\t\t\tif (this.settings.length > 0) {\n\t\t\t\tthis.applySort();\n\t\t\t} else {\n\t\t\t\tthis.resetSort();\n\t\t\t}\n\t\t}\n\n\t\treturn sortSetting;\n\t}\n\n\t/**\n\t * Apply current sorting settings to rows\n\t */\n\tapplySort() {\n\t\tconst m = this.model;\n\t\tconst cellComparers = this.settings.map(s => {\n\t\t\tconst column = m.columns[s.c];\n\t\t\tif (!column) {\n\t\t\t\tlog.getLogger().warn(`Column sorting: Column with index ${s.c} not found`);\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\t\n\t\t\tif (column.comparer) return s.ord == SortOrder.Asc \n\t\t\t\t? column.comparer\n\t\t\t\t: (a: CellModel, b: CellModel) => -column.comparer(a, b);\n\n\t\t\treturn s.ord == SortOrder.Asc\n\t\t\t\t? ascComparers[column.type ?? 't']\n\t\t\t\t: descComparers[column.type ?? 't'];\n\t\t}).filter(c => c);\n\n\t\tconst len = cellComparers.length;\n\t\tlet ord: number, i: number, c: number;\n\n\t\tconst rowComparer = (a: RowModel, b: RowModel) => {\n\t\t\tif (a.sortable === false || b.sortable === false) {\n\t\t\t\t// if sorting for one of the rows is disabled, use original index for comparison\n\t\t\t\treturn a.origIndex - b.origIndex;\n\t\t\t}\n\n\t\t\tfor (i = 0; i < len; i++) {\n\t\t\t\tc = this.settings[i].c;\n\t\t\t\tord = cellComparers[i](a.cell(c), b.cell(c));\n\t\t\t\tif (ord != 0) return ord;\n\t\t\t}\n\t\t\treturn 0;\n\t\t};\n\n\t\tm.rowRoot.sort(rowComparer);\n\t\tm.indexRowsByTree();\n\t}\n\n\t/**\n\t * Reset row order to default state\n\t */\n\tresetSort() {\n\t\tthis.settings = [];\n\t\tthis.colMap.clear();\n\t\tthis.model.rowRoot.sort(origComparer);\n\t\tthis.model.indexRowsByTree();\n\t}\n\n\t/**\n\t * Use current sorting settings as default row order\n\t */\n\tpersistSort() {\n\t\tthis.model.rows.forEach((r, i) => r.origIndex = i);\n\t}\n\n}"]}
|