@schukai/monster 3.60.0 → 3.62.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +20 -0
- package/package.json +1 -1
- package/source/components/datatable/datatable.mjs +723 -599
- package/source/components/datatable/stylesheet/change-button.mjs +1 -1
- package/source/components/datatable/stylesheet/column-bar.mjs +1 -1
- package/source/components/datatable/stylesheet/dataset.mjs +1 -1
- package/source/components/datatable/stylesheet/datatable.mjs +1 -1
- package/source/components/datatable/stylesheet/embedded-pagination.mjs +1 -1
- package/source/components/datatable/stylesheet/filter.mjs +1 -1
- package/source/components/datatable/stylesheet/pagination.mjs +1 -1
- package/source/components/datatable/stylesheet/save-button.mjs +1 -1
- package/source/components/datatable/stylesheet/select-filter.mjs +1 -1
- package/source/components/datatable/stylesheet/status.mjs +1 -1
- package/source/components/datatable/util.mjs +10 -7
- package/source/components/events.mjs +17 -0
- package/source/components/form/api-button.mjs +4 -0
- package/source/components/form/button-bar.mjs +1 -1
- package/source/components/form/button.mjs +1 -3
- package/source/components/form/events.mjs +28 -4
- package/source/components/form/form-field.mjs +341 -0
- package/source/components/form/reload.mjs +4 -4
- package/source/components/form/shadow-reload.mjs +1 -1
- package/source/components/form/style/form-field.pcss +4 -0
- package/source/components/form/stylesheet/action-button.mjs +1 -1
- package/source/components/form/stylesheet/button-bar.mjs +1 -1
- package/source/components/form/stylesheet/button.mjs +1 -1
- package/source/components/form/stylesheet/confirm-button.mjs +1 -1
- package/source/components/form/stylesheet/form-field.mjs +27 -0
- package/source/components/form/stylesheet/form.mjs +1 -1
- package/source/components/form/stylesheet/popper-button.mjs +1 -1
- package/source/components/form/stylesheet/select.mjs +1 -1
- package/source/components/form/stylesheet/state-button.mjs +1 -1
- package/source/components/form/stylesheet/toggle-switch.mjs +1 -1
- package/source/components/form/tabs.mjs +1 -1
- package/source/components/form/template.mjs +4 -4
- package/source/components/host/stylesheet/call-button.mjs +1 -1
- package/source/components/host/stylesheet/collapse.mjs +1 -1
- package/source/components/host/stylesheet/details.mjs +1 -1
- package/source/components/host/stylesheet/host.mjs +1 -1
- package/source/components/host/stylesheet/overlay.mjs +1 -1
- package/source/components/host/stylesheet/toggle-button.mjs +1 -1
- package/source/components/host/stylesheet/viewer.mjs +1 -1
- package/source/components/layout/events.mjs +30 -0
- package/source/components/layout/split-screen.mjs +28 -2
- package/source/components/layout/style/tabs.pcss +16 -13
- package/source/components/layout/stylesheet/tabs.mjs +1 -1
- package/source/components/layout/tabs.mjs +58 -3
- package/source/components/notify/stylesheet/message.mjs +1 -1
- package/source/components/notify/stylesheet/notify.mjs +1 -1
- package/source/components/state/stylesheet/log.mjs +1 -1
- package/source/components/state/stylesheet/state.mjs +1 -1
- package/source/components/style/border.pcss +0 -4
- package/source/components/style/link.pcss +19 -34
- package/source/components/style/mixin/button.pcss +3 -0
- package/source/components/style/mixin/form.pcss +8 -12
- package/source/components/style/mixin/property.pcss +10 -12
- package/source/components/style/mixin/typography.pcss +10 -9
- package/source/components/stylesheet/border.mjs +1 -1
- package/source/components/stylesheet/button.mjs +1 -1
- package/source/components/stylesheet/data-grid.mjs +1 -1
- package/source/components/stylesheet/form.mjs +1 -1
- package/source/components/stylesheet/link.mjs +1 -1
- package/source/components/stylesheet/property.mjs +1 -1
- package/source/components/stylesheet/typography.mjs +1 -1
- package/source/types/version.mjs +1 -1
- package/test/cases/monster.mjs +1 -1
- package/test/web/test.html +2 -2
- package/test/web/tests.js +181 -88
@@ -3,62 +3,64 @@
|
|
3
3
|
* SPDX-License-Identifier: AGPL-3.0
|
4
4
|
*/
|
5
5
|
|
6
|
-
import {
|
6
|
+
import {Datasource} from "./datasource.mjs";
|
7
7
|
import {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
assembleMethodSymbol,
|
9
|
+
CustomElement,
|
10
|
+
registerCustomElement,
|
11
|
+
getSlottedElements,
|
12
12
|
} from "../../dom/customelement.mjs";
|
13
|
-
import {
|
13
|
+
import {findTargetElementFromEvent} from "../../dom/events.mjs";
|
14
|
+
import {clone} from "../../util/clone.mjs";
|
14
15
|
import {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
isString,
|
17
|
+
isFunction,
|
18
|
+
isInstance,
|
19
|
+
isObject,
|
20
|
+
isArray,
|
20
21
|
} from "../../types/is.mjs";
|
21
|
-
import {
|
22
|
+
import {validateArray, validateInteger, validateObject} from "../../types/validate.mjs";
|
23
|
+
import {Observer} from "../../types/observer.mjs";
|
22
24
|
import {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
ATTRIBUTE_DATATABLE_HEAD,
|
26
|
+
ATTRIBUTE_DATATABLE_GRID_TEMPLATE,
|
27
|
+
ATTRIBUTE_DATASOURCE_SELECTOR,
|
28
|
+
ATTRIBUTE_DATATABLE_ALIGN,
|
29
|
+
ATTRIBUTE_DATATABLE_SORTABLE,
|
30
|
+
ATTRIBUTE_DATATABLE_MODE,
|
31
|
+
ATTRIBUTE_DATATABLE_INDEX,
|
32
|
+
ATTRIBUTE_DATATABLE_MODE_HIDDEN,
|
33
|
+
ATTRIBUTE_DATATABLE_MODE_VISIBLE,
|
34
|
+
ATTRIBUTE_DATATABLE_RESPONSIVE_BREAKPOINT,
|
35
|
+
ATTRIBUTE_DATATABLE_MODE_FIXED,
|
34
36
|
} from "./constants.mjs";
|
35
|
-
import {
|
37
|
+
import {instanceSymbol} from "../../constants.mjs";
|
36
38
|
import {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
Header,
|
40
|
+
createOrderStatement,
|
41
|
+
DIRECTION_ASC,
|
42
|
+
DIRECTION_DESC,
|
43
|
+
DIRECTION_NONE,
|
42
44
|
} from "./datatable/header.mjs";
|
43
|
-
import {
|
45
|
+
import {DatatableStyleSheet} from "./stylesheet/datatable.mjs";
|
44
46
|
import {
|
45
|
-
|
46
|
-
|
47
|
+
handleDataSourceChanges,
|
48
|
+
datasourceLinkedElementSymbol,
|
47
49
|
} from "./util.mjs";
|
48
50
|
import "./columnbar.mjs";
|
49
51
|
import "./filter-button.mjs";
|
50
|
-
import {
|
51
|
-
import {
|
52
|
-
import {
|
53
|
-
import {
|
52
|
+
import {getDocument, getWindow} from "../../dom/util.mjs";
|
53
|
+
import {addAttributeToken} from "../../dom/attributes.mjs";
|
54
|
+
import {ATTRIBUTE_ERRORMESSAGE} from "../../dom/constants.mjs";
|
55
|
+
import {getDocumentTranslations} from "../../i18n/translations.mjs";
|
54
56
|
import "../state/state.mjs";
|
55
57
|
import "../host/collapse.mjs";
|
56
|
-
import {
|
58
|
+
import {generateUniqueConfigKey} from "../host/util.mjs";
|
57
59
|
|
58
60
|
import "./datasource/dom.mjs";
|
59
61
|
import "./datasource/rest.mjs";
|
60
62
|
|
61
|
-
export {
|
63
|
+
export {DataTable};
|
62
64
|
|
63
65
|
/**
|
64
66
|
* @private
|
@@ -119,209 +121,332 @@ const columnBarElementSymbol = Symbol("columnBarElement");
|
|
119
121
|
* @summary A data table
|
120
122
|
*/
|
121
123
|
class DataTable extends CustomElement {
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
124
|
+
/**
|
125
|
+
* This method is called by the `instanceof` operator.
|
126
|
+
* @returns {symbol}
|
127
|
+
*/
|
128
|
+
static get [instanceSymbol]() {
|
129
|
+
return Symbol.for("@schukai/monster/components/datatable@@instance");
|
130
|
+
}
|
131
|
+
|
132
|
+
/**
|
133
|
+
* To set the options via the html tag the attribute `data-monster-options` must be used.
|
134
|
+
* @see {@link https://monsterjs.org/en/doc/#configurate-a-monster-control}
|
135
|
+
*
|
136
|
+
* The individual configuration values can be found in the table.
|
137
|
+
*
|
138
|
+
* @property {Object} templates Template definitions
|
139
|
+
* @property {string} templates.main Main template
|
140
|
+
* @property {Object} datasource Datasource configuration
|
141
|
+
* @property {string} datasource.selector Selector for the datasource
|
142
|
+
* @property {Object} mapping Mapping configuration
|
143
|
+
* @property {string} mapping.data Data mapping
|
144
|
+
* @property {Array} data Data
|
145
|
+
* @property {Array} headers Headers
|
146
|
+
* @property {Object} responsive Responsive configuration
|
147
|
+
* @property {number} responsive.breakpoint Breakpoint for responsive mode
|
148
|
+
* @property {Object} labels Labels
|
149
|
+
* @property {string} labels.theListContainsNoEntries Label for empty state
|
150
|
+
* @property {Object} features Features
|
151
|
+
* @property {boolean} features.settings Settings feature
|
152
|
+
* @property {boolean} features.footer Footer feature
|
153
|
+
* @property {boolean} features.autoInit Auto init feature (init datasource automatically)
|
154
|
+
* @property {Object} templateMapping Template mapping
|
155
|
+
* @property {string} templateMapping.row-key Row key
|
156
|
+
* @property {string} templateMapping.filter-id Filter id
|
157
|
+
**/
|
158
|
+
get defaults() {
|
159
|
+
return Object.assign(
|
160
|
+
{},
|
161
|
+
super.defaults,
|
162
|
+
{
|
163
|
+
templates: {
|
164
|
+
main: getTemplate(),
|
165
|
+
emptyState: getEmptyTemplate(),
|
166
|
+
},
|
167
|
+
|
168
|
+
datasource: {
|
169
|
+
selector: null,
|
170
|
+
},
|
171
|
+
|
172
|
+
mapping: {
|
173
|
+
data: "dataset",
|
174
|
+
},
|
175
|
+
|
176
|
+
data: [],
|
177
|
+
headers: [],
|
178
|
+
|
179
|
+
responsive: {
|
180
|
+
breakpoint: 800,
|
181
|
+
},
|
182
|
+
|
183
|
+
labels: {
|
184
|
+
theListContainsNoEntries: "The list contains no entries",
|
185
|
+
},
|
186
|
+
|
187
|
+
features: {
|
188
|
+
settings: true,
|
189
|
+
footer: true,
|
190
|
+
autoInit: true,
|
191
|
+
},
|
192
|
+
|
193
|
+
templateMapping: {
|
194
|
+
"row-key": null,
|
195
|
+
"filter-id": null,
|
196
|
+
},
|
197
|
+
},
|
198
|
+
initOptionsFromArguments.call(this),
|
199
|
+
);
|
200
|
+
}
|
201
|
+
|
202
|
+
/**
|
203
|
+
*
|
204
|
+
* @param {string} selector
|
205
|
+
* @returns {NodeListOf<*>}
|
206
|
+
*/
|
207
|
+
getGridElements(selector) {
|
208
|
+
return this[gridElementSymbol].querySelectorAll(selector);
|
209
|
+
}
|
210
|
+
|
211
|
+
/**
|
212
|
+
*
|
213
|
+
* @return {string}
|
214
|
+
*/
|
215
|
+
static getTag() {
|
216
|
+
return "monster-datatable";
|
217
|
+
}
|
218
|
+
|
219
|
+
/**
|
220
|
+
*
|
221
|
+
* @return {Monster.Components.Form.Form}
|
222
|
+
*/
|
223
|
+
[assembleMethodSymbol]() {
|
224
|
+
const rawKey = this.getOption("templateMapping.row-key");
|
225
|
+
|
226
|
+
if (rawKey === null) {
|
227
|
+
if (this.id !== null && this.id !== "") {
|
228
|
+
const rawKey = this.getOption("templateMapping.row-key");
|
229
|
+
if (rawKey === null) {
|
230
|
+
this.setOption("templateMapping.row-key", this.id + "-row");
|
231
|
+
}
|
232
|
+
} else {
|
233
|
+
this.setOption("templateMapping.row-key", "row");
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
if (this.id !== null && this.id !== "") {
|
238
|
+
this.setOption("templateMapping.filter-id", "" + this.id + "-filter");
|
239
|
+
} else {
|
240
|
+
this.setOption("templateMapping.filter-id", "filter");
|
241
|
+
}
|
242
|
+
|
243
|
+
super[assembleMethodSymbol]();
|
244
|
+
|
245
|
+
initControlReferences.call(this);
|
246
|
+
initEventHandler.call(this);
|
247
|
+
|
248
|
+
const selector = this.getOption("datasource.selector");
|
249
|
+
|
250
|
+
if (isString(selector)) {
|
251
|
+
const elements = document.querySelectorAll(selector);
|
252
|
+
if (elements.length !== 1) {
|
253
|
+
throw new Error("the selector must match exactly one element");
|
254
|
+
}
|
255
|
+
|
256
|
+
const element = elements[0];
|
257
|
+
|
258
|
+
if (!isInstance(element, Datasource)) {
|
259
|
+
throw new TypeError("the element must be a datasource");
|
260
|
+
}
|
261
|
+
|
262
|
+
this[datasourceLinkedElementSymbol] = element;
|
263
|
+
|
264
|
+
setTimeout(() => {
|
265
|
+
handleDataSourceChanges.call(this);
|
266
|
+
element.datasource.attachObserver(
|
267
|
+
new Observer(handleDataSourceChanges.bind(this)),
|
268
|
+
);
|
269
|
+
}, 0);
|
270
|
+
}
|
271
|
+
|
272
|
+
getHostConfig
|
273
|
+
.call(this, getColumnVisibilityConfigKey)
|
274
|
+
.then((config) => {
|
275
|
+
const headerOrderMap = new Map();
|
276
|
+
|
277
|
+
getHostConfig
|
278
|
+
.call(this, getStoredOrderConfigKey)
|
279
|
+
.then((orderConfig) => {
|
280
|
+
if (isArray(orderConfig) || orderConfig.length > 0) {
|
281
|
+
for (let i = 0; i < orderConfig.length; i++) {
|
282
|
+
const item = orderConfig[i];
|
283
|
+
const parts = item.split(" ");
|
284
|
+
const field = parts[0];
|
285
|
+
const direction = parts[1] || DIRECTION_ASC;
|
286
|
+
headerOrderMap.set(field, direction);
|
287
|
+
}
|
288
|
+
}
|
289
|
+
})
|
290
|
+
.then(() => {
|
291
|
+
try {
|
292
|
+
initGridAndStructs.call(this, config, headerOrderMap);
|
293
|
+
} catch (error) {
|
294
|
+
addAttributeToken(
|
295
|
+
this,
|
296
|
+
ATTRIBUTE_ERRORMESSAGE,
|
297
|
+
error?.message || error.toString(),
|
298
|
+
);
|
299
|
+
}
|
300
|
+
|
301
|
+
updateColumnBar.call(this);
|
302
|
+
})
|
303
|
+
.catch((error) => {
|
304
|
+
addAttributeToken(
|
305
|
+
this,
|
306
|
+
ATTRIBUTE_ERRORMESSAGE,
|
307
|
+
error?.message || error.toString(),
|
308
|
+
);
|
309
|
+
});
|
310
|
+
})
|
311
|
+
.catch((error) => {
|
312
|
+
addAttributeToken(
|
313
|
+
this,
|
314
|
+
ATTRIBUTE_ERRORMESSAGE,
|
315
|
+
error?.message || error.toString(),
|
316
|
+
);
|
317
|
+
});
|
318
|
+
}
|
319
|
+
|
320
|
+
/**
|
321
|
+
*
|
322
|
+
* @return {CSSStyleSheet[]}
|
323
|
+
*/
|
324
|
+
static getCSSStyleSheet() {
|
325
|
+
return [DatatableStyleSheet];
|
326
|
+
}
|
327
|
+
|
328
|
+
/**
|
329
|
+
* Copy a row from the datatable
|
330
|
+
* @param {number} fromIndex
|
331
|
+
* @param {number} toIndex
|
332
|
+
* @returns {Monster.Components.Datatable.DataTable}
|
333
|
+
*/
|
334
|
+
copyRow(fromIndex, toIndex) {
|
335
|
+
|
336
|
+
const datasource = this[datasourceLinkedElementSymbol];
|
337
|
+
if (!datasource) {
|
338
|
+
return this;
|
339
|
+
}
|
340
|
+
let d = datasource.data;
|
341
|
+
let c = clone(d);
|
342
|
+
|
343
|
+
let rows = c
|
344
|
+
const mapping = this.getOption("mapping.data");
|
345
|
+
|
346
|
+
if (mapping) {
|
347
|
+
rows=c?.[mapping];
|
348
|
+
}
|
349
|
+
|
350
|
+
if (rows === undefined || rows === null) {
|
351
|
+
rows = [];
|
352
|
+
}
|
353
|
+
|
354
|
+
if (toIndex===undefined) {
|
355
|
+
toIndex = rows.length;
|
356
|
+
}
|
357
|
+
|
358
|
+
fromIndex = parseInt(fromIndex);
|
359
|
+
toIndex = parseInt(toIndex);
|
360
|
+
|
361
|
+
if (toIndex < 0 || toIndex > rows.length) {
|
362
|
+
throw new RangeError("index out of bounds");
|
363
|
+
}
|
364
|
+
|
365
|
+
validateArray(rows);
|
366
|
+
validateInteger(fromIndex);
|
367
|
+
validateInteger(toIndex);
|
368
|
+
|
369
|
+
if (fromIndex < 0 || fromIndex >= rows.length) {
|
370
|
+
throw new RangeError("index out of bounds");
|
371
|
+
}
|
372
|
+
|
373
|
+
rows.splice(toIndex, 0, clone(rows[fromIndex]));
|
374
|
+
datasource.data=c;
|
375
|
+
return this;
|
376
|
+
}
|
377
|
+
|
378
|
+
/**
|
379
|
+
* Remove a row from the datatable
|
380
|
+
* @param index
|
381
|
+
* @returns {Monster.Components.Datatable.DataTable}
|
382
|
+
*/
|
383
|
+
removeRow(index) {
|
384
|
+
const datasource = this[datasourceLinkedElementSymbol];
|
385
|
+
if (!datasource) {
|
386
|
+
return this;
|
387
|
+
}
|
388
|
+
let d = datasource.data;
|
389
|
+
let c = clone(d);
|
390
|
+
|
391
|
+
let rows = c
|
392
|
+
const mapping = this.getOption("mapping.data");
|
393
|
+
|
394
|
+
if (mapping) {
|
395
|
+
rows=c?.[mapping];
|
396
|
+
}
|
397
|
+
|
398
|
+
if (rows === undefined || rows === null) {
|
399
|
+
rows = [];
|
400
|
+
}
|
401
|
+
|
402
|
+
index = parseInt(index);
|
403
|
+
|
404
|
+
validateArray(rows);
|
405
|
+
validateInteger(index);
|
406
|
+
if (index < 0 || index >= rows.length) {
|
407
|
+
throw new RangeError("index out of bounds");
|
408
|
+
}
|
409
|
+
if (mapping) {
|
410
|
+
rows=c?.[mapping];
|
411
|
+
}
|
412
|
+
|
413
|
+
rows.splice(index, 1)
|
414
|
+
datasource.data=c;
|
415
|
+
return this;
|
416
|
+
}
|
417
|
+
|
418
|
+
/**
|
419
|
+
* Add a row to the datatable
|
420
|
+
* @param {Object} data
|
421
|
+
* @returns {Monster.Components.Datatable.DataTable}
|
422
|
+
*/
|
423
|
+
addRow(data) {
|
424
|
+
const datasource = this[datasourceLinkedElementSymbol];
|
425
|
+
if (!datasource) {
|
426
|
+
return this;
|
427
|
+
}
|
428
|
+
let d = datasource.data;
|
429
|
+
let c = clone(d);
|
430
|
+
|
431
|
+
let rows = c
|
432
|
+
|
433
|
+
const mapping = this.getOption("mapping.data");
|
434
|
+
if (mapping) {
|
435
|
+
rows=c?.[mapping];
|
436
|
+
}
|
437
|
+
|
438
|
+
if (rows === undefined || rows === null) {
|
439
|
+
rows = [];
|
440
|
+
}
|
441
|
+
|
442
|
+
validateArray(rows);
|
443
|
+
validateObject(data);
|
444
|
+
|
445
|
+
rows.push(data)
|
446
|
+
datasource.data=c;
|
447
|
+
return this;
|
448
|
+
}
|
449
|
+
|
325
450
|
}
|
326
451
|
|
327
452
|
/**
|
@@ -329,7 +454,7 @@ class DataTable extends CustomElement {
|
|
329
454
|
* @returns {string}
|
330
455
|
*/
|
331
456
|
function getColumnVisibilityConfigKey() {
|
332
|
-
|
457
|
+
return generateUniqueConfigKey("datatable", this?.id, "columns-visibility");
|
333
458
|
}
|
334
459
|
|
335
460
|
/**
|
@@ -337,7 +462,7 @@ function getColumnVisibilityConfigKey() {
|
|
337
462
|
* @returns {string}
|
338
463
|
*/
|
339
464
|
function getFilterConfigKey() {
|
340
|
-
|
465
|
+
return generateUniqueConfigKey("datatable", this?.id, "filter");
|
341
466
|
}
|
342
467
|
|
343
468
|
/**
|
@@ -345,293 +470,293 @@ function getFilterConfigKey() {
|
|
345
470
|
* @returns {Promise}
|
346
471
|
*/
|
347
472
|
function getHostConfig(callback) {
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
473
|
+
const document = getDocument();
|
474
|
+
const host = document.querySelector("monster-host");
|
475
|
+
|
476
|
+
if (!(host && this.id)) {
|
477
|
+
return Promise.resolve({});
|
478
|
+
}
|
479
|
+
|
480
|
+
if (!host || !isFunction(host?.getConfig)) {
|
481
|
+
throw new TypeError("the host must be a monster-host");
|
482
|
+
}
|
483
|
+
|
484
|
+
const configKey = callback.call(this);
|
485
|
+
return host.hasConfig(configKey).then((hasConfig) => {
|
486
|
+
if (hasConfig) {
|
487
|
+
return host.getConfig(configKey);
|
488
|
+
} else {
|
489
|
+
return {};
|
490
|
+
}
|
491
|
+
});
|
367
492
|
}
|
368
493
|
|
369
494
|
/**
|
370
495
|
* @private
|
371
496
|
*/
|
372
497
|
function updateColumnBar() {
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
498
|
+
if (!this[columnBarElementSymbol]) {
|
499
|
+
return;
|
500
|
+
}
|
501
|
+
|
502
|
+
const columns = [];
|
503
|
+
for (const header of this.getOption("headers")) {
|
504
|
+
const mode = header.getInternal("mode");
|
505
|
+
|
506
|
+
if (mode === ATTRIBUTE_DATATABLE_MODE_FIXED) {
|
507
|
+
continue;
|
508
|
+
}
|
509
|
+
|
510
|
+
columns.push({
|
511
|
+
visible: mode !== ATTRIBUTE_DATATABLE_MODE_HIDDEN,
|
512
|
+
name: header.label,
|
513
|
+
index: header.index,
|
514
|
+
});
|
515
|
+
}
|
516
|
+
|
517
|
+
this[columnBarElementSymbol].setOption("columns", columns);
|
393
518
|
}
|
394
519
|
|
395
520
|
/**
|
396
521
|
* @private
|
397
522
|
*/
|
398
523
|
function updateHeaderFromColumnBar() {
|
399
|
-
|
400
|
-
|
401
|
-
|
524
|
+
if (!this[columnBarElementSymbol]) {
|
525
|
+
return;
|
526
|
+
}
|
402
527
|
|
403
|
-
|
404
|
-
|
528
|
+
const options = this[columnBarElementSymbol].getOption("columns");
|
529
|
+
if (!isArray(options)) return;
|
405
530
|
|
406
|
-
|
531
|
+
const invisibleMap = {};
|
407
532
|
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
533
|
+
for (let i = 0; i < options.length; i++) {
|
534
|
+
const option = options[i];
|
535
|
+
invisibleMap[option.index] = option.visible;
|
536
|
+
}
|
412
537
|
|
413
|
-
|
414
|
-
|
538
|
+
for (const header of this.getOption("headers")) {
|
539
|
+
const mode = header.getInternal("mode");
|
415
540
|
|
416
|
-
|
417
|
-
|
418
|
-
|
541
|
+
if (mode === ATTRIBUTE_DATATABLE_MODE_FIXED) {
|
542
|
+
continue;
|
543
|
+
}
|
419
544
|
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
545
|
+
if (invisibleMap[header.index] === false) {
|
546
|
+
header.setInternal("mode", ATTRIBUTE_DATATABLE_MODE_HIDDEN);
|
547
|
+
} else {
|
548
|
+
header.setInternal("mode", ATTRIBUTE_DATATABLE_MODE_VISIBLE);
|
549
|
+
}
|
550
|
+
}
|
426
551
|
}
|
427
552
|
|
428
553
|
/**
|
429
554
|
* @private
|
430
555
|
*/
|
431
556
|
function updateConfigColumnBar() {
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
557
|
+
if (!this[columnBarElementSymbol]) {
|
558
|
+
return;
|
559
|
+
}
|
560
|
+
|
561
|
+
const options = this[columnBarElementSymbol].getOption("columns");
|
562
|
+
if (!isArray(options)) return;
|
563
|
+
|
564
|
+
const map = {};
|
565
|
+
for (let i = 0; i < options.length; i++) {
|
566
|
+
const option = options[i];
|
567
|
+
map[option.name] = option.visible;
|
568
|
+
}
|
569
|
+
|
570
|
+
const document = getDocument();
|
571
|
+
const host = document.querySelector("monster-host");
|
572
|
+
if (!(host && this.id)) {
|
573
|
+
return;
|
574
|
+
}
|
575
|
+
const configKey = getColumnVisibilityConfigKey.call(this);
|
576
|
+
|
577
|
+
try {
|
578
|
+
host.setConfig(configKey, map);
|
579
|
+
} catch (error) {
|
580
|
+
addAttributeToken(this, ATTRIBUTE_ERRORMESSAGE, String(error));
|
581
|
+
}
|
457
582
|
}
|
458
583
|
|
459
584
|
/**
|
460
585
|
* @private
|
461
586
|
*/
|
462
587
|
function initEventHandler() {
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
588
|
+
const self = this;
|
589
|
+
|
590
|
+
getWindow().addEventListener("resize", (event) => {
|
591
|
+
updateGrid.call(self);
|
592
|
+
});
|
593
|
+
|
594
|
+
self[columnBarElementSymbol].attachObserver(
|
595
|
+
new Observer((e) => {
|
596
|
+
updateHeaderFromColumnBar.call(self);
|
597
|
+
updateGrid.call(self);
|
598
|
+
updateConfigColumnBar.call(self);
|
599
|
+
}),
|
600
|
+
);
|
601
|
+
|
602
|
+
self[gridHeadersElementSymbol].addEventListener("click", function (event) {
|
603
|
+
let element = null;
|
604
|
+
const datasource = self[datasourceLinkedElementSymbol];
|
605
|
+
if (!datasource) {
|
606
|
+
return;
|
607
|
+
}
|
608
|
+
|
609
|
+
element = findTargetElementFromEvent(event, ATTRIBUTE_DATATABLE_SORTABLE);
|
610
|
+
if (element) {
|
611
|
+
const index = element.parentNode.getAttribute(ATTRIBUTE_DATATABLE_INDEX);
|
612
|
+
const headers = self.getOption("headers");
|
613
|
+
|
614
|
+
event.preventDefault();
|
615
|
+
|
616
|
+
headers[index].changeDirection();
|
617
|
+
|
618
|
+
setTimeout(function () {
|
619
|
+
/** hotfix, normally this should be done via the updater, no idea why this is not possible. */
|
620
|
+
element.setAttribute(
|
621
|
+
ATTRIBUTE_DATATABLE_SORTABLE,
|
622
|
+
`${headers[index].field} ${headers[index].direction}`,
|
623
|
+
);
|
624
|
+
|
625
|
+
storeOrderStatement.call(self, true);
|
626
|
+
}, 0);
|
627
|
+
}
|
628
|
+
});
|
504
629
|
}
|
505
630
|
|
506
631
|
/**
|
507
632
|
* @private
|
508
633
|
*/
|
509
634
|
function initGridAndStructs(hostConfig, headerOrderMap) {
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
+
const rowID = this.getOption("templateMapping.row-key");
|
636
|
+
|
637
|
+
if (!this[gridElementSymbol]) {
|
638
|
+
throw new Error("no grid element is defined");
|
639
|
+
}
|
640
|
+
|
641
|
+
let template;
|
642
|
+
getSlottedElements.call(this).forEach((e) => {
|
643
|
+
if (e instanceof HTMLTemplateElement && e.id === rowID) {
|
644
|
+
template = e;
|
645
|
+
}
|
646
|
+
});
|
647
|
+
|
648
|
+
if (!template) {
|
649
|
+
throw new Error("no template is defined");
|
650
|
+
}
|
651
|
+
|
652
|
+
const rowCount = template.content.children.length;
|
653
|
+
|
654
|
+
const headers = [];
|
655
|
+
|
656
|
+
for (let i = 0; i < rowCount; i++) {
|
657
|
+
let hClass = "";
|
658
|
+
const row = template.content.children[i];
|
659
|
+
|
660
|
+
let mode = "";
|
661
|
+
if (row.hasAttribute(ATTRIBUTE_DATATABLE_MODE)) {
|
662
|
+
mode = row.getAttribute(ATTRIBUTE_DATATABLE_MODE);
|
663
|
+
}
|
664
|
+
|
665
|
+
let grid = row.getAttribute(ATTRIBUTE_DATATABLE_GRID_TEMPLATE);
|
666
|
+
if (!grid || grid === "" || grid === "auto") {
|
667
|
+
grid = "minmax(0, 1fr)";
|
668
|
+
}
|
669
|
+
|
670
|
+
let label = "";
|
671
|
+
let labelKey = "";
|
672
|
+
|
673
|
+
if (row.hasAttribute(ATTRIBUTE_DATATABLE_HEAD)) {
|
674
|
+
label = row.getAttribute(ATTRIBUTE_DATATABLE_HEAD);
|
675
|
+
labelKey = label;
|
676
|
+
|
677
|
+
try {
|
678
|
+
if (label.startsWith("i18n:")) {
|
679
|
+
label = label.substring(5, label.length);
|
680
|
+
label = getDocumentTranslations().getText(label, label);
|
681
|
+
}
|
682
|
+
} catch (e) {
|
683
|
+
label = "i18n error " + label;
|
684
|
+
}
|
685
|
+
}
|
686
|
+
|
687
|
+
if (!label) {
|
688
|
+
label = i + 1 + "";
|
689
|
+
mode = ATTRIBUTE_DATATABLE_MODE_FIXED;
|
690
|
+
labelKey = label;
|
691
|
+
}
|
692
|
+
|
693
|
+
if (isObject(hostConfig) && hostConfig.hasOwnProperty(label)) {
|
694
|
+
if (hostConfig[label] === false) {
|
695
|
+
mode = ATTRIBUTE_DATATABLE_MODE_HIDDEN;
|
696
|
+
} else {
|
697
|
+
mode = ATTRIBUTE_DATATABLE_MODE_VISIBLE;
|
698
|
+
}
|
699
|
+
}
|
700
|
+
|
701
|
+
let align = "";
|
702
|
+
if (row.hasAttribute(ATTRIBUTE_DATATABLE_ALIGN)) {
|
703
|
+
align = row.getAttribute(ATTRIBUTE_DATATABLE_ALIGN);
|
704
|
+
}
|
705
|
+
|
706
|
+
switch (align) {
|
707
|
+
case "center":
|
708
|
+
hClass = "flex-center";
|
709
|
+
break;
|
710
|
+
case "end":
|
711
|
+
hClass = "flex-end";
|
712
|
+
break;
|
713
|
+
case "start":
|
714
|
+
hClass = "flex-start";
|
715
|
+
break;
|
716
|
+
default:
|
717
|
+
hClass = "flex-start";
|
718
|
+
}
|
719
|
+
|
720
|
+
let field = "";
|
721
|
+
let direction = DIRECTION_NONE;
|
722
|
+
if (row.hasAttribute(ATTRIBUTE_DATATABLE_SORTABLE)) {
|
723
|
+
field = row.getAttribute(ATTRIBUTE_DATATABLE_SORTABLE).trim();
|
724
|
+
const parts = field.split(" ").map((item) => item.trim());
|
725
|
+
field = parts[0];
|
726
|
+
|
727
|
+
if (headerOrderMap.has(field)) {
|
728
|
+
direction = headerOrderMap.get(field);
|
729
|
+
} else if (
|
730
|
+
parts.length === 2 &&
|
731
|
+
[DIRECTION_ASC, DIRECTION_DESC].indexOf(parts[1]) !== -1
|
732
|
+
) {
|
733
|
+
direction = parts[1];
|
734
|
+
}
|
735
|
+
}
|
736
|
+
|
737
|
+
if (mode === ATTRIBUTE_DATATABLE_MODE_HIDDEN) {
|
738
|
+
hClass += " hidden";
|
739
|
+
}
|
740
|
+
|
741
|
+
const header = new Header();
|
742
|
+
header.setInternals({
|
743
|
+
field: field,
|
744
|
+
label: label,
|
745
|
+
classes: hClass,
|
746
|
+
index: i,
|
747
|
+
mode: mode,
|
748
|
+
grid: grid,
|
749
|
+
labelKey: labelKey,
|
750
|
+
direction: direction,
|
751
|
+
});
|
752
|
+
|
753
|
+
headers.push(header);
|
754
|
+
}
|
755
|
+
|
756
|
+
this.setOption("headers", headers);
|
757
|
+
setTimeout(() => {
|
758
|
+
storeOrderStatement.call(this, this.getOption("features.autoInit"));
|
759
|
+
}, 0);
|
635
760
|
}
|
636
761
|
|
637
762
|
/**
|
@@ -639,79 +764,78 @@ function initGridAndStructs(hostConfig, headerOrderMap) {
|
|
639
764
|
* @returns {string}
|
640
765
|
*/
|
641
766
|
export function getStoredOrderConfigKey() {
|
642
|
-
|
767
|
+
return generateUniqueConfigKey("datatable", this?.id, "stored-order");
|
643
768
|
}
|
644
769
|
|
645
770
|
/**
|
646
771
|
* @private
|
647
772
|
*/
|
648
773
|
function storeOrderStatement(doFetch) {
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
host.setConfig(configKey, list);
|
774
|
+
const headers = this.getOption("headers");
|
775
|
+
const statement = createOrderStatement(headers);
|
776
|
+
setDataSource.call(this, {orderBy: statement}, doFetch);
|
777
|
+
|
778
|
+
const document = getDocument();
|
779
|
+
const host = document.querySelector("monster-host");
|
780
|
+
if (!(host && this.id)) {
|
781
|
+
return;
|
782
|
+
}
|
783
|
+
|
784
|
+
const configKey = getStoredOrderConfigKey.call(this);
|
785
|
+
|
786
|
+
// statement explode with , and remove all empty
|
787
|
+
const list = statement.split(",").filter((item) => item.trim() !== "");
|
788
|
+
if (list.length === 0) {
|
789
|
+
return;
|
790
|
+
}
|
791
|
+
|
792
|
+
host.setConfig(configKey, list);
|
669
793
|
}
|
670
794
|
|
671
795
|
/**
|
672
796
|
* @private
|
673
797
|
*/
|
674
798
|
function updateGrid() {
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
799
|
+
if (!this[gridElementSymbol]) {
|
800
|
+
throw new Error("no grid element is defined");
|
801
|
+
}
|
802
|
+
|
803
|
+
let gridTemplateColumns = "";
|
804
|
+
|
805
|
+
const headers = this.getOption("headers");
|
806
|
+
|
807
|
+
let styles = "";
|
808
|
+
|
809
|
+
for (let i = 0; i < headers.length; i++) {
|
810
|
+
const header = headers[i];
|
811
|
+
|
812
|
+
if (header.mode === ATTRIBUTE_DATATABLE_MODE_HIDDEN) {
|
813
|
+
styles += `[data-monster-role=datatable]>[data-monster-head="${header.labelKey}"] { display: none; }\n`;
|
814
|
+
styles += `[data-monster-role=datatable-headers]>[data-monster-index="${header.index}"] { display: none; }\n`;
|
815
|
+
} else {
|
816
|
+
gridTemplateColumns += `${header.grid} `;
|
817
|
+
}
|
818
|
+
}
|
819
|
+
|
820
|
+
const sheet = new CSSStyleSheet();
|
821
|
+
if (styles !== "") sheet.replaceSync(styles);
|
822
|
+
this.shadowRoot.adoptedStyleSheets = [...DataTable.getCSSStyleSheet(), sheet];
|
823
|
+
|
824
|
+
const bodyWidth = getDocument().body.getBoundingClientRect().width;
|
825
|
+
|
826
|
+
const breakpoint = this.getOption("responsive.breakpoint");
|
827
|
+
|
828
|
+
if (bodyWidth > breakpoint) {
|
829
|
+
this[
|
830
|
+
gridElementSymbol
|
831
|
+
].style.gridTemplateColumns = `${gridTemplateColumns}`;
|
832
|
+
this[
|
833
|
+
gridHeadersElementSymbol
|
834
|
+
].style.gridTemplateColumns = `${gridTemplateColumns}`;
|
835
|
+
} else {
|
836
|
+
this[gridElementSymbol].style.gridTemplateColumns = "auto";
|
837
|
+
this[gridHeadersElementSymbol].style.gridTemplateColumns = "auto";
|
838
|
+
}
|
715
839
|
}
|
716
840
|
|
717
841
|
/**
|
@@ -719,20 +843,20 @@ function updateGrid() {
|
|
719
843
|
* @param {Monster.Components.Datatable.Header[]} headers
|
720
844
|
* @param {bool} doFetch
|
721
845
|
*/
|
722
|
-
function setDataSource({
|
723
|
-
|
846
|
+
function setDataSource({orderBy}, doFetch) {
|
847
|
+
const datasource = this[datasourceLinkedElementSymbol];
|
724
848
|
|
725
|
-
|
726
|
-
|
727
|
-
|
849
|
+
if (!datasource) {
|
850
|
+
return;
|
851
|
+
}
|
728
852
|
|
729
|
-
|
730
|
-
|
731
|
-
|
853
|
+
if (isFunction(datasource?.setParameters)) {
|
854
|
+
datasource.setParameters({orderBy});
|
855
|
+
}
|
732
856
|
|
733
|
-
|
734
|
-
|
735
|
-
|
857
|
+
if (doFetch !== false && isFunction(datasource?.fetch)) {
|
858
|
+
datasource.fetch();
|
859
|
+
}
|
736
860
|
}
|
737
861
|
|
738
862
|
/**
|
@@ -740,20 +864,20 @@ function setDataSource({ orderBy }, doFetch) {
|
|
740
864
|
* @return {Monster.Components.Datatable.Form}
|
741
865
|
*/
|
742
866
|
function initControlReferences() {
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
867
|
+
if (!this.shadowRoot) {
|
868
|
+
throw new Error("no shadow-root is defined");
|
869
|
+
}
|
870
|
+
|
871
|
+
this[gridElementSymbol] = this.shadowRoot.querySelector(
|
872
|
+
"[data-monster-role=datatable]",
|
873
|
+
);
|
874
|
+
this[gridHeadersElementSymbol] = this.shadowRoot.querySelector(
|
875
|
+
"[data-monster-role=datatable-headers]",
|
876
|
+
);
|
877
|
+
this[columnBarElementSymbol] =
|
878
|
+
this.shadowRoot.querySelector("monster-column-bar");
|
879
|
+
|
880
|
+
return this;
|
757
881
|
}
|
758
882
|
|
759
883
|
/**
|
@@ -763,22 +887,22 @@ function initControlReferences() {
|
|
763
887
|
* @throws {Error} the datasource could not be initialized
|
764
888
|
*/
|
765
889
|
function initOptionsFromArguments() {
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
890
|
+
const options = {};
|
891
|
+
const selector = this.getAttribute(ATTRIBUTE_DATASOURCE_SELECTOR);
|
892
|
+
|
893
|
+
if (selector) {
|
894
|
+
options.datasource = {selector: selector};
|
895
|
+
}
|
896
|
+
|
897
|
+
const breakpoint = this.getAttribute(
|
898
|
+
ATTRIBUTE_DATATABLE_RESPONSIVE_BREAKPOINT,
|
899
|
+
);
|
900
|
+
if (breakpoint) {
|
901
|
+
options.responsive = {};
|
902
|
+
options.responsive.breakpoint = parseInt(breakpoint);
|
903
|
+
}
|
904
|
+
|
905
|
+
return options;
|
782
906
|
}
|
783
907
|
|
784
908
|
/**
|
@@ -786,7 +910,7 @@ function initOptionsFromArguments() {
|
|
786
910
|
* @return {string}
|
787
911
|
*/
|
788
912
|
function getEmptyTemplate() {
|
789
|
-
|
913
|
+
return `<monster-state data-monster-role="empty-without-action">
|
790
914
|
<div part="visual">
|
791
915
|
<svg width="4rem" height="4rem" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
792
916
|
<path d="m21.5 22h-19c-1.378 0-2.5-1.121-2.5-2.5v-7c0-.07.015-.141.044-.205l3.969-8.82c.404-.896 1.299-1.475 2.28-1.475h11.414c.981 0 1.876.579 2.28 1.475l3.969 8.82c.029.064.044.135.044.205v7c0 1.379-1.122 2.5-2.5 2.5zm-20.5-9.393v6.893c0 .827.673 1.5 1.5 1.5h19c.827 0 1.5-.673 1.5-1.5v-6.893l-3.925-8.723c-.242-.536-.779-.884-1.368-.884h-11.414c-.589 0-1.126.348-1.368.885z"/>
|
@@ -804,8 +928,8 @@ function getEmptyTemplate() {
|
|
804
928
|
* @return {string}
|
805
929
|
*/
|
806
930
|
function getTemplate() {
|
807
|
-
|
808
|
-
|
931
|
+
// language=HTML
|
932
|
+
return `
|
809
933
|
<div data-monster-role="control" part="control">
|
810
934
|
<template id="headers-row">
|
811
935
|
<div data-monster-attributes="class path:headers-row.classname,
|