tablevu 0.3.0-beta.3 → 0.3.0-beta.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/README.md +25 -65
- package/dist/adapters/array.d.ts +3 -0
- package/dist/adapters/odata.d.ts +4 -0
- package/dist/index.d.ts +4 -5
- package/dist/table.d.ts +168 -46
- package/dist/tablevu.cjs +765 -0
- package/dist/tablevu.esm.js +759 -0
- package/dist/types/adapter.d.ts +1 -1
- package/dist/types/index.d.ts +12 -11
- package/dist/types/odata.d.ts +27 -0
- package/dist/types/tablevu-column.d.ts +2 -2
- package/dist/types/tablevu-emits.d.ts +2 -6
- package/dist/types/{tablevu-footer-settings.d.ts → tablevu-footer.d.ts} +5 -0
- package/dist/types/tablevu-page.d.ts +10 -0
- package/dist/types/tablevu-props.d.ts +10 -4
- package/dist/types/tablevu-settings.d.ts +2 -13
- package/dist/types/tablevu-spec.d.ts +6 -11
- package/package.json +10 -29
- package/dist/array.d.ts +0 -14
- package/dist/odata.d.ts +0 -40
- package/dist/tablevu-index.esm.js +0 -1102
- package/dist/tablevu-index.umd.cjs.js +0 -1112
- package/dist/tablevu-odata.esm.js +0 -507
- package/dist/tablevu-odata.umd.cjs.js +0 -518
- package/dist/tablevu-table.esm.js +0 -578
- package/dist/tablevu-table.umd.cjs.js +0 -586
- package/dist/tablevu-webapi.esm.js +0 -19
- package/dist/tablevu-webapi.umd.cjs.js +0 -29
- package/dist/types/tablevu-page-settings.d.ts +0 -4
- package/dist/webapi.d.ts +0 -15
|
@@ -1,586 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.tablevu = {}, global.Vue));
|
|
5
|
-
})(this, (function (exports, vue) { 'use strict';
|
|
6
|
-
|
|
7
|
-
function adaptArray(props, data) {
|
|
8
|
-
const d = Array.isArray(data) ? [...data] : [];
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
try {
|
|
11
|
-
// Filter & Search //
|
|
12
|
-
if (props.filter || props.search) {
|
|
13
|
-
const searchableCols = props.cols
|
|
14
|
-
?.map((m, i) => ({ index: i, searchable: m.searchable !== false }))
|
|
15
|
-
.filter(q => q.searchable)
|
|
16
|
-
.map(m => m.index) || [];
|
|
17
|
-
let filtered = d;
|
|
18
|
-
if (props.filter) {
|
|
19
|
-
filtered = filtered.filter(row => {
|
|
20
|
-
return Object.entries(props.filter).every(([key, value]) => {
|
|
21
|
-
return row[key] === value;
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
if (props.search && searchableCols.length > 0) {
|
|
26
|
-
const searchLower = props.search.toLowerCase();
|
|
27
|
-
filtered = filtered.filter(row => {
|
|
28
|
-
return searchableCols.some(colIndex => {
|
|
29
|
-
const col = props.cols?.[colIndex];
|
|
30
|
-
if (!col)
|
|
31
|
-
return false;
|
|
32
|
-
const val = row[col.name];
|
|
33
|
-
return val && String(val).toLowerCase().includes(searchLower);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
// Update d with filtered results
|
|
38
|
-
d.length = 0;
|
|
39
|
-
d.push(...filtered);
|
|
40
|
-
}
|
|
41
|
-
// Sort //
|
|
42
|
-
if (props.sort && props.sort.length > 0) {
|
|
43
|
-
for (let i = props.sort.length - 1; i >= 0; i--) {
|
|
44
|
-
const s = props.sort[i];
|
|
45
|
-
let field;
|
|
46
|
-
if (s.index !== undefined && s.index >= 0 && props.cols?.[s.index]) {
|
|
47
|
-
field = props.cols[s.index].name;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
field = s.name || '';
|
|
51
|
-
}
|
|
52
|
-
if (!field)
|
|
53
|
-
continue;
|
|
54
|
-
const dir = s.dir === 'desc' ? -1 : 1;
|
|
55
|
-
d.sort((a, b) => {
|
|
56
|
-
const av = a[field];
|
|
57
|
-
const bv = b[field];
|
|
58
|
-
if (av === bv)
|
|
59
|
-
return 0;
|
|
60
|
-
if (av === null || av === undefined)
|
|
61
|
-
return 1;
|
|
62
|
-
if (bv === null || bv === undefined)
|
|
63
|
-
return -1;
|
|
64
|
-
return (av > bv ? 1 : -1) * dir;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// Paging //
|
|
69
|
-
let result = d;
|
|
70
|
-
if (props.pageSize && props.pageSize > 0) {
|
|
71
|
-
const start = (props.currPage - 1) * props.pageSize;
|
|
72
|
-
const end = props.currPage * props.pageSize;
|
|
73
|
-
result = d.slice(start, end);
|
|
74
|
-
}
|
|
75
|
-
resolve({ rows: result, count: d.length });
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
reject(err);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const TablevuStatus = {
|
|
84
|
-
Error: -1,
|
|
85
|
-
Ready: 0,
|
|
86
|
-
Loading: 1
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const tablevu = {
|
|
90
|
-
props: {
|
|
91
|
-
settings: { type: Object, default: null },
|
|
92
|
-
data: { type: [Array, Function] },
|
|
93
|
-
group: { type: [String, Object] },
|
|
94
|
-
search: { type: String },
|
|
95
|
-
filter: { type: [Array, Object] },
|
|
96
|
-
rowid: { type: String },
|
|
97
|
-
onRowClick: { type: Function },
|
|
98
|
-
onRowDblClick: { type: Function },
|
|
99
|
-
class: { type: String, default: 'table' },
|
|
100
|
-
style: { type: String, default: null }
|
|
101
|
-
},
|
|
102
|
-
emits: ['onRowClick', 'onRowDblClick', 'selectionChange', 'columnVisibilityChange'],
|
|
103
|
-
setup(props, { attrs, slots, emit, expose }) {
|
|
104
|
-
let rows = [];
|
|
105
|
-
let rowg = [];
|
|
106
|
-
let grps = [];
|
|
107
|
-
let adapter = null;
|
|
108
|
-
let timer = null;
|
|
109
|
-
const spec = vue.reactive({
|
|
110
|
-
caption: null,
|
|
111
|
-
group: {
|
|
112
|
-
value: (props.settings && props.settings.group) ? props.settings.group.value : props.group ? props.group : undefined,
|
|
113
|
-
content: (props.settings && props.settings.group) ? props.settings.group.content : undefined,
|
|
114
|
-
expandAll: true,
|
|
115
|
-
class: 'table-light'
|
|
116
|
-
},
|
|
117
|
-
page: {
|
|
118
|
-
count: 0,
|
|
119
|
-
size: (props.settings && props.settings.page) ? (props.settings.page.size || 0) : 0,
|
|
120
|
-
current: 0,
|
|
121
|
-
type: undefined
|
|
122
|
-
},
|
|
123
|
-
sort: (props.settings && props.settings.sort) ? props.settings.sort : [],
|
|
124
|
-
columns: (props.settings && props.settings.columns) ? props.settings.columns : [],
|
|
125
|
-
footer: {
|
|
126
|
-
button: {
|
|
127
|
-
class: (props.settings && props.settings.footer && props.settings.footer.button && props.settings.footer.button.class) || 'btn'
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
status: TablevuStatus.Ready,
|
|
131
|
-
time: null,
|
|
132
|
-
search: null,
|
|
133
|
-
filter: null,
|
|
134
|
-
onData: (props.settings && props.settings.onData) ? props.settings.onData : undefined,
|
|
135
|
-
selectedRows: [],
|
|
136
|
-
columnWidths: {},
|
|
137
|
-
columnOrder: [],
|
|
138
|
-
columnVisibility: {}
|
|
139
|
-
});
|
|
140
|
-
if (props.data) {
|
|
141
|
-
if (Array.isArray(props.data)) {
|
|
142
|
-
adapter = adaptArray;
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
adapter = props.data;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (props.search)
|
|
149
|
-
spec.search = props.search;
|
|
150
|
-
vue.watch(() => props.search, (n, o) => {
|
|
151
|
-
const x = parseInt(String(props.settings?.searchMinChar)) || 3;
|
|
152
|
-
if (timer) {
|
|
153
|
-
clearTimeout(timer);
|
|
154
|
-
timer = null;
|
|
155
|
-
}
|
|
156
|
-
if (n && n.length > x) {
|
|
157
|
-
spec.search = n;
|
|
158
|
-
timer = setTimeout(() => { refresh(); timer = null; }, 444);
|
|
159
|
-
}
|
|
160
|
-
else if (o && o.length > x && (n == undefined || n == null || n.length <= x)) {
|
|
161
|
-
spec.search = null;
|
|
162
|
-
timer = setTimeout(() => { refresh(); timer = null; }, 444);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
if (props.filter)
|
|
166
|
-
spec.filter = props.filter;
|
|
167
|
-
vue.watch(() => props.filter, () => {
|
|
168
|
-
if (props.filter)
|
|
169
|
-
spec.filter = props.filter;
|
|
170
|
-
else
|
|
171
|
-
spec.filter = null;
|
|
172
|
-
refresh();
|
|
173
|
-
}, { deep: true });
|
|
174
|
-
function prepareGroup(g, r) {
|
|
175
|
-
grps = [];
|
|
176
|
-
rowg = [];
|
|
177
|
-
for (let i = 0; i < r.length; i++) {
|
|
178
|
-
let v = null;
|
|
179
|
-
let c = null;
|
|
180
|
-
const o = r[i];
|
|
181
|
-
if (g.value) {
|
|
182
|
-
if (typeof g.value == 'function')
|
|
183
|
-
v = g.value(o);
|
|
184
|
-
else
|
|
185
|
-
v = o[g.value];
|
|
186
|
-
}
|
|
187
|
-
else if (typeof g == 'function') {
|
|
188
|
-
v = g(o);
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
if (typeof g == 'bigint' || typeof g == 'number') {
|
|
192
|
-
const l = parseFloat(String(g));
|
|
193
|
-
if (l)
|
|
194
|
-
v = o[l];
|
|
195
|
-
}
|
|
196
|
-
else if (typeof g == 'string')
|
|
197
|
-
v = o[g];
|
|
198
|
-
}
|
|
199
|
-
if (g.content) {
|
|
200
|
-
if (typeof g.content == 'function')
|
|
201
|
-
c = g.content(o);
|
|
202
|
-
else
|
|
203
|
-
c = o[g.content];
|
|
204
|
-
}
|
|
205
|
-
let n = grps.findIndex(f => f.group == v);
|
|
206
|
-
if (n == -1) {
|
|
207
|
-
n = grps.push({ group: v, content: c, expand: spec.group.expandAll }) - 1;
|
|
208
|
-
}
|
|
209
|
-
rowg.push(n);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
function first() { loadPage(1); }
|
|
213
|
-
function prior() {
|
|
214
|
-
if (spec.page.current > 1) {
|
|
215
|
-
loadPage(spec.page.current - 1);
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
loadPage(spec.page.current);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
function next() { loadPage(spec.page.current + 1); }
|
|
222
|
-
function last() { loadPage(spec.page.count); }
|
|
223
|
-
// Navigate to specific page number
|
|
224
|
-
function page(currentPage) {
|
|
225
|
-
if (currentPage < 1)
|
|
226
|
-
currentPage = 1;
|
|
227
|
-
if (currentPage > spec.page.count && spec.page.count > 0)
|
|
228
|
-
currentPage = spec.page.count;
|
|
229
|
-
loadPage(currentPage);
|
|
230
|
-
}
|
|
231
|
-
function refresh() { loadPage(spec.page.current); }
|
|
232
|
-
function orderby(ind, dir) {
|
|
233
|
-
if (spec.sort && spec.sort.length > 0) {
|
|
234
|
-
let l = spec.sort.findIndex(f => f.index == ind);
|
|
235
|
-
if (l < 0) {
|
|
236
|
-
let n = spec.columns[ind]?.name;
|
|
237
|
-
l = spec.sort.findIndex(f => f.name == n);
|
|
238
|
-
}
|
|
239
|
-
if (l == 0) {
|
|
240
|
-
spec.sort[l].dir = dir ? dir : (spec.sort[0].dir ? null : 'desc');
|
|
241
|
-
}
|
|
242
|
-
else if (l > 0) {
|
|
243
|
-
spec.sort.splice(l, 1);
|
|
244
|
-
}
|
|
245
|
-
if (l != 0) {
|
|
246
|
-
spec.sort.unshift({ index: ind, dir: dir ? dir : null });
|
|
247
|
-
}
|
|
248
|
-
if (spec.sort.length > 2) {
|
|
249
|
-
spec.sort.pop();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
spec.sort.push({ index: ind, dir: dir ? dir : null });
|
|
254
|
-
}
|
|
255
|
-
loadPage(spec.page.current);
|
|
256
|
-
}
|
|
257
|
-
// Internal load function (alias for adapter call)
|
|
258
|
-
function loadPage(currentPage) {
|
|
259
|
-
let dat = null;
|
|
260
|
-
if (props.data) {
|
|
261
|
-
if (Array.isArray(props.data))
|
|
262
|
-
dat = props.data;
|
|
263
|
-
}
|
|
264
|
-
else
|
|
265
|
-
return;
|
|
266
|
-
spec.status = TablevuStatus.Loading;
|
|
267
|
-
if (adapter) {
|
|
268
|
-
const pageSize = spec.page.size || 20;
|
|
269
|
-
adapter({
|
|
270
|
-
pageSize,
|
|
271
|
-
currPage: currentPage,
|
|
272
|
-
sort: spec.sort,
|
|
273
|
-
cols: spec.columns,
|
|
274
|
-
filter: spec.filter,
|
|
275
|
-
search: spec.search
|
|
276
|
-
}, dat).then(ada => {
|
|
277
|
-
if (spec.onData)
|
|
278
|
-
rows = spec.onData(ada.rows);
|
|
279
|
-
else
|
|
280
|
-
rows = ada.rows;
|
|
281
|
-
const groupValue = spec.group.value;
|
|
282
|
-
if (groupValue && (typeof groupValue == 'string' || typeof groupValue == 'number' || typeof groupValue == 'bigint' || (typeof groupValue == 'object' && groupValue.value)))
|
|
283
|
-
prepareGroup(spec.group, rows);
|
|
284
|
-
spec.page.count = (ada.count > 0 && pageSize > 0) ? Math.ceil(ada.count / pageSize) : 0;
|
|
285
|
-
spec.page.current = currentPage;
|
|
286
|
-
spec.status = TablevuStatus.Ready;
|
|
287
|
-
spec.time = Date.now();
|
|
288
|
-
}).catch(err => {
|
|
289
|
-
console.error(err);
|
|
290
|
-
spec.status = TablevuStatus.Error;
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
function renderValue(col, val) {
|
|
295
|
-
if (val) {
|
|
296
|
-
let v;
|
|
297
|
-
if (col.type == 'datetime' || col.type == 'date' || col.type == 'time') {
|
|
298
|
-
const t = new Date(val);
|
|
299
|
-
if (col.type == 'date')
|
|
300
|
-
v = t.toLocaleDateString();
|
|
301
|
-
else if (col.type == 'time')
|
|
302
|
-
v = t.toLocaleTimeString();
|
|
303
|
-
else
|
|
304
|
-
v = t.toLocaleString();
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
if (col.type == 'numeric') {
|
|
308
|
-
v = parseFloat(val);
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
if (col.type == 'integer') {
|
|
312
|
-
v = parseInt(val);
|
|
313
|
-
}
|
|
314
|
-
else
|
|
315
|
-
v = val;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
return v;
|
|
319
|
-
}
|
|
320
|
-
else
|
|
321
|
-
return '';
|
|
322
|
-
}
|
|
323
|
-
function renderCell(col, val) {
|
|
324
|
-
const o = { style: {} };
|
|
325
|
-
if (col.colspan && col.colspan > 1)
|
|
326
|
-
o.colspan = col.colspan;
|
|
327
|
-
if (col.style)
|
|
328
|
-
o.style = { ...o.style, ...col.style };
|
|
329
|
-
if (col.align)
|
|
330
|
-
o.style['text-align'] = col.align;
|
|
331
|
-
if (col.width)
|
|
332
|
-
o.style['max-width'] = col.width;
|
|
333
|
-
const v = renderValue(col, val);
|
|
334
|
-
return vue.h('td', o, v);
|
|
335
|
-
}
|
|
336
|
-
function renderCustomCell(col, row) {
|
|
337
|
-
const o = { style: {} };
|
|
338
|
-
if (col.colspan && col.colspan > 1)
|
|
339
|
-
o.colspan = col.colspan;
|
|
340
|
-
if (col.style)
|
|
341
|
-
o.style = { ...o.style, ...col.style };
|
|
342
|
-
if (col.align)
|
|
343
|
-
o.style['text-align'] = col.align;
|
|
344
|
-
if (col.width)
|
|
345
|
-
o.style['max-width'] = col.width;
|
|
346
|
-
const f = col.render?.(row) ?? '';
|
|
347
|
-
return vue.h('td', { ...o, innerHTML: f });
|
|
348
|
-
}
|
|
349
|
-
function renderGroup(grp) {
|
|
350
|
-
const b = vue.h('button', {
|
|
351
|
-
title: String(grp.expand),
|
|
352
|
-
onClick: (event) => {
|
|
353
|
-
grp.expand = !grp.expand;
|
|
354
|
-
event.currentTarget.value = grp.expand ? '▼' : '►';
|
|
355
|
-
spec.time = Date.now();
|
|
356
|
-
event.preventDefault();
|
|
357
|
-
},
|
|
358
|
-
style: { padding: 0, margin: '0 6px 0 0', width: '12px', height: '100%', border: 'none', outline: '0', backgroundColor: 'transparent' }
|
|
359
|
-
}, grp.expand ? '▼' : '►');
|
|
360
|
-
const v = grp.content || grp.group;
|
|
361
|
-
return vue.h('tr', {}, vue.h('td', { colspan: spec.columns.length, class: spec.group.class }, [b, v]));
|
|
362
|
-
}
|
|
363
|
-
function renderRow(index, row) {
|
|
364
|
-
const o = { key: index, index: index };
|
|
365
|
-
if (props.rowid)
|
|
366
|
-
o.rowid = row[props.rowid];
|
|
367
|
-
const r = [];
|
|
368
|
-
for (let i = 0; i < spec.columns.length; i++) {
|
|
369
|
-
const c = spec.columns[i];
|
|
370
|
-
if (c.render) {
|
|
371
|
-
r.push(renderCustomCell(c, row));
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
let v;
|
|
375
|
-
if (c.depth) {
|
|
376
|
-
v = row;
|
|
377
|
-
for (let j = 0; j < c.depth.length; j++) {
|
|
378
|
-
if (v)
|
|
379
|
-
v = v[c.depth[j]];
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
383
|
-
v = row[c.name];
|
|
384
|
-
}
|
|
385
|
-
r.push(renderCell(c, v));
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
o.ondblclick = (event) => {
|
|
389
|
-
const target = event.currentTarget;
|
|
390
|
-
const idx = target.getAttribute('index');
|
|
391
|
-
if (idx !== null) {
|
|
392
|
-
const rowData = rows[parseInt(idx)];
|
|
393
|
-
emit('onRowDblClick', event, rowData);
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
if (props.onRowClick) {
|
|
397
|
-
o.onClick = (event) => {
|
|
398
|
-
const target = event.currentTarget;
|
|
399
|
-
const idx = target.getAttribute('index');
|
|
400
|
-
if (idx !== null) {
|
|
401
|
-
const rowData = rows[parseInt(idx)];
|
|
402
|
-
props.onRowClick(event, rowData);
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
// Selection
|
|
407
|
-
if (spec.selectedRows.some(s => s[props.rowid || 'id'] === row[props.rowid || 'id'])) {
|
|
408
|
-
o.class = (o.class || '') + ' selected';
|
|
409
|
-
}
|
|
410
|
-
return vue.h('tr', o, r);
|
|
411
|
-
}
|
|
412
|
-
function renderHeader() {
|
|
413
|
-
const ar = [];
|
|
414
|
-
for (let i = 0; i < spec.columns.length; i++) {
|
|
415
|
-
const cl = [];
|
|
416
|
-
if (spec.columns[i].label)
|
|
417
|
-
cl.push(vue.h('span', spec.columns[i].label));
|
|
418
|
-
else
|
|
419
|
-
cl.push(vue.h('span', spec.columns[i].name));
|
|
420
|
-
if (spec.sort && spec.sort.length > 0 && spec.sort[0].index == i) {
|
|
421
|
-
if (spec.sort[0].dir == 'desc')
|
|
422
|
-
cl.push(vue.h('span', { style: { float: 'right' } }, '▼'));
|
|
423
|
-
else
|
|
424
|
-
cl.push(vue.h('span', { style: { float: 'right' } }, '▲'));
|
|
425
|
-
}
|
|
426
|
-
const ch = { position: 'relative' };
|
|
427
|
-
if (spec.columns[i].width) {
|
|
428
|
-
ch.width = spec.columns[i].width;
|
|
429
|
-
ch.minWidth = spec.columns[i].width;
|
|
430
|
-
ch.maxWidth = spec.columns[i].width;
|
|
431
|
-
}
|
|
432
|
-
const cy = { display: 'block', 'font-weight': 500, textDecoration: 'none', textAlign: 'center' };
|
|
433
|
-
let a;
|
|
434
|
-
let f;
|
|
435
|
-
if (spec.columns[i].popup) {
|
|
436
|
-
const r = vue.ref(null);
|
|
437
|
-
const c = [
|
|
438
|
-
vue.h('a', { href: '#', onClick: (event) => { orderby(i); event.preventDefault(); }, style: { display: 'block', textDecoration: 'none', color: 'black', fontWeight: 'initial', padding: '.25rem' } }, 'Order by Ascending'),
|
|
439
|
-
vue.h('a', { href: '#', onClick: (event) => { orderby(i, 'desc'); event.preventDefault(); }, style: { display: 'block', textDecoration: 'none', color: 'black', fontWeight: 'initial', padding: '.25rem' } }, 'Order by Descending'),
|
|
440
|
-
];
|
|
441
|
-
a = vue.h('a', {
|
|
442
|
-
href: '#',
|
|
443
|
-
onClick: (event) => {
|
|
444
|
-
if (r.value && r.value.style && r.value.style.display && r.value.style.display == 'block')
|
|
445
|
-
r.value.style.display = 'none';
|
|
446
|
-
else if (r.value && r.value.style)
|
|
447
|
-
r.value.style.display = 'block';
|
|
448
|
-
event.preventDefault();
|
|
449
|
-
},
|
|
450
|
-
style: cy
|
|
451
|
-
}, cl);
|
|
452
|
-
f = vue.h('div', {
|
|
453
|
-
ref: r,
|
|
454
|
-
style: { position: 'absolute', display: 'none', width: spec.columns[i].width || '12rem', height: 'fit-content', border: '1px solid lightgray', backgroundColor: 'whitesmoke', zIndex: 1, left: 0, top: '2rem', bottom: 0, right: 0, padding: '.25rem' }
|
|
455
|
-
}, c);
|
|
456
|
-
}
|
|
457
|
-
else
|
|
458
|
-
a = vue.h('a', { href: '#', onClick: (event) => { orderby(i); event.preventDefault(); }, style: cy }, cl);
|
|
459
|
-
if (spec.columns[i].filter) ;
|
|
460
|
-
ar.push(vue.h('th', {
|
|
461
|
-
colspan: null,
|
|
462
|
-
style: ch
|
|
463
|
-
}, [a, f]));
|
|
464
|
-
}
|
|
465
|
-
const tr = vue.h('tr', {}, ar);
|
|
466
|
-
return [tr];
|
|
467
|
-
}
|
|
468
|
-
function renderBody() {
|
|
469
|
-
const dr = [];
|
|
470
|
-
if (rows && rows.length > 0) {
|
|
471
|
-
if (grps && grps.length > 0) {
|
|
472
|
-
const r = [];
|
|
473
|
-
for (let g = 0; g < grps.length; g++)
|
|
474
|
-
r.push({ index: g, childs: [] });
|
|
475
|
-
for (let i = 0; i < rows.length; i++) {
|
|
476
|
-
const x = rowg[i];
|
|
477
|
-
r[x].childs.push(renderRow(i, rows[i]));
|
|
478
|
-
}
|
|
479
|
-
for (let g = 0; g < grps.length; g++) {
|
|
480
|
-
dr.push(renderGroup(grps[g]));
|
|
481
|
-
if (grps[g].expand)
|
|
482
|
-
dr.push(r[g].childs);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
else {
|
|
486
|
-
for (let i = 0; i < rows.length; i++) {
|
|
487
|
-
dr.push(renderRow(i, rows[i]));
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
else if (spec.settings?.emptyMessage) {
|
|
492
|
-
dr.push(vue.h('tr', {}, vue.h('td', { colspan: spec.columns.length, style: { textAlign: 'center', padding: '2rem', color: '#666' } }, spec.settings.emptyMessage)));
|
|
493
|
-
}
|
|
494
|
-
return dr;
|
|
495
|
-
}
|
|
496
|
-
// Prompt user for page number and navigate
|
|
497
|
-
function goToPage() {
|
|
498
|
-
const input = prompt('Page number:', String(spec.page.current));
|
|
499
|
-
if (input) {
|
|
500
|
-
const pageNum = parseInt(input, 10);
|
|
501
|
-
if (!isNaN(pageNum) && pageNum > 0 && pageNum !== spec.page.current) {
|
|
502
|
-
page(pageNum);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
function makeHandler(fn) {
|
|
507
|
-
return (e) => {
|
|
508
|
-
e.preventDefault();
|
|
509
|
-
e.stopPropagation();
|
|
510
|
-
fn();
|
|
511
|
-
};
|
|
512
|
-
}
|
|
513
|
-
function renderFooter() {
|
|
514
|
-
const fr = vue.h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: makeHandler(first), disabled: spec.page.current == 1 }, '◀◀');
|
|
515
|
-
const ls = vue.h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: makeHandler(last), disabled: spec.page.count == 0 || spec.page.current == spec.page.count }, '▶▶');
|
|
516
|
-
const pg = vue.h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: makeHandler(goToPage) }, spec.page.current + (spec.page.count > 0 ? (' / ' + spec.page.count) : ''));
|
|
517
|
-
const pr = vue.h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: makeHandler(prior), disabled: spec.page.current == 1 }, '◀');
|
|
518
|
-
const nx = vue.h('button', { class: spec.footer.button.class, style: 'font: initial; margin-right: .5rem', onClick: makeHandler(next), disabled: spec.page.count > 0 && spec.page.current == spec.page.count }, '▶');
|
|
519
|
-
const td = vue.h('td', { colspan: spec.columns.length, align: 'center' }, [fr, pr, pg, nx, ls]);
|
|
520
|
-
const tr = vue.h('tr', {}, [td]);
|
|
521
|
-
return [tr];
|
|
522
|
-
}
|
|
523
|
-
function renderCaption() {
|
|
524
|
-
return null;
|
|
525
|
-
}
|
|
526
|
-
// Initialize column metadata
|
|
527
|
-
if (spec.columns.length == 0) {
|
|
528
|
-
console.error('Columns not defined !');
|
|
529
|
-
}
|
|
530
|
-
for (let i = 0; i < spec.columns.length; i++) {
|
|
531
|
-
if (spec.columns[i].name && spec.columns[i].name.indexOf('.') > -1) {
|
|
532
|
-
spec.columns[i].depth = spec.columns[i].name.split('.');
|
|
533
|
-
}
|
|
534
|
-
// Initialize visibility
|
|
535
|
-
if (spec.columns[i].visible === undefined) {
|
|
536
|
-
spec.columns[i].visible = true;
|
|
537
|
-
spec.columnVisibility[spec.columns[i].name] = true;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
loadPage(1);
|
|
541
|
-
// Expose methods for external access via ref
|
|
542
|
-
expose({
|
|
543
|
-
first,
|
|
544
|
-
prior,
|
|
545
|
-
next,
|
|
546
|
-
last,
|
|
547
|
-
page,
|
|
548
|
-
refresh,
|
|
549
|
-
orderby,
|
|
550
|
-
getSelectedRows: () => spec.selectedRows,
|
|
551
|
-
setSelectedRows: (rows) => { spec.selectedRows = rows; }
|
|
552
|
-
});
|
|
553
|
-
vue.onMounted(() => {
|
|
554
|
-
// mounted hook
|
|
555
|
-
});
|
|
556
|
-
return {
|
|
557
|
-
spec, renderHeader, renderBody, renderFooter, renderCaption,
|
|
558
|
-
first, prior, next, last, page, refresh, orderby,
|
|
559
|
-
getSelectedRows: () => spec.selectedRows,
|
|
560
|
-
setSelectedRows: (rows) => { spec.selectedRows = rows; }
|
|
561
|
-
};
|
|
562
|
-
},
|
|
563
|
-
render(props) {
|
|
564
|
-
let prps = { class: 'tablevu' };
|
|
565
|
-
if (props.class)
|
|
566
|
-
prps.class = 'tablevu ' + props.class;
|
|
567
|
-
if (props.style)
|
|
568
|
-
prps.style = props.style;
|
|
569
|
-
const cntn = [];
|
|
570
|
-
cntn.push(vue.h('thead', {}, this.renderHeader()));
|
|
571
|
-
if (this.spec.status == TablevuStatus.Ready)
|
|
572
|
-
cntn.push(vue.h('tbody', { 'data-time': this.spec.time }, this.renderBody()));
|
|
573
|
-
if (this.spec.caption)
|
|
574
|
-
cntn.push(vue.h('caption', {}, this.renderCaption()));
|
|
575
|
-
if (this.spec.status == TablevuStatus.Ready)
|
|
576
|
-
if (this.spec.page.size > 0)
|
|
577
|
-
cntn.push(vue.h('tfoot', {}, this.renderFooter()));
|
|
578
|
-
return vue.h('table', prps, cntn);
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
exports.default = tablevu;
|
|
583
|
-
|
|
584
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
585
|
-
|
|
586
|
-
}));
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const param = (uri, header, props) => {
|
|
2
|
-
const url = new URL(uri);
|
|
3
|
-
// Paging //
|
|
4
|
-
if (props.pageSize && props.currentPage) {
|
|
5
|
-
url.searchParams.append('skip', String(props.pageSize * (props.currentPage - 1)));
|
|
6
|
-
url.searchParams.append('top', String(props.pageSize));
|
|
7
|
-
}
|
|
8
|
-
// Filter //
|
|
9
|
-
if (props.search)
|
|
10
|
-
url.searchParams.append('search', props.search);
|
|
11
|
-
// Order //
|
|
12
|
-
if (props.order && props.order.length > 0 && props.cols) {
|
|
13
|
-
url.searchParams.append('orderby', props.order.map(m => props.cols?.[m.index]?.name || '').join(','));
|
|
14
|
-
url.searchParams.append('orderdir', props.order.map(m => m.type ? m.type : 'asc').join(','));
|
|
15
|
-
}
|
|
16
|
-
return new Request(url, header);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { param as default };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.tablevu = {}));
|
|
5
|
-
})(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
const param = (uri, header, props) => {
|
|
8
|
-
const url = new URL(uri);
|
|
9
|
-
// Paging //
|
|
10
|
-
if (props.pageSize && props.currentPage) {
|
|
11
|
-
url.searchParams.append('skip', String(props.pageSize * (props.currentPage - 1)));
|
|
12
|
-
url.searchParams.append('top', String(props.pageSize));
|
|
13
|
-
}
|
|
14
|
-
// Filter //
|
|
15
|
-
if (props.search)
|
|
16
|
-
url.searchParams.append('search', props.search);
|
|
17
|
-
// Order //
|
|
18
|
-
if (props.order && props.order.length > 0 && props.cols) {
|
|
19
|
-
url.searchParams.append('orderby', props.order.map(m => props.cols?.[m.index]?.name || '').join(','));
|
|
20
|
-
url.searchParams.append('orderdir', props.order.map(m => m.type ? m.type : 'asc').join(','));
|
|
21
|
-
}
|
|
22
|
-
return new Request(url, header);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
exports.default = param;
|
|
26
|
-
|
|
27
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
28
|
-
|
|
29
|
-
}));
|
package/dist/webapi.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
interface WebApiProps {
|
|
2
|
-
pageSize?: number;
|
|
3
|
-
currentPage?: number;
|
|
4
|
-
search?: string;
|
|
5
|
-
order?: {
|
|
6
|
-
index: number;
|
|
7
|
-
type?: string;
|
|
8
|
-
}[];
|
|
9
|
-
cols?: {
|
|
10
|
-
name: string;
|
|
11
|
-
type?: string;
|
|
12
|
-
}[];
|
|
13
|
-
}
|
|
14
|
-
declare const param: (uri: string, header: any, props: WebApiProps) => Request;
|
|
15
|
-
export default param;
|