Repository navigation
Expand file tree
/
Copy pathdatatable.html
More file actions
124 lines (106 loc) · 5.65 KB
/
Copy pathdatatable.html
File metadata and controls
124 lines (106 loc) · 5.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Data tables - rnxJS</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Archivo:wght@600;700&family=JetBrains+Mono:wght@400;500&family=Public+Sans:wght@400;500;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="index.css">
<link rel="stylesheet" href="demo.css">
</head>
<body>
<div class="topbar">
<div class="shell topbar-in mono">
<a class="wordmark" href="./" style="color:inherit;text-decoration:none">rnxJS</a>
<span class="sep">/</span>
<span>data tables</span>
<span class="spacer"></span>
<a class="chan" href="./"><i class="bi bi-arrow-left"></i> All demos</a>
</div>
</div>
<div class="shell">
<header class="page-head">
<div class="titles">
<h1>Shipment ledger</h1>
<p class="sub">
One <code><DataTable></code> with sorting, filtering and pagination.
Click any column header.
</p>
</div>
<div class="page-actions" data-ref="actions"></div>
</header>
<section class="grid-metrics">
<div class="metric"><span class="k">Consignments</span><span class="v" data-ref="mTotal">0</span><span class="d">across 6 lanes</span></div>
<div class="metric"><span class="k">In transit</span><span class="v" data-ref="mTransit">0</span><span class="d">live tracking</span></div>
<div class="metric"><span class="k">Delayed</span><span class="v" data-ref="mLate">0</span><span class="d down">customs holds</span></div>
<div class="metric"><span class="k">Total value</span><span class="v" data-ref="mValue">0</span><span class="d">declared, EUR</span></div>
</section>
<section class="panel" style="margin-top:0.85rem">
<div class="panel-head">
<h2>All consignments</h2>
<p class="hint">Filter with the box, sort with the headers</p>
</div>
<div class="panel-body flush" data-ref="table"></div>
</section>
</div>
<footer style="margin-top:2.5rem">
<div class="shell" style="display:flex;gap:1.25rem;flex-wrap:wrap;align-items:center;">
<span class="mono" data-ref="footVersion">rnxJS</span>
<a href="./">All demos</a>
<a href="https://github.com/BaryoDev/rnxJS_samples">Source</a>
<span style="margin-left:auto" class="mono">MPL-2.0</span>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/@arnelirobles/rnxjs@2.3.1/dist/rnx.global.js"></script>
<script>
const { DataTable, Button } = rnx;
const $ = (ref) => document.querySelector(`[data-ref="${ref}"]`);
const num = (v) => v.toLocaleString('en-US');
const LANES = ['Rotterdam to Lyon', 'Hamburg to Prague', 'Antwerp to Milan',
'Gdansk to Vienna', 'Bilbao to Toulouse', 'Trieste to Munich'];
const STATUS = ['In transit', 'In transit', 'In transit', 'At customs', 'Delayed', 'Delivered'];
const CARRIERS = ['Meridian Haulage', 'Kestrel Logistics', 'Alpine Freight', 'Delta Roadways'];
// Deterministic sample data: a demo that reshuffles on every reload is
// harder to talk about, and impossible to write a test against.
const rows = Array.from({ length: 28 }, (_, i) => {
const s = STATUS[i % STATUS.length];
return {
ref: 'CN-' + (20480 - i * 7),
lane: LANES[i % LANES.length],
carrier: CARRIERS[i % CARRIERS.length],
status: s,
pallets: 4 + ((i * 3) % 19),
value: '€' + num(1800 + ((i * 1373) % 24000)),
eta: ['today', 'tomorrow', 'in 2 days', 'in 4 days'][i % 4],
};
});
$('mTotal').textContent = num(rows.length);
$('mTransit').textContent = num(rows.filter(r => r.status === 'In transit').length);
$('mLate').textContent = num(rows.filter(r => r.status === 'Delayed').length);
$('mValue').textContent = '€' + num(
rows.reduce((a, r) => a + Number(r.value.replace(/[^0-9]/g, '')), 0));
$('table').appendChild(DataTable({
columns: [
{ key: 'ref', label: 'Ref', sortable: true },
{ key: 'lane', label: 'Lane', sortable: true, filterable: true },
{ key: 'carrier', label: 'Carrier', sortable: true, filterable: true },
{ key: 'status', label: 'Status', sortable: true, filterable: true },
{ key: 'pallets', label: 'Pallets', sortable: true },
{ key: 'value', label: 'Value', sortable: true },
{ key: 'eta', label: 'ETA', sortable: true },
],
rows,
pageSize: 10,
filterable: true,
ariaLabel: 'Consignments',
}));
$('actions').append(Button({ label: 'Export CSV', icon: 'download', variant: 'outlined' }));
const build = (document.documentElement.dataset.rnxVersion || '').trim();
if (build) $('footVersion').textContent = 'rnxJS ' + build;
</script>
</body>
</html>