jsl-ui 9.28.3 → 9.28.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/lib/components/IntervalComponent.d.ts +17 -17
- package/lib/components/IntervalComponent.js +65 -65
- package/lib/components/auto-suggest/AutoSuggestComponent.d.ts +22 -22
- package/lib/components/auto-suggest/AutoSuggestComponent.js +47 -47
- package/lib/components/button/ButtonComponent.d.ts +18 -18
- package/lib/components/button/ButtonComponent.js +29 -29
- package/lib/components/checkbox/CheckBoxComponent.d.ts +28 -28
- package/lib/components/checkbox/CheckBoxComponent.js +81 -81
- package/lib/components/date/DateComponent.d.ts +32 -32
- package/lib/components/date/DateComponent.js +89 -89
- package/lib/components/date-range/DateRangeComponent.d.ts +35 -35
- package/lib/components/date-range/DateRangeComponent.js +121 -123
- package/lib/components/date-time/DateTimeComponent.d.ts +15 -15
- package/lib/components/date-time/DateTimeComponent.js +39 -39
- package/lib/components/dialog/DialogComponent.d.ts +67 -67
- package/lib/components/dialog/DialogComponent.js +192 -198
- package/lib/components/drop-down/DropDownComponent.d.ts +27 -27
- package/lib/components/drop-down/DropDownComponent.js +60 -60
- package/lib/components/expander/ExpanderComponent.d.ts +27 -27
- package/lib/components/expander/ExpanderComponent.js +87 -89
- package/lib/components/form-field/FormComponent.d.ts +12 -12
- package/lib/components/form-field/FormComponent.js +23 -23
- package/lib/components/form-field/FormFieldComponent.d.ts +39 -39
- package/lib/components/form-field/FormFieldComponent.js +138 -138
- package/lib/components/grid/GridComponent.d.ts +26 -26
- package/lib/components/grid/GridComponent.js +110 -110
- package/lib/components/input/InputComponent.d.ts +33 -33
- package/lib/components/input/InputComponent.js +126 -126
- package/lib/components/loading/LoadingComponent.d.ts +8 -8
- package/lib/components/loading/LoadingComponent.js +20 -20
- package/lib/components/navigation/NavigationComponent.d.ts +34 -34
- package/lib/components/navigation/NavigationComponent.js +47 -45
- package/lib/components/notification/Notification.d.ts +19 -19
- package/lib/components/notification/Notification.js +65 -65
- package/lib/components/number/NumberComponent.d.ts +26 -26
- package/lib/components/number/NumberComponent.js +80 -80
- package/lib/components/overlay/OverlayComponent.d.ts +27 -27
- package/lib/components/overlay/OverlayComponent.js +134 -137
- package/lib/components/progress/ProgressComponent.d.ts +18 -18
- package/lib/components/progress/ProgressComponent.js +40 -40
- package/lib/components/ribbon-menu/RibbonMenuComponent.d.ts +12 -12
- package/lib/components/ribbon-menu/RibbonMenuComponent.js +23 -23
- package/lib/components/select/SelectComponent.d.ts +79 -79
- package/lib/components/select/SelectComponent.js +352 -356
- package/lib/components/select/SelectDDAreaComponent.d.ts +32 -32
- package/lib/components/select/SelectDDAreaComponent.js +303 -303
- package/lib/components/slider/nouislider.d.ts +44 -44
- package/lib/components/slider/nouislider.js +2158 -2158
- package/lib/components/stack-panel/SplitterComponent.d.ts +21 -21
- package/lib/components/stack-panel/SplitterComponent.js +124 -124
- package/lib/components/stack-panel/StackPanelComponent.d.ts +20 -20
- package/lib/components/stack-panel/StackPanelComponent.js +50 -50
- package/lib/components/tabs/TabsComponent.d.ts +40 -40
- package/lib/components/tabs/TabsComponent.js +191 -200
- package/lib/components/time/TimeComponent.d.ts +29 -29
- package/lib/components/time/TimeComponent.js +102 -104
- package/lib/components/tree-view/TreeViewComponent.d.ts +23 -23
- package/lib/components/tree-view/TreeViewComponent.js +42 -43
- package/lib/components/virtual-render/VirtualRenderComponent.d.ts +30 -30
- package/lib/components/virtual-render/VirtualRenderComponent.js +90 -92
- package/lib/core/culture.d.ts +5 -5
- package/lib/core/culture.js +385 -385
- package/lib/core/date.d.ts +14 -14
- package/lib/core/date.js +346 -346
- package/lib/core/helper.d.ts +13 -13
- package/lib/core/helper.js +100 -100
- package/lib/core/jq.d.ts +37 -37
- package/lib/core/jq.js +362 -362
- package/lib/core/lang.d.ts +24 -24
- package/lib/core/lang.js +24 -24
- package/lib/core/numeric.d.ts +7 -7
- package/lib/core/numeric.js +139 -139
- package/lib/core/polyfills.js +22 -22
- package/lib/core.d.ts +6 -6
- package/lib/core.js +6 -6
- package/lib/grid/filterDialogs/dateRangeFilter.d.ts +7 -7
- package/lib/grid/filterDialogs/dateRangeFilter.js +106 -106
- package/lib/grid/filterDialogs/excelFilter.d.ts +9 -9
- package/lib/grid/filterDialogs/excelFilter.js +250 -250
- package/lib/grid/plugins/ext.overlay.d.ts +2 -2
- package/lib/grid/plugins/ext.overlay.js +295 -295
- package/lib/grid/plugins/slick.cellrangedecorator.d.ts +12 -12
- package/lib/grid/plugins/slick.cellrangedecorator.js +68 -68
- package/lib/grid/plugins/slick.cellrangeselector.d.ts +1 -1
- package/lib/grid/plugins/slick.cellrangeselector.js +144 -144
- package/lib/grid/plugins/slick.cellselectionmodel.d.ts +1 -1
- package/lib/grid/plugins/slick.cellselectionmodel.js +194 -194
- package/lib/grid/plugins/slick.headerbuttons.d.ts +55 -55
- package/lib/grid/plugins/slick.headerbuttons.js +156 -156
- package/lib/grid/plugins/slick.headermenu.d.ts +74 -74
- package/lib/grid/plugins/slick.headermenu.js +260 -260
- package/lib/grid/plugins/slick.rowmovemanager.d.ts +18 -18
- package/lib/grid/plugins/slick.rowmovemanager.js +249 -249
- package/lib/grid/plugins/slick.rowselectionmodel.d.ts +1 -1
- package/lib/grid/plugins/slick.rowselectionmodel.js +167 -167
- package/lib/grid/slick.core.d.ts +91 -91
- package/lib/grid/slick.core.js +574 -574
- package/lib/grid/slick.creator.d.ts +81 -81
- package/lib/grid/slick.creator.js +726 -726
- package/lib/grid/slick.dataview.d.ts +71 -71
- package/lib/grid/slick.dataview.js +1069 -1069
- package/lib/grid/slick.editors.core.d.ts +4 -4
- package/lib/grid/slick.editors.core.js +235 -235
- package/lib/grid/slick.editors.date.d.ts +2 -2
- package/lib/grid/slick.editors.date.js +125 -125
- package/lib/grid/slick.editors.lookup.d.ts +14 -14
- package/lib/grid/slick.editors.lookup.js +352 -352
- package/lib/grid/slick.editors.nav.d.ts +6 -6
- package/lib/grid/slick.editors.nav.js +22 -22
- package/lib/grid/slick.formatters.d.ts +17 -17
- package/lib/grid/slick.formatters.js +144 -144
- package/lib/grid/slick.grid.d.ts +285 -285
- package/lib/grid/slick.grid.js +5409 -5409
- package/lib/grid/slick.groupitemmetadataprovider.d.ts +39 -39
- package/lib/grid/slick.groupitemmetadataprovider.js +165 -165
- package/lib/grid/slick.tree.d.ts +33 -33
- package/lib/grid/slick.tree.js +208 -208
- package/lib/grid.css +705 -1
- package/lib/grid.d.ts +13 -13
- package/lib/grid.js +13 -13
- package/lib/index.css +2195 -8
- package/lib/index.css.map +1 -1
- package/lib/index.d.ts +55 -56
- package/lib/index.js +61 -61
- package/lib/index.js.map +1 -1
- package/lib/interaction/dataconverter.d.ts +4 -4
- package/lib/interaction/dataconverter.js +1 -0
- package/lib/interaction/eventhandler.d.ts +13 -13
- package/lib/interaction/eventhandler.js +39 -39
- package/lib/interaction/moveable.d.ts +39 -39
- package/lib/interaction/moveable.js +160 -160
- package/lib/interaction/resizable.d.ts +37 -37
- package/lib/interaction/resizable.js +109 -109
- package/lib/ui/auto.suggest.d.ts +18 -18
- package/lib/ui/auto.suggest.js +244 -244
- package/lib/ui/date.picker/date-picker-options.d.ts +11 -11
- package/lib/ui/date.picker/date-picker-options.js +76 -76
- package/lib/ui/date.picker/lib/date-manip.d.ts +74 -74
- package/lib/ui/date.picker/lib/date-manip.js +120 -120
- package/lib/ui/date.picker/lib/dom.d.ts +23 -23
- package/lib/ui/date.picker/lib/dom.js +28 -28
- package/lib/ui/date.picker/lib/emitter.d.ts +13 -13
- package/lib/ui/date.picker/lib/emitter.js +49 -49
- package/lib/ui/date.picker/lib/fns.d.ts +23 -23
- package/lib/ui/date.picker/lib/fns.js +39 -39
- package/lib/ui/date.picker/mode/base-mode.d.ts +26 -26
- package/lib/ui/date.picker/mode/base-mode.js +248 -248
- package/lib/ui/date.picker/mode/dropdown-mode.d.ts +28 -28
- package/lib/ui/date.picker/mode/dropdown-mode.js +50 -50
- package/lib/ui/date.picker/mode/index.d.ts +28 -28
- package/lib/ui/date.picker/mode/index.js +18 -18
- package/lib/ui/date.picker/mode/modal-mode.d.ts +25 -25
- package/lib/ui/date.picker/mode/modal-mode.js +17 -17
- package/lib/ui/date.picker/mode/permanent-mode.d.ts +29 -29
- package/lib/ui/date.picker/mode/permanent-mode.js +19 -19
- package/lib/ui/date.picker/views/day-picker.d.ts +40 -40
- package/lib/ui/date.picker/views/day-picker.js +155 -155
- package/lib/ui/date.picker/views/month-picker.d.ts +26 -26
- package/lib/ui/date.picker/views/month-picker.js +65 -65
- package/lib/ui/date.picker/views/year-picker.d.ts +20 -20
- package/lib/ui/date.picker/views/year-picker.js +66 -66
- package/lib/ui/date.picker.d.ts +66 -66
- package/lib/ui/date.picker.js +32 -32
- package/lib/ui/dialog.d.ts +22 -22
- package/lib/ui/dialog.js +98 -98
- package/lib/ui/drop.down.d.ts +52 -52
- package/lib/ui/drop.down.js +2112 -2112
- package/lib/ui/number.input.d.ts +13 -13
- package/lib/ui/number.input.js +56 -56
- package/package.json +1 -1
|
@@ -1,726 +1,726 @@
|
|
|
1
|
-
import { Slick } from "./slick.core";
|
|
2
|
-
import { SlickGrid } from "./slick.grid";
|
|
3
|
-
import { RowSelectionModel } from "./plugins/slick.rowselectionmodel";
|
|
4
|
-
import { DataView } from "./slick.dataview";
|
|
5
|
-
import { GroupItemMetadataProvider } from "./slick.groupitemmetadataprovider";
|
|
6
|
-
import { jQueryReplacement } from "../core/jq";
|
|
7
|
-
import { HeaderMenu } from "./plugins/slick.headermenu";
|
|
8
|
-
import { HeaderButtons } from "./plugins/slick.headerbuttons";
|
|
9
|
-
import { TextFormatter } from "./slick.formatters";
|
|
10
|
-
import { ExcelFilter } from "./filterDialogs/excelFilter";
|
|
11
|
-
import { UILang } from "../core/lang";
|
|
12
|
-
import { RowMoveManager } from "./plugins/slick.rowmovemanager";
|
|
13
|
-
import { Overlays } from "./plugins/ext.overlay";
|
|
14
|
-
import { helper } from "../core/helper";
|
|
15
|
-
const $ = jQueryReplacement;
|
|
16
|
-
export function createJSLGrid(selector, data, columns, option) {
|
|
17
|
-
const formulaObjects = [];
|
|
18
|
-
let headerMenu;
|
|
19
|
-
let headerButtons;
|
|
20
|
-
const formulas = {};
|
|
21
|
-
let container;
|
|
22
|
-
let filters = [];
|
|
23
|
-
let customCommandHandler;
|
|
24
|
-
let grid;
|
|
25
|
-
let dataView;
|
|
26
|
-
let rowMoveManager;
|
|
27
|
-
//let options: ISlickCreatorOptions;
|
|
28
|
-
function createMe() {
|
|
29
|
-
sanitizeColumns(columns);
|
|
30
|
-
const options = $.shallowExtend({ explicitInitialization: true, mode: "client" }, option);
|
|
31
|
-
container = typeof (selector) === "string" ?
|
|
32
|
-
document.querySelector(selector) :
|
|
33
|
-
selector;
|
|
34
|
-
if (!container) {
|
|
35
|
-
throw new Error("error: selector for SlickCreator is invalid");
|
|
36
|
-
}
|
|
37
|
-
if (options.showColumnGroups) {
|
|
38
|
-
options.createPreHeaderPanel = true;
|
|
39
|
-
options.showPreHeaderPanel = true;
|
|
40
|
-
}
|
|
41
|
-
customCommandHandler = option.editCommandHandler;
|
|
42
|
-
options.editCommandHandler = (a, b, c) => { handleEditCommand(a, b, c); };
|
|
43
|
-
const groupItemMetadataProvider = options.groupItemMetadataProvider || GroupItemMetadataProvider(options.groupItemOptions);
|
|
44
|
-
if (options.dataView != null) {
|
|
45
|
-
dataView = options.dataView;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
dataView = new DataView({ inlineFilters: true, groupItemMetadataProvider });
|
|
49
|
-
dataView.setItems(data, options.primaryKey);
|
|
50
|
-
}
|
|
51
|
-
grid = new SlickGrid(container, dataView, columns, options);
|
|
52
|
-
grid.registerPlugin(groupItemMetadataProvider);
|
|
53
|
-
grid.setSelectionModel(new RowSelectionModel());
|
|
54
|
-
grid.onHeaderCellRendered.subscribe((e, args) => {
|
|
55
|
-
if (columnHasFilter(args.column.id)) {
|
|
56
|
-
//this column is filtered
|
|
57
|
-
args.node.classList.add("slick-filtered-header");
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
addCustomEvents();
|
|
61
|
-
setupDefaultSort();
|
|
62
|
-
setupChangeEvents();
|
|
63
|
-
if (options.showHeaderMenu) {
|
|
64
|
-
setupHeaderMenu();
|
|
65
|
-
}
|
|
66
|
-
setupHeaderButtons();
|
|
67
|
-
if (options.allowRowMove) {
|
|
68
|
-
rowMoveManager = new RowMoveManager({
|
|
69
|
-
cancelEditOnDrag: true,
|
|
70
|
-
singleRowMove: true,
|
|
71
|
-
disableRowSelection: true,
|
|
72
|
-
hideRowMoveShadow: false,
|
|
73
|
-
rowMoveShadowScale: 0.7,
|
|
74
|
-
rowMoveShadowOpacity: 0.9 // defaults to 0.95
|
|
75
|
-
});
|
|
76
|
-
grid.registerPlugin(rowMoveManager);
|
|
77
|
-
rowMoveManager.onBeforeMoveRows.subscribe(function (e, args) {
|
|
78
|
-
// debugger;
|
|
79
|
-
});
|
|
80
|
-
rowMoveManager.onMoveRows.subscribe(function (e, args) {
|
|
81
|
-
var extractedRows = [], left, right;
|
|
82
|
-
var rows = args.rows;
|
|
83
|
-
var insertBefore = args.insertBefore;
|
|
84
|
-
left = data.slice(0, insertBefore);
|
|
85
|
-
right = data.slice(insertBefore, data.length);
|
|
86
|
-
rows.sort(function (a, b) { return a - b; });
|
|
87
|
-
for (var i = 0; i < rows.length; i++) {
|
|
88
|
-
extractedRows.push(data[rows[i]]);
|
|
89
|
-
}
|
|
90
|
-
rows.reverse();
|
|
91
|
-
for (var i = 0; i < rows.length; i++) {
|
|
92
|
-
var row = rows[i];
|
|
93
|
-
if (row < insertBefore) {
|
|
94
|
-
left.splice(row, 1);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
right.splice(row - insertBefore, 1);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
data = left.concat(extractedRows.concat(right));
|
|
101
|
-
var selectedRows = [];
|
|
102
|
-
for (var i = 0; i < rows.length; i++)
|
|
103
|
-
selectedRows.push(left.length + i);
|
|
104
|
-
// grid.resetActiveCell();
|
|
105
|
-
dataView.beginUpdate();
|
|
106
|
-
dataView.setItems(data);
|
|
107
|
-
dataView.endUpdate();
|
|
108
|
-
grid.render();
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
const isTouch = helper.isTouchScreen();
|
|
112
|
-
if (option.enableFillDown && !isTouch) {
|
|
113
|
-
var overlayPlugin = new Overlays({});
|
|
114
|
-
// Event fires when a range is selected
|
|
115
|
-
overlayPlugin.onFillUpDown.subscribe(function (e, args) {
|
|
116
|
-
const column = grid.getColumns()[args.range.fromCell];
|
|
117
|
-
// Ensure the column is editable
|
|
118
|
-
if (column.editor == null || column.readonly || !grid.getOptions().editable) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
// Find the initial value
|
|
122
|
-
dataView.beginUpdate();
|
|
123
|
-
let value;
|
|
124
|
-
const items = [];
|
|
125
|
-
if (args.direction === "down") {
|
|
126
|
-
const item = dataView.getItem(args.range.fromRow);
|
|
127
|
-
value = grid.getDataItemValueForColumn(item, column); // item[column.field];
|
|
128
|
-
// Copy the value down
|
|
129
|
-
for (let i = args.range.fromRow + 1; i <= args.range.toRow; i++) {
|
|
130
|
-
if (grid.onBeforeEditCell.notify({ row: i, cell: args.range.fromCell, item: dataView.getItem(i), column }, e) !== false) {
|
|
131
|
-
const currentItem = dataView.getItem(i);
|
|
132
|
-
items.push(currentItem);
|
|
133
|
-
// if (options.setDataItemValueForColumn != null) {
|
|
134
|
-
// options.setDataItemValueForColumn(currentItem, column, value);
|
|
135
|
-
// } else {
|
|
136
|
-
// dataView.getItem(i)[column.field] = value;
|
|
137
|
-
// }
|
|
138
|
-
// grid.invalidateRow(i);
|
|
139
|
-
// grid.onAfterEdit.notify({ grid, oldValue, newValue: value, column, item: dataView.getItem(i) }, e);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
const item = dataView.getItem(args.range.toRow);
|
|
145
|
-
items.push(item);
|
|
146
|
-
value = grid.getDataItemValueForColumn(item, column); // item[column.field];
|
|
147
|
-
// Copy the value up
|
|
148
|
-
for (let i = args.range.fromRow; i <= args.range.toRow - 1; i++) {
|
|
149
|
-
if (grid.onBeforeEditCell.notify({ row: i, cell: args.range.fromCell, item: dataView.getItem(i), column }, e) !== false) {
|
|
150
|
-
const currentItem = dataView.getItem(i);
|
|
151
|
-
items.push(currentItem);
|
|
152
|
-
// if (options.setDataItemValueForColumn != null) {
|
|
153
|
-
// options.setDataItemValueForColumn(currentItem, column, value);
|
|
154
|
-
// } else {
|
|
155
|
-
// dataView.getItem(i)[column.field] = value;
|
|
156
|
-
// }
|
|
157
|
-
// grid.invalidateRow(i);
|
|
158
|
-
// grid.onAfterEdit.notify({ grid, oldValue, newValue: value, column, item: dataView.getItem(i) }, e);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
grid.onAfterFillDown.notify({ grid, value, column, direction: args.direction, range: args.range, items: items }, e);
|
|
163
|
-
dataView.endUpdate();
|
|
164
|
-
grid.render();
|
|
165
|
-
});
|
|
166
|
-
grid.registerPlugin(overlayPlugin);
|
|
167
|
-
}
|
|
168
|
-
if (!option.explicitInitialization) {
|
|
169
|
-
grid.init();
|
|
170
|
-
}
|
|
171
|
-
if (options.showColumnGroups) {
|
|
172
|
-
setTimeout(() => {
|
|
173
|
-
// TODO -> find better solution then timeout
|
|
174
|
-
grid.onColumnsResized.subscribe(() => {
|
|
175
|
-
CreateColumnGroups();
|
|
176
|
-
});
|
|
177
|
-
CreateColumnGroups();
|
|
178
|
-
}, 1);
|
|
179
|
-
}
|
|
180
|
-
if (options.saveColumnsKey) {
|
|
181
|
-
grid.onColumnsResized.subscribe(() => {
|
|
182
|
-
storeColumnSettings();
|
|
183
|
-
});
|
|
184
|
-
grid.onColumnsReordered.subscribe(() => {
|
|
185
|
-
storeColumnSettings();
|
|
186
|
-
});
|
|
187
|
-
loadColumnSettings();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
function CreateColumnGroups() {
|
|
191
|
-
const options = grid.getOptions();
|
|
192
|
-
const columns = grid.getColumns();
|
|
193
|
-
if (options.frozenColumn >= 0) {
|
|
194
|
-
// Add column groups to left panel
|
|
195
|
-
let $preHeaderPanel = $(grid.getPreHeaderPanel());
|
|
196
|
-
renderHeaderGroups($preHeaderPanel, 0, options.frozenColumn + 1);
|
|
197
|
-
// Add column groups to right panel
|
|
198
|
-
$preHeaderPanel = $(grid.getPreHeaderPanelRight());
|
|
199
|
-
renderHeaderGroups($preHeaderPanel, options.frozenColumn + 1, columns.length);
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
const $preHeaderPanel = $(grid.getPreHeaderPanel());
|
|
203
|
-
renderHeaderGroups($preHeaderPanel, 0, columns.length);
|
|
204
|
-
}
|
|
205
|
-
function renderHeaderGroups(preHeaderPanel, start, end) {
|
|
206
|
-
preHeaderPanel.empty()
|
|
207
|
-
.addClass("slick-header-columns")
|
|
208
|
-
.css("left", "-1000px")
|
|
209
|
-
.width(grid.getHeadersWidth());
|
|
210
|
-
preHeaderPanel[0].parentElement.classList.add("slick-header");
|
|
211
|
-
const headerColumnWidthDiff = grid.getHeaderColumnWidthDiff();
|
|
212
|
-
let header;
|
|
213
|
-
let lastColumnGroup = "";
|
|
214
|
-
let widthTotal = 0;
|
|
215
|
-
for (let i = start; i < end; i++) {
|
|
216
|
-
const m = columns[i];
|
|
217
|
-
if (lastColumnGroup === m.columnGroup && i > start) {
|
|
218
|
-
widthTotal += m.width;
|
|
219
|
-
header.width(widthTotal - headerColumnWidthDiff);
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
widthTotal = m.width;
|
|
223
|
-
header = $("<div class='ui-state-default slick-header-column' />")
|
|
224
|
-
.html("<span class='slick-column-name'>" + (m.columnGroup || '') + "</span>")
|
|
225
|
-
.width(m.width - headerColumnWidthDiff)
|
|
226
|
-
.appendTo(preHeaderPanel);
|
|
227
|
-
}
|
|
228
|
-
lastColumnGroup = m.columnGroup;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
function storeColumnSettings() {
|
|
233
|
-
const cols = grid.getColumns();
|
|
234
|
-
const options = grid.getOptions();
|
|
235
|
-
const colSettings = cols.map((c) => ({ id: c.id, width: c.width }));
|
|
236
|
-
if (window.localStorage) {
|
|
237
|
-
localStorage.setItem("_grid_col_settings_" + options.saveColumnsKey, JSON.stringify(colSettings));
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
function loadColumnSettings() {
|
|
241
|
-
if (!window.localStorage) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
const options = grid.getOptions();
|
|
245
|
-
const key = options.saveColumnsKey;
|
|
246
|
-
if (key) {
|
|
247
|
-
const cols = grid.getColumns();
|
|
248
|
-
const colSettings = JSON.parse(localStorage.getItem("_grid_col_settings_" + key));
|
|
249
|
-
if (!colSettings) {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
for (let i = 0; i < colSettings.length; i++) {
|
|
253
|
-
for (let j = 0; j < cols.length; j++) {
|
|
254
|
-
if (cols[j].id === colSettings[i].id) {
|
|
255
|
-
const c = cols[j];
|
|
256
|
-
c.width = colSettings[i].width;
|
|
257
|
-
if (i !== j) {
|
|
258
|
-
cols.splice(j, 1);
|
|
259
|
-
cols.splice(i, 0, c);
|
|
260
|
-
}
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
grid.setColumns(cols);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
function sanitizeColumns(cols) {
|
|
269
|
-
for (let i = 0; i < cols.length; i++) {
|
|
270
|
-
const c = cols[i];
|
|
271
|
-
if (c.field === undefined && c.id) {
|
|
272
|
-
c.field = c.id;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
function addCustomEvents() {
|
|
277
|
-
grid.onAfterEdit = new Slick.Event();
|
|
278
|
-
grid.onFiltersChanged = new Slick.Event();
|
|
279
|
-
grid.onAfterFillDown = new Slick.Event();
|
|
280
|
-
}
|
|
281
|
-
function setupChangeEvents() {
|
|
282
|
-
dataView.onRowsChanged.subscribe((e, args) => {
|
|
283
|
-
grid.invalidateRows(args.rows);
|
|
284
|
-
grid.render();
|
|
285
|
-
// for (let idx = 0; idx < args.rows.length; idx++) {
|
|
286
|
-
// grid.updateRow(args.rows[idx]);
|
|
287
|
-
// }
|
|
288
|
-
// grid.invalidate();
|
|
289
|
-
});
|
|
290
|
-
dataView.onRowCountChanged.subscribe((e, args) => {
|
|
291
|
-
grid.updateRowCount();
|
|
292
|
-
grid.render();
|
|
293
|
-
});
|
|
294
|
-
grid.onAddNewRow.subscribe((e, args) => {
|
|
295
|
-
const options = grid.getOptions();
|
|
296
|
-
if (options.provideDefaultValues != null) {
|
|
297
|
-
const result = options.provideDefaultValues(args.item);
|
|
298
|
-
if (result === false) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
dataView.addItem(args.item);
|
|
303
|
-
grid.onAfterEdit.notify({
|
|
304
|
-
grid,
|
|
305
|
-
oldValue: undefined,
|
|
306
|
-
newValue: grid.getDataItemValueForColumn(args.item, args.column),
|
|
307
|
-
column: args.column,
|
|
308
|
-
item: args.item
|
|
309
|
-
});
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
function setupDefaultSort() {
|
|
313
|
-
const options = grid.getOptions();
|
|
314
|
-
if (options.mode === "client") {
|
|
315
|
-
grid.onSort.subscribe((e, args) => {
|
|
316
|
-
sort(args.sortCol, args.sortAsc);
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
// TODO: multi column sort
|
|
320
|
-
}
|
|
321
|
-
function setupHeaderButtons() {
|
|
322
|
-
headerButtons = new HeaderButtons({});
|
|
323
|
-
grid.registerPlugin(headerButtons);
|
|
324
|
-
}
|
|
325
|
-
function setupHeaderMenu() {
|
|
326
|
-
headerMenu = new HeaderMenu({});
|
|
327
|
-
grid.registerPlugin(headerMenu);
|
|
328
|
-
headerMenu.onBeforeMenuShow.subscribe((e, args) => {
|
|
329
|
-
const column = args.column;
|
|
330
|
-
const menu = args.menu;
|
|
331
|
-
if (column.sortable) {
|
|
332
|
-
menu.items.push({
|
|
333
|
-
title: UILang.grid.Sort + " " + UILang.grid.Asc,
|
|
334
|
-
command: "sort-asc"
|
|
335
|
-
});
|
|
336
|
-
menu.items.push({
|
|
337
|
-
title: UILang.grid.Sort + " " + UILang.grid.Desc,
|
|
338
|
-
command: "sort-desc"
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
if (column.filterable) {
|
|
342
|
-
menu.items.push({
|
|
343
|
-
title: UILang.grid.Filter,
|
|
344
|
-
command: "filter"
|
|
345
|
-
});
|
|
346
|
-
if (filters.filter((f) => f.columnId === column.id).length > 0) {
|
|
347
|
-
menu.items.push({
|
|
348
|
-
title: UILang.grid.ClearFilter,
|
|
349
|
-
command: "clear-filter"
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
headerMenu.onCommand.subscribe((e, args) => {
|
|
355
|
-
if (args.command === "sort-asc" || args.command === "sort-desc") {
|
|
356
|
-
grid.onSort.notify({
|
|
357
|
-
sortAsc: args.command === "sort-asc",
|
|
358
|
-
sortCol: args.column,
|
|
359
|
-
columnId: args.column.id,
|
|
360
|
-
sortCols: [{ columnId: args.column.id, sortCol: args.column, sortAsc: args.command === "sort-asc" }],
|
|
361
|
-
multiColumnSort: false
|
|
362
|
-
}, e);
|
|
363
|
-
// sort(args.column, args.command === "sort-asc");
|
|
364
|
-
}
|
|
365
|
-
else if (args.command === "filter") {
|
|
366
|
-
const options = grid.getOptions();
|
|
367
|
-
if (options.showFilterDialog != null) {
|
|
368
|
-
options.showFilterDialog(args.column, grid);
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
new ExcelFilter(grid).show(args.column);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
else if (args.command === "clear-filter") {
|
|
375
|
-
clearFilter(args.column.id);
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
// refresh formulas depending on the given column
|
|
380
|
-
function triggerFormula(column, item) {
|
|
381
|
-
const options = grid.getOptions();
|
|
382
|
-
const f = formulas[column];
|
|
383
|
-
if (f) {
|
|
384
|
-
for (let i = 0, l = f.length; i < l; i++) {
|
|
385
|
-
if (options.setDataItemValueForColumn != null) {
|
|
386
|
-
options.setDataItemValueForColumn(item, f[i].column, f[i].fnc(item, column));
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
item[f[i].column] = f[i].fnc(item, column);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
function handleEditCommand(item, column, editCommand) {
|
|
395
|
-
const options = grid.getOptions();
|
|
396
|
-
const oldVal = grid.getDataItemValueForColumn(item, column);
|
|
397
|
-
if (customCommandHandler) {
|
|
398
|
-
customCommandHandler(item, column, editCommand);
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
editCommand.execute();
|
|
402
|
-
}
|
|
403
|
-
triggerFormula(column.field, item);
|
|
404
|
-
dataView.updateItem(item[options.primaryKey], item);
|
|
405
|
-
const afterEditResult = grid.onAfterEdit.notify({
|
|
406
|
-
grid,
|
|
407
|
-
oldValue: oldVal,
|
|
408
|
-
newValue: grid.getDataItemValueForColumn(item, column),
|
|
409
|
-
column,
|
|
410
|
-
item
|
|
411
|
-
});
|
|
412
|
-
if (afterEditResult === false) {
|
|
413
|
-
if (options.setDataItemValueForColumn != null) {
|
|
414
|
-
options.setDataItemValueForColumn(item, column, oldVal);
|
|
415
|
-
}
|
|
416
|
-
else {
|
|
417
|
-
item[column.field] = oldVal;
|
|
418
|
-
}
|
|
419
|
-
triggerFormula(column.field, item);
|
|
420
|
-
dataView.updateItem(item[options.primaryKey], item);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
function setHeight(height) {
|
|
424
|
-
$(container).height(height);
|
|
425
|
-
grid.resizeCanvas();
|
|
426
|
-
}
|
|
427
|
-
function getHeight() {
|
|
428
|
-
return $(container).height();
|
|
429
|
-
}
|
|
430
|
-
function sort(column, sortAsc) {
|
|
431
|
-
function _comparer(a, b) {
|
|
432
|
-
let x = grid.getDataItemValueForColumn(a, column);
|
|
433
|
-
let y = grid.getDataItemValueForColumn(b, column);
|
|
434
|
-
if (typeof x === "string" && typeof y === "string") {
|
|
435
|
-
x = x.toLocaleLowerCase();
|
|
436
|
-
y = y.toLocaleLowerCase();
|
|
437
|
-
}
|
|
438
|
-
if (x == null && y != null) {
|
|
439
|
-
return -1;
|
|
440
|
-
}
|
|
441
|
-
else if (x != null && y == null) {
|
|
442
|
-
return 1;
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
return (x === y ? 0 : (x > y ? 1 : -1));
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
function _visibleComparer(a, b) {
|
|
449
|
-
const x = column.formatter(0, 0, grid.getDataItemValueForColumn(a, column), column, a);
|
|
450
|
-
const y = column.formatter(0, 0, grid.getDataItemValueForColumn(b, column), column, b);
|
|
451
|
-
let xStr = (Object.prototype.toString.call(x) !== "[object Object]" ? x : x.text);
|
|
452
|
-
let yStr = (Object.prototype.toString.call(y) !== "[object Object]" ? y : y.text);
|
|
453
|
-
if (typeof x === "string" && typeof y === "string") {
|
|
454
|
-
xStr = x.toLocaleLowerCase();
|
|
455
|
-
yStr = y.toLocaleLowerCase();
|
|
456
|
-
}
|
|
457
|
-
return (xStr === yStr ? 0 : (xStr > yStr ? 1 : -1));
|
|
458
|
-
}
|
|
459
|
-
const comparer = column.comparer || (column.sortByVisibleValue ? _visibleComparer : _comparer);
|
|
460
|
-
dataView.sort(comparer, sortAsc ? true : false);
|
|
461
|
-
}
|
|
462
|
-
function setData(newData) {
|
|
463
|
-
data = newData;
|
|
464
|
-
dataView.setItems(data);
|
|
465
|
-
refresh();
|
|
466
|
-
}
|
|
467
|
-
function getData() {
|
|
468
|
-
return data;
|
|
469
|
-
}
|
|
470
|
-
function refreshData() {
|
|
471
|
-
// var selrows = self.getSelectedRows();
|
|
472
|
-
dataView.setItems(data);
|
|
473
|
-
// self.setSelectedRows(selrows);
|
|
474
|
-
refresh();
|
|
475
|
-
}
|
|
476
|
-
function refresh() {
|
|
477
|
-
grid.invalidate();
|
|
478
|
-
}
|
|
479
|
-
function addFormula(field, fnc, usedColumns) {
|
|
480
|
-
formulaObjects.push({ fnc, column: field });
|
|
481
|
-
for (let i = 0; i < usedColumns.length; i++) {
|
|
482
|
-
if (!formulas[usedColumns[i]]) {
|
|
483
|
-
formulas[usedColumns[i]] = [];
|
|
484
|
-
}
|
|
485
|
-
formulas[usedColumns[i]].push({ fnc, column: field });
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* returns the string representation of a value based on column settings
|
|
490
|
-
*/
|
|
491
|
-
function getFormattedValue(column, value, item) {
|
|
492
|
-
const formatter = column.formatter || TextFormatter;
|
|
493
|
-
const formatterResult = formatter(0, 0, value, column, item, grid);
|
|
494
|
-
return (Object.prototype.toString.call(formatterResult) !== "[object Object]" ?
|
|
495
|
-
formatterResult :
|
|
496
|
-
(formatterResult.text));
|
|
497
|
-
}
|
|
498
|
-
function getContentWidth(column, row) {
|
|
499
|
-
const item = dataView.getItem(row);
|
|
500
|
-
const html = getFormattedValue(column, grid.getDataItemValueForColumn(item, column), item);
|
|
501
|
-
if (html.indexOf("<") >= 0) {
|
|
502
|
-
return calcLengthInternal(html, true) + 12;
|
|
503
|
-
}
|
|
504
|
-
else {
|
|
505
|
-
if (convertElement == null) {
|
|
506
|
-
convertElement = document.createElement("span");
|
|
507
|
-
}
|
|
508
|
-
convertElement.innerHTML = html;
|
|
509
|
-
return calcTextLength(convertElement.textContent) + 12;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
let measureElement;
|
|
513
|
-
let convertElement;
|
|
514
|
-
const charWidth = {};
|
|
515
|
-
function calcTextLength(text) {
|
|
516
|
-
let result = 0;
|
|
517
|
-
for (let i = 0; i < text.length; i++) {
|
|
518
|
-
const c = text[i];
|
|
519
|
-
let w = charWidth[c];
|
|
520
|
-
if (w == null) {
|
|
521
|
-
charWidth[c] = w = calcLengthInternal(c, false);
|
|
522
|
-
}
|
|
523
|
-
result += w;
|
|
524
|
-
}
|
|
525
|
-
return result;
|
|
526
|
-
}
|
|
527
|
-
function calcLengthInternal(c, isHTML) {
|
|
528
|
-
if (measureElement == null) {
|
|
529
|
-
measureElement = document.createElement("span");
|
|
530
|
-
measureElement.style.top = "-100000px";
|
|
531
|
-
measureElement.style.position = "absolute";
|
|
532
|
-
measureElement.style.whiteSpace = "pre";
|
|
533
|
-
document.body.appendChild(measureElement);
|
|
534
|
-
grid.onBeforeDestroy.subscribe(() => {
|
|
535
|
-
if (measureElement.parentElement != null) {
|
|
536
|
-
measureElement.parentElement.removeChild(measureElement);
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
if (isHTML) {
|
|
541
|
-
measureElement.innerHTML = c;
|
|
542
|
-
}
|
|
543
|
-
else {
|
|
544
|
-
measureElement.textContent = c;
|
|
545
|
-
}
|
|
546
|
-
return measureElement.getBoundingClientRect().width;
|
|
547
|
-
}
|
|
548
|
-
function fitToContent(column) {
|
|
549
|
-
let width = 10;
|
|
550
|
-
for (let idx = 0, len = grid.getDataLength(); idx < len; idx++) {
|
|
551
|
-
//const d = grid.getDataItem(idx);
|
|
552
|
-
width = Math.max(width, getContentWidth(column, idx));
|
|
553
|
-
}
|
|
554
|
-
column.width = width;
|
|
555
|
-
grid.setColumns(grid.getColumns());
|
|
556
|
-
// TODO: raise column resize event
|
|
557
|
-
// TODO (2): find more performant way to refresh columns
|
|
558
|
-
}
|
|
559
|
-
function triggerAllFormulas() {
|
|
560
|
-
if (formulaObjects.length === 0) {
|
|
561
|
-
return;
|
|
562
|
-
}
|
|
563
|
-
for (let j = 0; j < formulaObjects.length; j++) {
|
|
564
|
-
for (let i = 0; i < data.length; i++) {
|
|
565
|
-
const val = formulaObjects[j].fnc(data[i], grid, formulaObjects[j].column);
|
|
566
|
-
data[i][formulaObjects[j].column] = val;
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
refreshData();
|
|
570
|
-
}
|
|
571
|
-
function columnHasFilter(columnId) {
|
|
572
|
-
for (let i = 0, l = (filters ? filters.length : 0); i < l; i++) {
|
|
573
|
-
if (filters[i].columnId === columnId) {
|
|
574
|
-
return true;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
return false;
|
|
578
|
-
}
|
|
579
|
-
function refreshDataItem(item) {
|
|
580
|
-
const options = grid.getOptions();
|
|
581
|
-
dataView.updateItem(item[options.primaryKey], item);
|
|
582
|
-
// formula refresh
|
|
583
|
-
for (const f in formulas) {
|
|
584
|
-
if (formulas.hasOwnProperty(f)) {
|
|
585
|
-
triggerFormula(f, item);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
grid.updateRow(dataView.getRowByItem(item));
|
|
589
|
-
}
|
|
590
|
-
function addFilter(filter, dontrefresh) {
|
|
591
|
-
let filterArray;
|
|
592
|
-
if (Array.isArray(filter)) {
|
|
593
|
-
filterArray = filter;
|
|
594
|
-
}
|
|
595
|
-
else {
|
|
596
|
-
filterArray = [filter];
|
|
597
|
-
}
|
|
598
|
-
for (let idx = 0; idx < filterArray.length; idx++) {
|
|
599
|
-
// add filter
|
|
600
|
-
filters.push(filterArray[idx]);
|
|
601
|
-
}
|
|
602
|
-
if (!dontrefresh) {
|
|
603
|
-
refreshFilters();
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
function setFilters(f, dontrefresh) {
|
|
607
|
-
filters = f;
|
|
608
|
-
if (!dontrefresh) {
|
|
609
|
-
refreshFilters();
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
function getFilters() {
|
|
613
|
-
return filters;
|
|
614
|
-
}
|
|
615
|
-
function clearFilter(columnId, dontrefresh) {
|
|
616
|
-
if (columnId === undefined) { // clear all filters
|
|
617
|
-
filters.length = 0;
|
|
618
|
-
}
|
|
619
|
-
else {
|
|
620
|
-
for (let i = 0; i < filters.length; i++) {
|
|
621
|
-
if (filters[i].columnId === columnId) {
|
|
622
|
-
filters.splice(i, 1);
|
|
623
|
-
i--;
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
if (!dontrefresh) {
|
|
628
|
-
refreshFilters();
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
function refreshFilters(noColumnHeaderRefresh) {
|
|
632
|
-
const options = grid.getOptions();
|
|
633
|
-
function client_filter(item, args) {
|
|
634
|
-
const filterArray = args;
|
|
635
|
-
// no filter present -> show all rows
|
|
636
|
-
if (filterArray.length === 0) {
|
|
637
|
-
return true;
|
|
638
|
-
}
|
|
639
|
-
if (filterArray.length === 1) {
|
|
640
|
-
return filterArray[0].match.call(null, item, filterArray[0].field);
|
|
641
|
-
}
|
|
642
|
-
else {
|
|
643
|
-
let result = true;
|
|
644
|
-
let i = 0;
|
|
645
|
-
while (i < filterArray.length) {
|
|
646
|
-
let orResult = false;
|
|
647
|
-
while (i < filterArray.length) { // combine or(s)
|
|
648
|
-
if (orResult || filterArray[i].match.call(null, item, filterArray[i].field)) {
|
|
649
|
-
orResult = true;
|
|
650
|
-
}
|
|
651
|
-
if (filterArray[i].combine !== "or") {
|
|
652
|
-
break;
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
i++;
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
if (!orResult) {
|
|
659
|
-
result = false;
|
|
660
|
-
break;
|
|
661
|
-
}
|
|
662
|
-
i++;
|
|
663
|
-
}
|
|
664
|
-
return result;
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
if (options.mode === "client") {
|
|
668
|
-
dataView.setFilterArgs(filters);
|
|
669
|
-
dataView.setFilter(client_filter);
|
|
670
|
-
}
|
|
671
|
-
// redraw columns
|
|
672
|
-
if (!noColumnHeaderRefresh) {
|
|
673
|
-
grid.setColumns(grid.getColumns());
|
|
674
|
-
}
|
|
675
|
-
grid.onFiltersChanged.notify();
|
|
676
|
-
}
|
|
677
|
-
function getSelectedItems() {
|
|
678
|
-
const selRows = grid.getSelectedRows();
|
|
679
|
-
const rows = [];
|
|
680
|
-
for (let i = 0; i < selRows.length; i++) {
|
|
681
|
-
const rowIdx = selRows[i];
|
|
682
|
-
const toPush = dataView.getItem(rowIdx);
|
|
683
|
-
if (toPush !== undefined && !toPush.__group && !toPush.__groupTotals) {
|
|
684
|
-
rows.push(toPush);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
return rows;
|
|
688
|
-
}
|
|
689
|
-
function getRowMoveManager() {
|
|
690
|
-
return rowMoveManager;
|
|
691
|
-
}
|
|
692
|
-
function getHeaderMenu() {
|
|
693
|
-
return headerMenu;
|
|
694
|
-
}
|
|
695
|
-
// function setHierachy(o: IGridTreeOptions): GridTree {
|
|
696
|
-
// return new GridTree(this, o);
|
|
697
|
-
// }
|
|
698
|
-
createMe();
|
|
699
|
-
return $.shallowExtend(grid, {
|
|
700
|
-
dataView,
|
|
701
|
-
setHeight,
|
|
702
|
-
getHeight,
|
|
703
|
-
sort,
|
|
704
|
-
refreshData,
|
|
705
|
-
setData,
|
|
706
|
-
getData,
|
|
707
|
-
refresh,
|
|
708
|
-
addFormula,
|
|
709
|
-
getFormattedValue,
|
|
710
|
-
getContentWidth,
|
|
711
|
-
fitToContent,
|
|
712
|
-
triggerAllFormulas,
|
|
713
|
-
columnHasFilter,
|
|
714
|
-
refreshDataItem,
|
|
715
|
-
addFilter,
|
|
716
|
-
setFilters,
|
|
717
|
-
getFilters,
|
|
718
|
-
clearFilter,
|
|
719
|
-
refreshFilters,
|
|
720
|
-
getSelectedItems,
|
|
721
|
-
getRowMoveManager,
|
|
722
|
-
getHeaderMenu,
|
|
723
|
-
refreshColumnGroups: CreateColumnGroups
|
|
724
|
-
// setHierachy
|
|
725
|
-
});
|
|
726
|
-
}
|
|
1
|
+
import { Slick } from "./slick.core";
|
|
2
|
+
import { SlickGrid } from "./slick.grid";
|
|
3
|
+
import { RowSelectionModel } from "./plugins/slick.rowselectionmodel";
|
|
4
|
+
import { DataView } from "./slick.dataview";
|
|
5
|
+
import { GroupItemMetadataProvider } from "./slick.groupitemmetadataprovider";
|
|
6
|
+
import { jQueryReplacement } from "../core/jq";
|
|
7
|
+
import { HeaderMenu } from "./plugins/slick.headermenu";
|
|
8
|
+
import { HeaderButtons } from "./plugins/slick.headerbuttons";
|
|
9
|
+
import { TextFormatter } from "./slick.formatters";
|
|
10
|
+
import { ExcelFilter } from "./filterDialogs/excelFilter";
|
|
11
|
+
import { UILang } from "../core/lang";
|
|
12
|
+
import { RowMoveManager } from "./plugins/slick.rowmovemanager";
|
|
13
|
+
import { Overlays } from "./plugins/ext.overlay";
|
|
14
|
+
import { helper } from "../core/helper";
|
|
15
|
+
const $ = jQueryReplacement;
|
|
16
|
+
export function createJSLGrid(selector, data, columns, option) {
|
|
17
|
+
const formulaObjects = [];
|
|
18
|
+
let headerMenu;
|
|
19
|
+
let headerButtons;
|
|
20
|
+
const formulas = {};
|
|
21
|
+
let container;
|
|
22
|
+
let filters = [];
|
|
23
|
+
let customCommandHandler;
|
|
24
|
+
let grid;
|
|
25
|
+
let dataView;
|
|
26
|
+
let rowMoveManager;
|
|
27
|
+
//let options: ISlickCreatorOptions;
|
|
28
|
+
function createMe() {
|
|
29
|
+
sanitizeColumns(columns);
|
|
30
|
+
const options = $.shallowExtend({ explicitInitialization: true, mode: "client" }, option);
|
|
31
|
+
container = typeof (selector) === "string" ?
|
|
32
|
+
document.querySelector(selector) :
|
|
33
|
+
selector;
|
|
34
|
+
if (!container) {
|
|
35
|
+
throw new Error("error: selector for SlickCreator is invalid");
|
|
36
|
+
}
|
|
37
|
+
if (options.showColumnGroups) {
|
|
38
|
+
options.createPreHeaderPanel = true;
|
|
39
|
+
options.showPreHeaderPanel = true;
|
|
40
|
+
}
|
|
41
|
+
customCommandHandler = option.editCommandHandler;
|
|
42
|
+
options.editCommandHandler = (a, b, c) => { handleEditCommand(a, b, c); };
|
|
43
|
+
const groupItemMetadataProvider = options.groupItemMetadataProvider || GroupItemMetadataProvider(options.groupItemOptions);
|
|
44
|
+
if (options.dataView != null) {
|
|
45
|
+
dataView = options.dataView;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
dataView = new DataView({ inlineFilters: true, groupItemMetadataProvider });
|
|
49
|
+
dataView.setItems(data, options.primaryKey);
|
|
50
|
+
}
|
|
51
|
+
grid = new SlickGrid(container, dataView, columns, options);
|
|
52
|
+
grid.registerPlugin(groupItemMetadataProvider);
|
|
53
|
+
grid.setSelectionModel(new RowSelectionModel());
|
|
54
|
+
grid.onHeaderCellRendered.subscribe((e, args) => {
|
|
55
|
+
if (columnHasFilter(args.column.id)) {
|
|
56
|
+
//this column is filtered
|
|
57
|
+
args.node.classList.add("slick-filtered-header");
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
addCustomEvents();
|
|
61
|
+
setupDefaultSort();
|
|
62
|
+
setupChangeEvents();
|
|
63
|
+
if (options.showHeaderMenu) {
|
|
64
|
+
setupHeaderMenu();
|
|
65
|
+
}
|
|
66
|
+
setupHeaderButtons();
|
|
67
|
+
if (options.allowRowMove) {
|
|
68
|
+
rowMoveManager = new RowMoveManager({
|
|
69
|
+
cancelEditOnDrag: true,
|
|
70
|
+
singleRowMove: true,
|
|
71
|
+
disableRowSelection: true,
|
|
72
|
+
hideRowMoveShadow: false, // defaults to true
|
|
73
|
+
rowMoveShadowScale: 0.7, // defaults to 0.75
|
|
74
|
+
rowMoveShadowOpacity: 0.9 // defaults to 0.95
|
|
75
|
+
});
|
|
76
|
+
grid.registerPlugin(rowMoveManager);
|
|
77
|
+
rowMoveManager.onBeforeMoveRows.subscribe(function (e, args) {
|
|
78
|
+
// debugger;
|
|
79
|
+
});
|
|
80
|
+
rowMoveManager.onMoveRows.subscribe(function (e, args) {
|
|
81
|
+
var extractedRows = [], left, right;
|
|
82
|
+
var rows = args.rows;
|
|
83
|
+
var insertBefore = args.insertBefore;
|
|
84
|
+
left = data.slice(0, insertBefore);
|
|
85
|
+
right = data.slice(insertBefore, data.length);
|
|
86
|
+
rows.sort(function (a, b) { return a - b; });
|
|
87
|
+
for (var i = 0; i < rows.length; i++) {
|
|
88
|
+
extractedRows.push(data[rows[i]]);
|
|
89
|
+
}
|
|
90
|
+
rows.reverse();
|
|
91
|
+
for (var i = 0; i < rows.length; i++) {
|
|
92
|
+
var row = rows[i];
|
|
93
|
+
if (row < insertBefore) {
|
|
94
|
+
left.splice(row, 1);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
right.splice(row - insertBefore, 1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
data = left.concat(extractedRows.concat(right));
|
|
101
|
+
var selectedRows = [];
|
|
102
|
+
for (var i = 0; i < rows.length; i++)
|
|
103
|
+
selectedRows.push(left.length + i);
|
|
104
|
+
// grid.resetActiveCell();
|
|
105
|
+
dataView.beginUpdate();
|
|
106
|
+
dataView.setItems(data);
|
|
107
|
+
dataView.endUpdate();
|
|
108
|
+
grid.render();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const isTouch = helper.isTouchScreen();
|
|
112
|
+
if (option.enableFillDown && !isTouch) {
|
|
113
|
+
var overlayPlugin = new Overlays({});
|
|
114
|
+
// Event fires when a range is selected
|
|
115
|
+
overlayPlugin.onFillUpDown.subscribe(function (e, args) {
|
|
116
|
+
const column = grid.getColumns()[args.range.fromCell];
|
|
117
|
+
// Ensure the column is editable
|
|
118
|
+
if (column.editor == null || column.readonly || !grid.getOptions().editable) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
// Find the initial value
|
|
122
|
+
dataView.beginUpdate();
|
|
123
|
+
let value;
|
|
124
|
+
const items = [];
|
|
125
|
+
if (args.direction === "down") {
|
|
126
|
+
const item = dataView.getItem(args.range.fromRow);
|
|
127
|
+
value = grid.getDataItemValueForColumn(item, column); // item[column.field];
|
|
128
|
+
// Copy the value down
|
|
129
|
+
for (let i = args.range.fromRow + 1; i <= args.range.toRow; i++) {
|
|
130
|
+
if (grid.onBeforeEditCell.notify({ row: i, cell: args.range.fromCell, item: dataView.getItem(i), column }, e) !== false) {
|
|
131
|
+
const currentItem = dataView.getItem(i);
|
|
132
|
+
items.push(currentItem);
|
|
133
|
+
// if (options.setDataItemValueForColumn != null) {
|
|
134
|
+
// options.setDataItemValueForColumn(currentItem, column, value);
|
|
135
|
+
// } else {
|
|
136
|
+
// dataView.getItem(i)[column.field] = value;
|
|
137
|
+
// }
|
|
138
|
+
// grid.invalidateRow(i);
|
|
139
|
+
// grid.onAfterEdit.notify({ grid, oldValue, newValue: value, column, item: dataView.getItem(i) }, e);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const item = dataView.getItem(args.range.toRow);
|
|
145
|
+
items.push(item);
|
|
146
|
+
value = grid.getDataItemValueForColumn(item, column); // item[column.field];
|
|
147
|
+
// Copy the value up
|
|
148
|
+
for (let i = args.range.fromRow; i <= args.range.toRow - 1; i++) {
|
|
149
|
+
if (grid.onBeforeEditCell.notify({ row: i, cell: args.range.fromCell, item: dataView.getItem(i), column }, e) !== false) {
|
|
150
|
+
const currentItem = dataView.getItem(i);
|
|
151
|
+
items.push(currentItem);
|
|
152
|
+
// if (options.setDataItemValueForColumn != null) {
|
|
153
|
+
// options.setDataItemValueForColumn(currentItem, column, value);
|
|
154
|
+
// } else {
|
|
155
|
+
// dataView.getItem(i)[column.field] = value;
|
|
156
|
+
// }
|
|
157
|
+
// grid.invalidateRow(i);
|
|
158
|
+
// grid.onAfterEdit.notify({ grid, oldValue, newValue: value, column, item: dataView.getItem(i) }, e);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
grid.onAfterFillDown.notify({ grid, value, column, direction: args.direction, range: args.range, items: items }, e);
|
|
163
|
+
dataView.endUpdate();
|
|
164
|
+
grid.render();
|
|
165
|
+
});
|
|
166
|
+
grid.registerPlugin(overlayPlugin);
|
|
167
|
+
}
|
|
168
|
+
if (!option.explicitInitialization) {
|
|
169
|
+
grid.init();
|
|
170
|
+
}
|
|
171
|
+
if (options.showColumnGroups) {
|
|
172
|
+
setTimeout(() => {
|
|
173
|
+
// TODO -> find better solution then timeout
|
|
174
|
+
grid.onColumnsResized.subscribe(() => {
|
|
175
|
+
CreateColumnGroups();
|
|
176
|
+
});
|
|
177
|
+
CreateColumnGroups();
|
|
178
|
+
}, 1);
|
|
179
|
+
}
|
|
180
|
+
if (options.saveColumnsKey) {
|
|
181
|
+
grid.onColumnsResized.subscribe(() => {
|
|
182
|
+
storeColumnSettings();
|
|
183
|
+
});
|
|
184
|
+
grid.onColumnsReordered.subscribe(() => {
|
|
185
|
+
storeColumnSettings();
|
|
186
|
+
});
|
|
187
|
+
loadColumnSettings();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function CreateColumnGroups() {
|
|
191
|
+
const options = grid.getOptions();
|
|
192
|
+
const columns = grid.getColumns();
|
|
193
|
+
if (options.frozenColumn >= 0) {
|
|
194
|
+
// Add column groups to left panel
|
|
195
|
+
let $preHeaderPanel = $(grid.getPreHeaderPanel());
|
|
196
|
+
renderHeaderGroups($preHeaderPanel, 0, options.frozenColumn + 1);
|
|
197
|
+
// Add column groups to right panel
|
|
198
|
+
$preHeaderPanel = $(grid.getPreHeaderPanelRight());
|
|
199
|
+
renderHeaderGroups($preHeaderPanel, options.frozenColumn + 1, columns.length);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
const $preHeaderPanel = $(grid.getPreHeaderPanel());
|
|
203
|
+
renderHeaderGroups($preHeaderPanel, 0, columns.length);
|
|
204
|
+
}
|
|
205
|
+
function renderHeaderGroups(preHeaderPanel, start, end) {
|
|
206
|
+
preHeaderPanel.empty()
|
|
207
|
+
.addClass("slick-header-columns")
|
|
208
|
+
.css("left", "-1000px")
|
|
209
|
+
.width(grid.getHeadersWidth());
|
|
210
|
+
preHeaderPanel[0].parentElement.classList.add("slick-header");
|
|
211
|
+
const headerColumnWidthDiff = grid.getHeaderColumnWidthDiff();
|
|
212
|
+
let header;
|
|
213
|
+
let lastColumnGroup = "";
|
|
214
|
+
let widthTotal = 0;
|
|
215
|
+
for (let i = start; i < end; i++) {
|
|
216
|
+
const m = columns[i];
|
|
217
|
+
if (lastColumnGroup === m.columnGroup && i > start) {
|
|
218
|
+
widthTotal += m.width;
|
|
219
|
+
header.width(widthTotal - headerColumnWidthDiff);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
widthTotal = m.width;
|
|
223
|
+
header = $("<div class='ui-state-default slick-header-column' />")
|
|
224
|
+
.html("<span class='slick-column-name'>" + (m.columnGroup || '') + "</span>")
|
|
225
|
+
.width(m.width - headerColumnWidthDiff)
|
|
226
|
+
.appendTo(preHeaderPanel);
|
|
227
|
+
}
|
|
228
|
+
lastColumnGroup = m.columnGroup;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function storeColumnSettings() {
|
|
233
|
+
const cols = grid.getColumns();
|
|
234
|
+
const options = grid.getOptions();
|
|
235
|
+
const colSettings = cols.map((c) => ({ id: c.id, width: c.width }));
|
|
236
|
+
if (window.localStorage) {
|
|
237
|
+
localStorage.setItem("_grid_col_settings_" + options.saveColumnsKey, JSON.stringify(colSettings));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function loadColumnSettings() {
|
|
241
|
+
if (!window.localStorage) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const options = grid.getOptions();
|
|
245
|
+
const key = options.saveColumnsKey;
|
|
246
|
+
if (key) {
|
|
247
|
+
const cols = grid.getColumns();
|
|
248
|
+
const colSettings = JSON.parse(localStorage.getItem("_grid_col_settings_" + key));
|
|
249
|
+
if (!colSettings) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
for (let i = 0; i < colSettings.length; i++) {
|
|
253
|
+
for (let j = 0; j < cols.length; j++) {
|
|
254
|
+
if (cols[j].id === colSettings[i].id) {
|
|
255
|
+
const c = cols[j];
|
|
256
|
+
c.width = colSettings[i].width;
|
|
257
|
+
if (i !== j) {
|
|
258
|
+
cols.splice(j, 1);
|
|
259
|
+
cols.splice(i, 0, c);
|
|
260
|
+
}
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
grid.setColumns(cols);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function sanitizeColumns(cols) {
|
|
269
|
+
for (let i = 0; i < cols.length; i++) {
|
|
270
|
+
const c = cols[i];
|
|
271
|
+
if (c.field === undefined && c.id) {
|
|
272
|
+
c.field = c.id;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function addCustomEvents() {
|
|
277
|
+
grid.onAfterEdit = new Slick.Event();
|
|
278
|
+
grid.onFiltersChanged = new Slick.Event();
|
|
279
|
+
grid.onAfterFillDown = new Slick.Event();
|
|
280
|
+
}
|
|
281
|
+
function setupChangeEvents() {
|
|
282
|
+
dataView.onRowsChanged.subscribe((e, args) => {
|
|
283
|
+
grid.invalidateRows(args.rows);
|
|
284
|
+
grid.render();
|
|
285
|
+
// for (let idx = 0; idx < args.rows.length; idx++) {
|
|
286
|
+
// grid.updateRow(args.rows[idx]);
|
|
287
|
+
// }
|
|
288
|
+
// grid.invalidate();
|
|
289
|
+
});
|
|
290
|
+
dataView.onRowCountChanged.subscribe((e, args) => {
|
|
291
|
+
grid.updateRowCount();
|
|
292
|
+
grid.render();
|
|
293
|
+
});
|
|
294
|
+
grid.onAddNewRow.subscribe((e, args) => {
|
|
295
|
+
const options = grid.getOptions();
|
|
296
|
+
if (options.provideDefaultValues != null) {
|
|
297
|
+
const result = options.provideDefaultValues(args.item);
|
|
298
|
+
if (result === false) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
dataView.addItem(args.item);
|
|
303
|
+
grid.onAfterEdit.notify({
|
|
304
|
+
grid,
|
|
305
|
+
oldValue: undefined,
|
|
306
|
+
newValue: grid.getDataItemValueForColumn(args.item, args.column),
|
|
307
|
+
column: args.column,
|
|
308
|
+
item: args.item
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function setupDefaultSort() {
|
|
313
|
+
const options = grid.getOptions();
|
|
314
|
+
if (options.mode === "client") {
|
|
315
|
+
grid.onSort.subscribe((e, args) => {
|
|
316
|
+
sort(args.sortCol, args.sortAsc);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
// TODO: multi column sort
|
|
320
|
+
}
|
|
321
|
+
function setupHeaderButtons() {
|
|
322
|
+
headerButtons = new HeaderButtons({});
|
|
323
|
+
grid.registerPlugin(headerButtons);
|
|
324
|
+
}
|
|
325
|
+
function setupHeaderMenu() {
|
|
326
|
+
headerMenu = new HeaderMenu({});
|
|
327
|
+
grid.registerPlugin(headerMenu);
|
|
328
|
+
headerMenu.onBeforeMenuShow.subscribe((e, args) => {
|
|
329
|
+
const column = args.column;
|
|
330
|
+
const menu = args.menu;
|
|
331
|
+
if (column.sortable) {
|
|
332
|
+
menu.items.push({
|
|
333
|
+
title: UILang.grid.Sort + " " + UILang.grid.Asc,
|
|
334
|
+
command: "sort-asc"
|
|
335
|
+
});
|
|
336
|
+
menu.items.push({
|
|
337
|
+
title: UILang.grid.Sort + " " + UILang.grid.Desc,
|
|
338
|
+
command: "sort-desc"
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
if (column.filterable) {
|
|
342
|
+
menu.items.push({
|
|
343
|
+
title: UILang.grid.Filter,
|
|
344
|
+
command: "filter"
|
|
345
|
+
});
|
|
346
|
+
if (filters.filter((f) => f.columnId === column.id).length > 0) {
|
|
347
|
+
menu.items.push({
|
|
348
|
+
title: UILang.grid.ClearFilter,
|
|
349
|
+
command: "clear-filter"
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
headerMenu.onCommand.subscribe((e, args) => {
|
|
355
|
+
if (args.command === "sort-asc" || args.command === "sort-desc") {
|
|
356
|
+
grid.onSort.notify({
|
|
357
|
+
sortAsc: args.command === "sort-asc",
|
|
358
|
+
sortCol: args.column,
|
|
359
|
+
columnId: args.column.id,
|
|
360
|
+
sortCols: [{ columnId: args.column.id, sortCol: args.column, sortAsc: args.command === "sort-asc" }],
|
|
361
|
+
multiColumnSort: false
|
|
362
|
+
}, e);
|
|
363
|
+
// sort(args.column, args.command === "sort-asc");
|
|
364
|
+
}
|
|
365
|
+
else if (args.command === "filter") {
|
|
366
|
+
const options = grid.getOptions();
|
|
367
|
+
if (options.showFilterDialog != null) {
|
|
368
|
+
options.showFilterDialog(args.column, grid);
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
new ExcelFilter(grid).show(args.column);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
else if (args.command === "clear-filter") {
|
|
375
|
+
clearFilter(args.column.id);
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
// refresh formulas depending on the given column
|
|
380
|
+
function triggerFormula(column, item) {
|
|
381
|
+
const options = grid.getOptions();
|
|
382
|
+
const f = formulas[column];
|
|
383
|
+
if (f) {
|
|
384
|
+
for (let i = 0, l = f.length; i < l; i++) {
|
|
385
|
+
if (options.setDataItemValueForColumn != null) {
|
|
386
|
+
options.setDataItemValueForColumn(item, f[i].column, f[i].fnc(item, column));
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
item[f[i].column] = f[i].fnc(item, column);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function handleEditCommand(item, column, editCommand) {
|
|
395
|
+
const options = grid.getOptions();
|
|
396
|
+
const oldVal = grid.getDataItemValueForColumn(item, column);
|
|
397
|
+
if (customCommandHandler) {
|
|
398
|
+
customCommandHandler(item, column, editCommand);
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
editCommand.execute();
|
|
402
|
+
}
|
|
403
|
+
triggerFormula(column.field, item);
|
|
404
|
+
dataView.updateItem(item[options.primaryKey], item);
|
|
405
|
+
const afterEditResult = grid.onAfterEdit.notify({
|
|
406
|
+
grid,
|
|
407
|
+
oldValue: oldVal,
|
|
408
|
+
newValue: grid.getDataItemValueForColumn(item, column),
|
|
409
|
+
column,
|
|
410
|
+
item
|
|
411
|
+
});
|
|
412
|
+
if (afterEditResult === false) {
|
|
413
|
+
if (options.setDataItemValueForColumn != null) {
|
|
414
|
+
options.setDataItemValueForColumn(item, column, oldVal);
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
item[column.field] = oldVal;
|
|
418
|
+
}
|
|
419
|
+
triggerFormula(column.field, item);
|
|
420
|
+
dataView.updateItem(item[options.primaryKey], item);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
function setHeight(height) {
|
|
424
|
+
$(container).height(height);
|
|
425
|
+
grid.resizeCanvas();
|
|
426
|
+
}
|
|
427
|
+
function getHeight() {
|
|
428
|
+
return $(container).height();
|
|
429
|
+
}
|
|
430
|
+
function sort(column, sortAsc) {
|
|
431
|
+
function _comparer(a, b) {
|
|
432
|
+
let x = grid.getDataItemValueForColumn(a, column);
|
|
433
|
+
let y = grid.getDataItemValueForColumn(b, column);
|
|
434
|
+
if (typeof x === "string" && typeof y === "string") {
|
|
435
|
+
x = x.toLocaleLowerCase();
|
|
436
|
+
y = y.toLocaleLowerCase();
|
|
437
|
+
}
|
|
438
|
+
if (x == null && y != null) {
|
|
439
|
+
return -1;
|
|
440
|
+
}
|
|
441
|
+
else if (x != null && y == null) {
|
|
442
|
+
return 1;
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
return (x === y ? 0 : (x > y ? 1 : -1));
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function _visibleComparer(a, b) {
|
|
449
|
+
const x = column.formatter(0, 0, grid.getDataItemValueForColumn(a, column), column, a);
|
|
450
|
+
const y = column.formatter(0, 0, grid.getDataItemValueForColumn(b, column), column, b);
|
|
451
|
+
let xStr = (Object.prototype.toString.call(x) !== "[object Object]" ? x : x.text);
|
|
452
|
+
let yStr = (Object.prototype.toString.call(y) !== "[object Object]" ? y : y.text);
|
|
453
|
+
if (typeof x === "string" && typeof y === "string") {
|
|
454
|
+
xStr = x.toLocaleLowerCase();
|
|
455
|
+
yStr = y.toLocaleLowerCase();
|
|
456
|
+
}
|
|
457
|
+
return (xStr === yStr ? 0 : (xStr > yStr ? 1 : -1));
|
|
458
|
+
}
|
|
459
|
+
const comparer = column.comparer || (column.sortByVisibleValue ? _visibleComparer : _comparer);
|
|
460
|
+
dataView.sort(comparer, sortAsc ? true : false);
|
|
461
|
+
}
|
|
462
|
+
function setData(newData) {
|
|
463
|
+
data = newData;
|
|
464
|
+
dataView.setItems(data);
|
|
465
|
+
refresh();
|
|
466
|
+
}
|
|
467
|
+
function getData() {
|
|
468
|
+
return data;
|
|
469
|
+
}
|
|
470
|
+
function refreshData() {
|
|
471
|
+
// var selrows = self.getSelectedRows();
|
|
472
|
+
dataView.setItems(data);
|
|
473
|
+
// self.setSelectedRows(selrows);
|
|
474
|
+
refresh();
|
|
475
|
+
}
|
|
476
|
+
function refresh() {
|
|
477
|
+
grid.invalidate();
|
|
478
|
+
}
|
|
479
|
+
function addFormula(field, fnc, usedColumns) {
|
|
480
|
+
formulaObjects.push({ fnc, column: field });
|
|
481
|
+
for (let i = 0; i < usedColumns.length; i++) {
|
|
482
|
+
if (!formulas[usedColumns[i]]) {
|
|
483
|
+
formulas[usedColumns[i]] = [];
|
|
484
|
+
}
|
|
485
|
+
formulas[usedColumns[i]].push({ fnc, column: field });
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* returns the string representation of a value based on column settings
|
|
490
|
+
*/
|
|
491
|
+
function getFormattedValue(column, value, item) {
|
|
492
|
+
const formatter = column.formatter || TextFormatter;
|
|
493
|
+
const formatterResult = formatter(0, 0, value, column, item, grid);
|
|
494
|
+
return (Object.prototype.toString.call(formatterResult) !== "[object Object]" ?
|
|
495
|
+
formatterResult :
|
|
496
|
+
(formatterResult.text));
|
|
497
|
+
}
|
|
498
|
+
function getContentWidth(column, row) {
|
|
499
|
+
const item = dataView.getItem(row);
|
|
500
|
+
const html = getFormattedValue(column, grid.getDataItemValueForColumn(item, column), item);
|
|
501
|
+
if (html.indexOf("<") >= 0) {
|
|
502
|
+
return calcLengthInternal(html, true) + 12;
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
if (convertElement == null) {
|
|
506
|
+
convertElement = document.createElement("span");
|
|
507
|
+
}
|
|
508
|
+
convertElement.innerHTML = html;
|
|
509
|
+
return calcTextLength(convertElement.textContent) + 12;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
let measureElement;
|
|
513
|
+
let convertElement;
|
|
514
|
+
const charWidth = {};
|
|
515
|
+
function calcTextLength(text) {
|
|
516
|
+
let result = 0;
|
|
517
|
+
for (let i = 0; i < text.length; i++) {
|
|
518
|
+
const c = text[i];
|
|
519
|
+
let w = charWidth[c];
|
|
520
|
+
if (w == null) {
|
|
521
|
+
charWidth[c] = w = calcLengthInternal(c, false);
|
|
522
|
+
}
|
|
523
|
+
result += w;
|
|
524
|
+
}
|
|
525
|
+
return result;
|
|
526
|
+
}
|
|
527
|
+
function calcLengthInternal(c, isHTML) {
|
|
528
|
+
if (measureElement == null) {
|
|
529
|
+
measureElement = document.createElement("span");
|
|
530
|
+
measureElement.style.top = "-100000px";
|
|
531
|
+
measureElement.style.position = "absolute";
|
|
532
|
+
measureElement.style.whiteSpace = "pre";
|
|
533
|
+
document.body.appendChild(measureElement);
|
|
534
|
+
grid.onBeforeDestroy.subscribe(() => {
|
|
535
|
+
if (measureElement.parentElement != null) {
|
|
536
|
+
measureElement.parentElement.removeChild(measureElement);
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
if (isHTML) {
|
|
541
|
+
measureElement.innerHTML = c;
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
measureElement.textContent = c;
|
|
545
|
+
}
|
|
546
|
+
return measureElement.getBoundingClientRect().width;
|
|
547
|
+
}
|
|
548
|
+
function fitToContent(column) {
|
|
549
|
+
let width = 10;
|
|
550
|
+
for (let idx = 0, len = grid.getDataLength(); idx < len; idx++) {
|
|
551
|
+
//const d = grid.getDataItem(idx);
|
|
552
|
+
width = Math.max(width, getContentWidth(column, idx));
|
|
553
|
+
}
|
|
554
|
+
column.width = width;
|
|
555
|
+
grid.setColumns(grid.getColumns());
|
|
556
|
+
// TODO: raise column resize event
|
|
557
|
+
// TODO (2): find more performant way to refresh columns
|
|
558
|
+
}
|
|
559
|
+
function triggerAllFormulas() {
|
|
560
|
+
if (formulaObjects.length === 0) {
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
for (let j = 0; j < formulaObjects.length; j++) {
|
|
564
|
+
for (let i = 0; i < data.length; i++) {
|
|
565
|
+
const val = formulaObjects[j].fnc(data[i], grid, formulaObjects[j].column);
|
|
566
|
+
data[i][formulaObjects[j].column] = val;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
refreshData();
|
|
570
|
+
}
|
|
571
|
+
function columnHasFilter(columnId) {
|
|
572
|
+
for (let i = 0, l = (filters ? filters.length : 0); i < l; i++) {
|
|
573
|
+
if (filters[i].columnId === columnId) {
|
|
574
|
+
return true;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return false;
|
|
578
|
+
}
|
|
579
|
+
function refreshDataItem(item) {
|
|
580
|
+
const options = grid.getOptions();
|
|
581
|
+
dataView.updateItem(item[options.primaryKey], item);
|
|
582
|
+
// formula refresh
|
|
583
|
+
for (const f in formulas) {
|
|
584
|
+
if (formulas.hasOwnProperty(f)) {
|
|
585
|
+
triggerFormula(f, item);
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
grid.updateRow(dataView.getRowByItem(item));
|
|
589
|
+
}
|
|
590
|
+
function addFilter(filter, dontrefresh) {
|
|
591
|
+
let filterArray;
|
|
592
|
+
if (Array.isArray(filter)) {
|
|
593
|
+
filterArray = filter;
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
filterArray = [filter];
|
|
597
|
+
}
|
|
598
|
+
for (let idx = 0; idx < filterArray.length; idx++) {
|
|
599
|
+
// add filter
|
|
600
|
+
filters.push(filterArray[idx]);
|
|
601
|
+
}
|
|
602
|
+
if (!dontrefresh) {
|
|
603
|
+
refreshFilters();
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
function setFilters(f, dontrefresh) {
|
|
607
|
+
filters = f;
|
|
608
|
+
if (!dontrefresh) {
|
|
609
|
+
refreshFilters();
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
function getFilters() {
|
|
613
|
+
return filters;
|
|
614
|
+
}
|
|
615
|
+
function clearFilter(columnId, dontrefresh) {
|
|
616
|
+
if (columnId === undefined) { // clear all filters
|
|
617
|
+
filters.length = 0;
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
for (let i = 0; i < filters.length; i++) {
|
|
621
|
+
if (filters[i].columnId === columnId) {
|
|
622
|
+
filters.splice(i, 1);
|
|
623
|
+
i--;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
if (!dontrefresh) {
|
|
628
|
+
refreshFilters();
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
function refreshFilters(noColumnHeaderRefresh) {
|
|
632
|
+
const options = grid.getOptions();
|
|
633
|
+
function client_filter(item, args) {
|
|
634
|
+
const filterArray = args;
|
|
635
|
+
// no filter present -> show all rows
|
|
636
|
+
if (filterArray.length === 0) {
|
|
637
|
+
return true;
|
|
638
|
+
}
|
|
639
|
+
if (filterArray.length === 1) {
|
|
640
|
+
return filterArray[0].match.call(null, item, filterArray[0].field);
|
|
641
|
+
}
|
|
642
|
+
else {
|
|
643
|
+
let result = true;
|
|
644
|
+
let i = 0;
|
|
645
|
+
while (i < filterArray.length) {
|
|
646
|
+
let orResult = false;
|
|
647
|
+
while (i < filterArray.length) { // combine or(s)
|
|
648
|
+
if (orResult || filterArray[i].match.call(null, item, filterArray[i].field)) {
|
|
649
|
+
orResult = true;
|
|
650
|
+
}
|
|
651
|
+
if (filterArray[i].combine !== "or") {
|
|
652
|
+
break;
|
|
653
|
+
}
|
|
654
|
+
else {
|
|
655
|
+
i++;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
if (!orResult) {
|
|
659
|
+
result = false;
|
|
660
|
+
break;
|
|
661
|
+
}
|
|
662
|
+
i++;
|
|
663
|
+
}
|
|
664
|
+
return result;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
if (options.mode === "client") {
|
|
668
|
+
dataView.setFilterArgs(filters);
|
|
669
|
+
dataView.setFilter(client_filter);
|
|
670
|
+
}
|
|
671
|
+
// redraw columns
|
|
672
|
+
if (!noColumnHeaderRefresh) {
|
|
673
|
+
grid.setColumns(grid.getColumns());
|
|
674
|
+
}
|
|
675
|
+
grid.onFiltersChanged.notify();
|
|
676
|
+
}
|
|
677
|
+
function getSelectedItems() {
|
|
678
|
+
const selRows = grid.getSelectedRows();
|
|
679
|
+
const rows = [];
|
|
680
|
+
for (let i = 0; i < selRows.length; i++) {
|
|
681
|
+
const rowIdx = selRows[i];
|
|
682
|
+
const toPush = dataView.getItem(rowIdx);
|
|
683
|
+
if (toPush !== undefined && !toPush.__group && !toPush.__groupTotals) {
|
|
684
|
+
rows.push(toPush);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
return rows;
|
|
688
|
+
}
|
|
689
|
+
function getRowMoveManager() {
|
|
690
|
+
return rowMoveManager;
|
|
691
|
+
}
|
|
692
|
+
function getHeaderMenu() {
|
|
693
|
+
return headerMenu;
|
|
694
|
+
}
|
|
695
|
+
// function setHierachy(o: IGridTreeOptions): GridTree {
|
|
696
|
+
// return new GridTree(this, o);
|
|
697
|
+
// }
|
|
698
|
+
createMe();
|
|
699
|
+
return $.shallowExtend(grid, {
|
|
700
|
+
dataView,
|
|
701
|
+
setHeight,
|
|
702
|
+
getHeight,
|
|
703
|
+
sort,
|
|
704
|
+
refreshData,
|
|
705
|
+
setData,
|
|
706
|
+
getData,
|
|
707
|
+
refresh,
|
|
708
|
+
addFormula,
|
|
709
|
+
getFormattedValue,
|
|
710
|
+
getContentWidth,
|
|
711
|
+
fitToContent,
|
|
712
|
+
triggerAllFormulas,
|
|
713
|
+
columnHasFilter,
|
|
714
|
+
refreshDataItem,
|
|
715
|
+
addFilter,
|
|
716
|
+
setFilters,
|
|
717
|
+
getFilters,
|
|
718
|
+
clearFilter,
|
|
719
|
+
refreshFilters,
|
|
720
|
+
getSelectedItems,
|
|
721
|
+
getRowMoveManager,
|
|
722
|
+
getHeaderMenu,
|
|
723
|
+
refreshColumnGroups: CreateColumnGroups
|
|
724
|
+
// setHierachy
|
|
725
|
+
});
|
|
726
|
+
}
|