@bexis2/bexis2-core-ui 0.4.23 → 0.4.24
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 +9 -0
- package/dist/components/Facets/Facets.svelte +13 -9
- package/dist/components/Table/TableContent.svelte +74 -141
- package/dist/components/Table/TableContent.svelte.d.ts +0 -1
- package/dist/components/Table/TablePagination.svelte +15 -7
- package/dist/components/Table/TablePagination.svelte.d.ts +2 -0
- package/dist/components/Table/TablePaginationServer.svelte +11 -9
- package/dist/components/Table/TablePaginationServer.svelte.d.ts +1 -0
- package/dist/components/Table/utils.d.ts +34 -0
- package/dist/components/Table/{shared.js → utils.js} +109 -0
- package/dist/models/Models.d.ts +2 -0
- package/package.json +1 -1
- package/src/lib/components/Facets/Facets.svelte +13 -9
- package/src/lib/components/Table/TableContent.svelte +81 -167
- package/src/lib/components/Table/TablePagination.svelte +17 -7
- package/src/lib/components/Table/TablePaginationServer.svelte +16 -9
- package/src/lib/components/Table/{shared.ts → utils.ts} +157 -1
- package/src/lib/models/Models.ts +2 -0
- package/dist/components/Table/shared.d.ts +0 -15
package/README.md
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
# bexis-core-ui
|
|
2
|
+
## 0.4.24
|
|
3
|
+
- Table
|
|
4
|
+
- Adds option for enabling/disabling show/hide column menu in table.
|
|
5
|
+
- Adds option to show number of items displayed instead of number of pages.
|
|
6
|
+
- Fixes an issue where "0" values return empty string.
|
|
7
|
+
|
|
8
|
+
- Facets
|
|
9
|
+
- Fixes an issue with truncation of text in Facet headers and options.
|
|
10
|
+
|
|
2
11
|
## 0.4.23
|
|
3
12
|
- Table
|
|
4
13
|
- fix resizing issues after page size or page index changes
|
|
@@ -147,10 +147,14 @@ $: selectedGroups, mapSelected("groups");
|
|
|
147
147
|
hyphenOpacity="opacity-0"
|
|
148
148
|
bind:checked={selectedGroups[group.name]}
|
|
149
149
|
bind:group={selectedGroups}
|
|
150
|
+
regionSymbol="shrink-0"
|
|
150
151
|
>
|
|
151
|
-
<
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
<div class="grid grid-flow-col gap-2">
|
|
153
|
+
<p class="font-semibold whitespace-nowrap truncate" title={group.displayName}>
|
|
154
|
+
{group.displayName}
|
|
155
|
+
</p>
|
|
156
|
+
<span>{group.count !== undefined ? ` (${group.count})` : ''}</span>
|
|
157
|
+
</div>
|
|
154
158
|
|
|
155
159
|
<svelte:fragment slot="children">
|
|
156
160
|
<!-- If more than 5 choices, show the remaining in the Modal -->
|
|
@@ -166,9 +170,9 @@ $: selectedGroups, mapSelected("groups");
|
|
|
166
170
|
selection
|
|
167
171
|
multiple
|
|
168
172
|
>
|
|
169
|
-
<div class="
|
|
170
|
-
<p class="
|
|
171
|
-
<span title={item.displayName}>{item.displayName}</span>
|
|
173
|
+
<div class="grid grid-flow-col gap-2">
|
|
174
|
+
<p class="truncate">
|
|
175
|
+
<span class="" title={item.displayName}>{item.displayName}</span>
|
|
172
176
|
</p>
|
|
173
177
|
<span>({item.count})</span>
|
|
174
178
|
</div>
|
|
@@ -193,9 +197,9 @@ $: selectedGroups, mapSelected("groups");
|
|
|
193
197
|
selection
|
|
194
198
|
multiple
|
|
195
199
|
>
|
|
196
|
-
<div class="
|
|
197
|
-
<p class="
|
|
198
|
-
<span title={item.displayName}>{item.displayName}</span>
|
|
200
|
+
<div class="grid grid-flow-col gap-2">
|
|
201
|
+
<p class="truncate">
|
|
202
|
+
<span class="" title={item.displayName}>{item.displayName}</span>
|
|
199
203
|
</p>
|
|
200
204
|
<span>({item.count})</span>
|
|
201
205
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<script>import { afterUpdate,
|
|
1
|
+
<script>import { afterUpdate, createEventDispatcher, onDestroy } from "svelte";
|
|
2
2
|
import { readable, writable } from "svelte/store";
|
|
3
3
|
import Fa from "svelte-fa";
|
|
4
4
|
import { faCompress, faDownload, faXmark } from "@fortawesome/free-solid-svg-icons";
|
|
@@ -21,18 +21,9 @@ import TableFilterServer from "./TableFilterServer.svelte";
|
|
|
21
21
|
import TablePagination from "./TablePagination.svelte";
|
|
22
22
|
import TablePaginationServer from "./TablePaginationServer.svelte";
|
|
23
23
|
import ColumnsMenu from "./ColumnsMenu.svelte";
|
|
24
|
+
import * as utils from "./utils";
|
|
24
25
|
import { columnFilter, searchFilter } from "./filter";
|
|
25
|
-
import {
|
|
26
|
-
cellStyle,
|
|
27
|
-
exportAsCsv,
|
|
28
|
-
jsonToCsv,
|
|
29
|
-
fixedWidth,
|
|
30
|
-
normalizeFilters,
|
|
31
|
-
resetResize,
|
|
32
|
-
convertServerColumns,
|
|
33
|
-
minWidth
|
|
34
|
-
} from "./shared";
|
|
35
|
-
import { Receive, Send } from "../../models/Models";
|
|
26
|
+
import { Send } from "../../models/Models";
|
|
36
27
|
export let config;
|
|
37
28
|
let {
|
|
38
29
|
id: tableId,
|
|
@@ -41,6 +32,8 @@ let {
|
|
|
41
32
|
// Data store
|
|
42
33
|
columns,
|
|
43
34
|
// Column configuration
|
|
35
|
+
showColumnsMenu = false,
|
|
36
|
+
// Whether to display the columns menu
|
|
44
37
|
resizable = "none",
|
|
45
38
|
// Resizability config
|
|
46
39
|
height = null,
|
|
@@ -57,6 +50,8 @@ let {
|
|
|
57
50
|
// Whether to display the search input
|
|
58
51
|
pageSizes = [5, 10, 20, 50, 100],
|
|
59
52
|
// Page sizes to display in the pagination component
|
|
53
|
+
pageIndexStringType = "pages",
|
|
54
|
+
// pages by default
|
|
60
55
|
fitToScreen = true,
|
|
61
56
|
// Whether to fit the table to the screen,
|
|
62
57
|
exportable = false,
|
|
@@ -67,7 +62,7 @@ let searchValue = "";
|
|
|
67
62
|
let isFetching = false;
|
|
68
63
|
let tableRef;
|
|
69
64
|
const serverSide = server !== void 0;
|
|
70
|
-
const {
|
|
65
|
+
const { sendModel = new Send() } = server ?? {};
|
|
71
66
|
const filters = writable({});
|
|
72
67
|
const dispatch = createEventDispatcher();
|
|
73
68
|
const actionDispatcher = (obj) => dispatch("action", obj);
|
|
@@ -170,7 +165,7 @@ const tableColumns = [
|
|
|
170
165
|
id,
|
|
171
166
|
tableId,
|
|
172
167
|
values,
|
|
173
|
-
updateTable,
|
|
168
|
+
updateTable: updateTableWithParams,
|
|
174
169
|
pageIndex,
|
|
175
170
|
toFilterableValueFn,
|
|
176
171
|
filters,
|
|
@@ -200,7 +195,7 @@ const tableColumns = [
|
|
|
200
195
|
header: key,
|
|
201
196
|
accessor,
|
|
202
197
|
cell: ({ value }) => {
|
|
203
|
-
return value
|
|
198
|
+
return value ?? "";
|
|
204
199
|
},
|
|
205
200
|
plugins: {
|
|
206
201
|
// Sorting enabled by default
|
|
@@ -213,7 +208,7 @@ const tableColumns = [
|
|
|
213
208
|
id,
|
|
214
209
|
tableId,
|
|
215
210
|
values,
|
|
216
|
-
updateTable,
|
|
211
|
+
updateTable: updateTableWithParams,
|
|
217
212
|
pageIndex,
|
|
218
213
|
filters
|
|
219
214
|
}) : createRender(TableFilter, {
|
|
@@ -251,57 +246,11 @@ if (optionsComponent !== void 0) {
|
|
|
251
246
|
);
|
|
252
247
|
}
|
|
253
248
|
const createdTableColumns = table.createColumns(tableColumns);
|
|
254
|
-
const { headerRows, pageRows, tableAttrs, tableBodyAttrs, pluginStates } = table.createViewModel(createdTableColumns);
|
|
249
|
+
const { headerRows, pageRows, tableAttrs, tableBodyAttrs, pluginStates, rows } = table.createViewModel(createdTableColumns);
|
|
255
250
|
const { filterValue } = pluginStates.tableFilter;
|
|
256
251
|
const { exportedData } = pluginStates.export;
|
|
257
252
|
const { pageIndex, pageSize } = pluginStates.page;
|
|
258
253
|
const { hiddenColumnIds } = pluginStates.hideColumns;
|
|
259
|
-
const updateTable = async () => {
|
|
260
|
-
if (!sendModel) throw new Error("Server-side configuration is missing");
|
|
261
|
-
sendModel.limit = $pageSize;
|
|
262
|
-
sendModel.offset = $pageSize * $pageIndex;
|
|
263
|
-
sendModel.version = versionId || -1;
|
|
264
|
-
sendModel.id = entityId || -1;
|
|
265
|
-
sendModel.filter = normalizeFilters($filters);
|
|
266
|
-
let fetchData;
|
|
267
|
-
try {
|
|
268
|
-
isFetching = true;
|
|
269
|
-
fetchData = await fetch(baseUrl || "", {
|
|
270
|
-
headers: {
|
|
271
|
-
"Content-Type": "application/json"
|
|
272
|
-
},
|
|
273
|
-
method: "POST",
|
|
274
|
-
body: JSON.stringify(sendModel)
|
|
275
|
-
});
|
|
276
|
-
} catch (error) {
|
|
277
|
-
throw new Error(`Network error: ${error.message}`);
|
|
278
|
-
} finally {
|
|
279
|
-
isFetching = false;
|
|
280
|
-
}
|
|
281
|
-
if (!fetchData.ok) {
|
|
282
|
-
throw new Error("Failed to fetch data");
|
|
283
|
-
}
|
|
284
|
-
const response = await fetchData.json();
|
|
285
|
-
if (response.columns !== void 0) {
|
|
286
|
-
columns = convertServerColumns(response.columns, columns);
|
|
287
|
-
const clientCols = response.columns.reduce((acc, col) => {
|
|
288
|
-
acc[col.key] = col.column;
|
|
289
|
-
return acc;
|
|
290
|
-
}, {});
|
|
291
|
-
const tmpArr = [];
|
|
292
|
-
response.data.forEach((row, index) => {
|
|
293
|
-
const tmp = {};
|
|
294
|
-
Object.keys(row).forEach((key) => {
|
|
295
|
-
tmp[clientCols[key]] = row[key];
|
|
296
|
-
});
|
|
297
|
-
tmpArr.push(tmp);
|
|
298
|
-
});
|
|
299
|
-
dispatch("fetch", columns);
|
|
300
|
-
$data = tmpArr;
|
|
301
|
-
}
|
|
302
|
-
$serverItems = response.count;
|
|
303
|
-
return response;
|
|
304
|
-
};
|
|
305
254
|
const sortServer = (order, id) => {
|
|
306
255
|
if (!sendModel) throw new Error("Server-side configuration is missing");
|
|
307
256
|
if (order === void 0) {
|
|
@@ -310,64 +259,54 @@ const sortServer = (order, id) => {
|
|
|
310
259
|
sendModel.order = [{ column: id, direction: order }];
|
|
311
260
|
}
|
|
312
261
|
$pageIndex = 0;
|
|
313
|
-
|
|
262
|
+
updateTableWithParams();
|
|
314
263
|
};
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
});
|
|
330
|
-
rowHeights.update((rh) => {
|
|
331
|
-
const id = +row.id.split(`${tableId}-row-`)[1];
|
|
332
|
-
return {
|
|
333
|
-
...rh,
|
|
334
|
-
[id]: {
|
|
335
|
-
max: maxHeight - 24,
|
|
336
|
-
min: Math.max(minHeight - 24, rowHeight ?? 20)
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
});
|
|
340
|
-
});
|
|
264
|
+
const updateTableWithParams = async () => {
|
|
265
|
+
isFetching = true;
|
|
266
|
+
const result = await utils.updateTable(
|
|
267
|
+
$pageSize,
|
|
268
|
+
$pageIndex,
|
|
269
|
+
server,
|
|
270
|
+
$filters,
|
|
271
|
+
data,
|
|
272
|
+
serverItems,
|
|
273
|
+
columns,
|
|
274
|
+
dispatch
|
|
275
|
+
);
|
|
276
|
+
isFetching = false;
|
|
277
|
+
return result;
|
|
341
278
|
};
|
|
342
|
-
const
|
|
343
|
-
if (!tableRef
|
|
344
|
-
if (
|
|
345
|
-
|
|
279
|
+
const getDimensions = () => {
|
|
280
|
+
if (!tableRef) return;
|
|
281
|
+
if (resizable === "none") return;
|
|
282
|
+
else if (resizable === "columns") {
|
|
283
|
+
observeHeaderColumns();
|
|
284
|
+
} else if (resizable === "rows") {
|
|
285
|
+
observeFirstCells();
|
|
286
|
+
} else {
|
|
287
|
+
observeHeaderColumns();
|
|
288
|
+
observeFirstCells();
|
|
346
289
|
}
|
|
347
|
-
colWidths.update((cw) => {
|
|
348
|
-
tableRef?.querySelectorAll("thead tr th span").forEach((cell, index) => {
|
|
349
|
-
cw[index] = cw[index] === 100 ? cell.getBoundingClientRect().width + 12 + 32 : cw[index];
|
|
350
|
-
});
|
|
351
|
-
return cw;
|
|
352
|
-
});
|
|
353
290
|
};
|
|
354
291
|
const resizeRowsObserver = new ResizeObserver(() => {
|
|
355
|
-
getMaxCellHeightInRow(
|
|
292
|
+
utils.getMaxCellHeightInRow(
|
|
293
|
+
tableRef,
|
|
294
|
+
resizable,
|
|
295
|
+
optionsComponent,
|
|
296
|
+
rowHeights,
|
|
297
|
+
tableId,
|
|
298
|
+
rowHeight
|
|
299
|
+
);
|
|
356
300
|
});
|
|
357
301
|
const resizeColumnsObserver = new ResizeObserver(() => {
|
|
358
|
-
getMinCellWidthInColumn();
|
|
302
|
+
utils.getMinCellWidthInColumn(tableRef, colWidths, $headerRows[0].cells.length, resizable);
|
|
359
303
|
});
|
|
360
304
|
const observeFirstCells = () => {
|
|
361
305
|
if (!tableRef) return;
|
|
362
|
-
$pageRows.forEach((row) => {
|
|
363
|
-
const cell = tableRef.querySelector(`#${tableId}-row-${row.id}`);
|
|
364
|
-
if (cell) {
|
|
365
|
-
resizeRowsObserver.observe(cell);
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
306
|
tableRef.querySelectorAll("tbody tr td:first-child").forEach((cell) => {
|
|
369
307
|
resizeRowsObserver.observe(cell);
|
|
370
308
|
});
|
|
309
|
+
return resizeRowsObserver;
|
|
371
310
|
};
|
|
372
311
|
const observeHeaderColumns = () => {
|
|
373
312
|
if (!tableRef) return;
|
|
@@ -385,23 +324,11 @@ afterUpdate(() => {
|
|
|
385
324
|
}
|
|
386
325
|
});
|
|
387
326
|
onDestroy(() => {
|
|
388
|
-
resizeRowsObserver.disconnect();
|
|
389
327
|
resizeColumnsObserver.disconnect();
|
|
328
|
+
resizeRowsObserver.disconnect();
|
|
390
329
|
});
|
|
391
|
-
const getDimensions = () => {
|
|
392
|
-
if (!tableRef) return;
|
|
393
|
-
if (resizable === "none") return;
|
|
394
|
-
else if (resizable === "columns") {
|
|
395
|
-
observeHeaderColumns();
|
|
396
|
-
} else if (resizable === "rows") {
|
|
397
|
-
observeFirstCells();
|
|
398
|
-
} else {
|
|
399
|
-
observeHeaderColumns();
|
|
400
|
-
observeFirstCells();
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
330
|
$: sortKeys = pluginStates.sort.sortKeys;
|
|
404
|
-
$: serverSide &&
|
|
331
|
+
$: serverSide && updateTableWithParams();
|
|
405
332
|
$: serverSide && sortServer($sortKeys[0]?.order, $sortKeys[0]?.id);
|
|
406
333
|
$: $hiddenColumnIds = shownColumns.filter((col) => !col.visible).map((col) => col.id);
|
|
407
334
|
</script>
|
|
@@ -501,20 +428,23 @@ $: $hiddenColumnIds = shownColumns.filter((col) => !col.visible).map((col) => co
|
|
|
501
428
|
class="btn btn-sm variant-filled-primary rounded-full order-last flex gap-2 items-center"
|
|
502
429
|
aria-label="Reset sizing of columns and rows"
|
|
503
430
|
on:click|preventDefault={() =>
|
|
504
|
-
resetResize($headerRows, $pageRows, tableId, columns, resizable)}
|
|
431
|
+
utils.resetResize($headerRows, $pageRows, tableId, columns, resizable)}
|
|
505
432
|
><Fa icon={faCompress} /> Reset sizing</button
|
|
506
433
|
>
|
|
507
434
|
{/if}
|
|
435
|
+
<!-- Enable export as CSV button if exportable === true -->
|
|
508
436
|
{#if exportable}
|
|
509
437
|
<button
|
|
510
438
|
type="button"
|
|
511
439
|
class="btn btn-sm variant-filled-primary rounded-full order-last flex items-center gap-2"
|
|
512
440
|
aria-label="Export table data as CSV"
|
|
513
|
-
on:click|preventDefault={() =>
|
|
441
|
+
on:click|preventDefault={() =>
|
|
442
|
+
utils.exportAsCsv(tableId, utils.jsonToCsv($exportedData))}
|
|
514
443
|
><Fa icon={faDownload} /> Export as CSV</button
|
|
515
444
|
>
|
|
516
445
|
{/if}
|
|
517
|
-
|
|
446
|
+
<!-- Enable show/hide columns menu if showColumnsMenu === true -->
|
|
447
|
+
{#if showColumnsMenu && shownColumns.length > 0}
|
|
518
448
|
<ColumnsMenu bind:columns={shownColumns} {tableId} />
|
|
519
449
|
{/if}
|
|
520
450
|
</div>
|
|
@@ -547,16 +477,20 @@ $: $hiddenColumnIds = shownColumns.filter((col) => !col.visible).map((col) => co
|
|
|
547
477
|
{...attrs}
|
|
548
478
|
style={`
|
|
549
479
|
width: ${cell.isData() ? 'auto' : '0'};
|
|
550
|
-
${cellStyle(cell.id, columns)}
|
|
480
|
+
${utils.cellStyle(cell.id, columns)}
|
|
551
481
|
`}
|
|
552
482
|
>
|
|
553
483
|
<div
|
|
554
484
|
class="overflow-auto"
|
|
555
485
|
class:resize-x={(resizable === 'columns' || resizable === 'both') &&
|
|
556
|
-
!fixedWidth(cell.id, columns)}
|
|
486
|
+
!utils.fixedWidth(cell.id, columns)}
|
|
557
487
|
id="th-{tableId}-{cell.id}"
|
|
558
488
|
style={`
|
|
559
|
-
min-width: ${
|
|
489
|
+
min-width: ${
|
|
490
|
+
utils.minWidth(cell.id, columns)
|
|
491
|
+
? utils.minWidth(cell.id, columns)
|
|
492
|
+
: $colWidths[index]
|
|
493
|
+
}px;
|
|
560
494
|
`}
|
|
561
495
|
>
|
|
562
496
|
<div class="flex justify-between items-center">
|
|
@@ -615,15 +549,7 @@ $: $hiddenColumnIds = shownColumns.filter((col) => !col.visible).map((col) => co
|
|
|
615
549
|
? 'resize-y overflow-auto'
|
|
616
550
|
: 'block'}"
|
|
617
551
|
id="{tableId}-{cell.id}-{row.id}"
|
|
618
|
-
style={
|
|
619
|
-
min-height: ${$rowHeights && $rowHeights[+row.id] ? `${$rowHeights[+row.id].min}px` : 'auto'};
|
|
620
|
-
max-height: ${
|
|
621
|
-
index !== 0 && $rowHeights && $rowHeights[+row.id]
|
|
622
|
-
? `${$rowHeights[+row.id].max}px`
|
|
623
|
-
: 'auto'
|
|
624
|
-
};
|
|
625
|
-
height: ${$rowHeights && $rowHeights[+row.id] ? `${$rowHeights[+row.id].min}px` : 'auto'};
|
|
626
|
-
`}
|
|
552
|
+
style={utils.getResizeStyles($rowHeights, row.id, index)}
|
|
627
553
|
>
|
|
628
554
|
<!-- Adding config for initial rowHeight, if provided -->
|
|
629
555
|
<div
|
|
@@ -636,8 +562,8 @@ $: $hiddenColumnIds = shownColumns.filter((col) => !col.visible).map((col) => co
|
|
|
636
562
|
class="grow overflow-auto"
|
|
637
563
|
style={cell.isData()
|
|
638
564
|
? `width: ${
|
|
639
|
-
minWidth(cell.id, columns)
|
|
640
|
-
? minWidth(cell.id, columns)
|
|
565
|
+
utils.minWidth(cell.id, columns)
|
|
566
|
+
? utils.minWidth(cell.id, columns)
|
|
641
567
|
: $colWidths[index]
|
|
642
568
|
}px;`
|
|
643
569
|
: 'max-width: min-content;'}
|
|
@@ -680,12 +606,19 @@ $: $hiddenColumnIds = shownColumns.filter((col) => !col.visible).map((col) => co
|
|
|
680
606
|
{pageIndex}
|
|
681
607
|
{pageSize}
|
|
682
608
|
{serverItemCount}
|
|
683
|
-
{
|
|
609
|
+
updateTable={updateTableWithParams}
|
|
684
610
|
{pageSizes}
|
|
611
|
+
{pageIndexStringType}
|
|
685
612
|
id={tableId}
|
|
686
613
|
/>
|
|
687
614
|
{:else}
|
|
688
|
-
<TablePagination
|
|
615
|
+
<TablePagination
|
|
616
|
+
itemCount={$rows.length}
|
|
617
|
+
pageConfig={pluginStates.page}
|
|
618
|
+
{pageSizes}
|
|
619
|
+
id={tableId}
|
|
620
|
+
{pageIndexStringType}
|
|
621
|
+
/>
|
|
689
622
|
{/if}
|
|
690
623
|
{/if}
|
|
691
624
|
</div>
|
|
@@ -7,9 +7,12 @@ import {
|
|
|
7
7
|
faChevronDown
|
|
8
8
|
} from "@fortawesome/free-solid-svg-icons";
|
|
9
9
|
import { ListBox, ListBoxItem, popup } from "@skeletonlabs/skeleton";
|
|
10
|
+
export let itemCount;
|
|
10
11
|
export let pageConfig;
|
|
11
12
|
export let pageSizes;
|
|
13
|
+
export let pageIndexStringType;
|
|
12
14
|
export let id;
|
|
15
|
+
let indexInformation = "";
|
|
13
16
|
const { pageIndex, pageCount, pageSize, hasNextPage, hasPreviousPage } = pageConfig;
|
|
14
17
|
const goToFirstPage = () => $pageIndex = 0;
|
|
15
18
|
const goToLastPage = () => $pageIndex = $pageCount - 1;
|
|
@@ -32,11 +35,22 @@ const pageSizePopup = {
|
|
|
32
35
|
placement: "bottom",
|
|
33
36
|
closeQuery: ".listbox-item"
|
|
34
37
|
};
|
|
38
|
+
const getIndexInfomationString = () => {
|
|
39
|
+
if (pageIndexStringType === "pages") {
|
|
40
|
+
return $pageCount > 0 ? `Page ${$pageIndex + 1} of ${$pageCount}` : "No pages";
|
|
41
|
+
} else {
|
|
42
|
+
return itemCount === 0 ? "No items" : `Displaying items ${$pageIndex * $pageSize + 1} - ${Math.min(
|
|
43
|
+
($pageIndex + 1) * $pageSize,
|
|
44
|
+
itemCount
|
|
45
|
+
)} of ${Math.min($pageCount * $pageSize, itemCount)}`;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
35
48
|
$: goToFirstPageDisabled = !$pageIndex;
|
|
36
49
|
$: goToLastPageDisabled = $pageIndex == $pageCount - 1;
|
|
37
50
|
$: goToNextPageDisabled = !$hasNextPage;
|
|
38
51
|
$: goToPreviousPageDisabled = !$hasPreviousPage;
|
|
39
52
|
$: $pageSize = pageSizeDropdownValue;
|
|
53
|
+
$: $pageCount, $pageIndex, $pageSize, indexInformation = getIndexInfomationString();
|
|
40
54
|
</script>
|
|
41
55
|
|
|
42
56
|
<div class="flex justify-between w-full items-stretch gap-10">
|
|
@@ -114,12 +128,6 @@ $: $pageSize = pageSizeDropdownValue;
|
|
|
114
128
|
>
|
|
115
129
|
</div>
|
|
116
130
|
<div class="flex justify-end items-center">
|
|
117
|
-
<span class="text-sm text-gray-500">
|
|
118
|
-
{#if $pageCount > 0}
|
|
119
|
-
Page {$pageIndex + 1} of {$pageCount}
|
|
120
|
-
{:else}
|
|
121
|
-
No pages
|
|
122
|
-
{/if}
|
|
123
|
-
</span>
|
|
131
|
+
<span class="text-sm text-gray-500">{indexInformation}</span>
|
|
124
132
|
</div>
|
|
125
133
|
</div>
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
export let id;
|
|
9
9
|
export let pageIndex;
|
|
10
10
|
export let pageSize;
|
|
11
|
+
export let pageIndexStringType;
|
|
11
12
|
export let pageSizes;
|
|
12
13
|
export let serverItemCount;
|
|
13
14
|
export let updateTable;
|
|
@@ -15,6 +16,7 @@ let goToFirstPageDisabled = true;
|
|
|
15
16
|
let goToLastPageDisabled = true;
|
|
16
17
|
let goToNextPageDisabled = true;
|
|
17
18
|
let goToPreviousPageDisabled = true;
|
|
19
|
+
let indexInformation = "";
|
|
18
20
|
const handleChange = (e) => {
|
|
19
21
|
const value = e.target.value;
|
|
20
22
|
if (value > pageCount) {
|
|
@@ -45,12 +47,20 @@ const goTo = (dst) => {
|
|
|
45
47
|
}
|
|
46
48
|
updateTable();
|
|
47
49
|
};
|
|
50
|
+
const getIndexInfomationString = () => {
|
|
51
|
+
if (pageIndexStringType === "pages") {
|
|
52
|
+
return pageCount > 0 ? `Page ${$pageIndex + 1} of ${pageCount}` : "No pages";
|
|
53
|
+
} else {
|
|
54
|
+
return `Showing ${$pageIndex * $pageSize + 1} - ${($pageIndex + 1) * $pageSize} of ${pageCount * $pageSize} items`;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
48
57
|
$: pageCount = Math.ceil($serverItemCount / $pageSize);
|
|
49
58
|
$: goToFirstPageDisabled = !$pageIndex;
|
|
50
59
|
$: goToLastPageDisabled = $pageIndex == pageCount - 1;
|
|
51
60
|
$: goToNextPageDisabled = $pageIndex == pageCount - 1;
|
|
52
61
|
$: goToPreviousPageDisabled = !$pageIndex;
|
|
53
62
|
$: $pageSize && updateTable();
|
|
63
|
+
$: pageCount, $pageIndex, $pageSize, indexInformation = getIndexInfomationString();
|
|
54
64
|
updateTable();
|
|
55
65
|
</script>
|
|
56
66
|
|
|
@@ -113,15 +123,7 @@ updateTable();
|
|
|
113
123
|
</div>
|
|
114
124
|
<div class="flex justify-end items-center">
|
|
115
125
|
<span class="text-sm text-gray-500">
|
|
116
|
-
{
|
|
117
|
-
{#if pageCount == 1}
|
|
118
|
-
1 page
|
|
119
|
-
{:else}
|
|
120
|
-
{pageCount} pages
|
|
121
|
-
{/if}
|
|
122
|
-
{:else}
|
|
123
|
-
No pages
|
|
124
|
-
{/if}
|
|
126
|
+
{indexInformation}
|
|
125
127
|
</span>
|
|
126
128
|
</div>
|
|
127
129
|
</div>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SvelteComponent } from 'svelte';
|
|
2
|
+
import type { Writable } from 'svelte/store';
|
|
3
|
+
import { Receive } from '../../models/Models';
|
|
4
|
+
import type { FilterOptionsEnum } from '../../models/Enums';
|
|
5
|
+
import type { Columns, Filter, ServerColumn, ServerConfig } from '../../models/Models';
|
|
6
|
+
export declare const minWidth: (id: string, columns: Columns | undefined) => number;
|
|
7
|
+
export declare const fixedWidth: (id: string, columns: Columns | undefined) => number;
|
|
8
|
+
export declare const cellStyle: (id: string, columns: Columns | undefined) => string;
|
|
9
|
+
export declare const normalizeFilters: (filters: {
|
|
10
|
+
[key: string]: { [key in FilterOptionsEnum]?: number | string | Date; };
|
|
11
|
+
}) => Filter[];
|
|
12
|
+
export declare const exportAsCsv: (tableId: string, exportedData: string) => void;
|
|
13
|
+
export declare const jsonToCsv: (data: string) => string;
|
|
14
|
+
export declare const resetResize: (headerRows: any, pageRows: any, tableId: string, columns: Columns | undefined, resizable: "none" | "rows" | "columns" | "both") => void;
|
|
15
|
+
export declare const missingValuesFn: (key: number | string, missingValues: {
|
|
16
|
+
[key: string | number]: string;
|
|
17
|
+
}) => string | number;
|
|
18
|
+
export declare const updateTable: (pageSize: number, pageIndex: number, server: ServerConfig | undefined, filters: {
|
|
19
|
+
[key: string]: { [key in FilterOptionsEnum]?: number | string | Date; };
|
|
20
|
+
}, data: Writable<any[]>, serverItems: Writable<number> | undefined, columns: Columns | undefined, dispatch: any) => Promise<Receive>;
|
|
21
|
+
export declare const convertServerColumns: (serverColumns: ServerColumn[], columns: Columns | undefined) => Columns;
|
|
22
|
+
export declare const getMaxCellHeightInRow: (tableRef: HTMLTableElement, resizable: "columns" | "rows" | "none" | "both", optionsComponent: typeof SvelteComponent | undefined, rowHeights: Writable<{
|
|
23
|
+
[key: number]: {
|
|
24
|
+
max: number;
|
|
25
|
+
min: number;
|
|
26
|
+
};
|
|
27
|
+
}>, tableId: string, rowHeight: number | null) => void;
|
|
28
|
+
export declare const getMinCellWidthInColumn: (tableRef: HTMLTableElement, colWidths: Writable<number[]>, headerRowsLength: number, resizable: "columns" | "rows" | "none" | "both") => void;
|
|
29
|
+
export declare const getResizeStyles: (rowHeights: {
|
|
30
|
+
[key: number]: {
|
|
31
|
+
max: number;
|
|
32
|
+
min: number;
|
|
33
|
+
};
|
|
34
|
+
}, id: string | number, index: number) => string;
|