@zhangt58/svelte-vtable 0.2.0 → 0.3.3
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 +38 -2
- package/dist/components/DataTable.svelte +490 -0
- package/dist/components/DataTable.svelte.d.ts +31 -0
- package/dist/components/DataTableControls.svelte +589 -0
- package/dist/components/DataTableControls.svelte.d.ts +39 -0
- package/{src → dist}/components/DataTableFilters.svelte +18 -3
- package/dist/components/DataTableFilters.svelte.d.ts +37 -0
- package/dist/components/FiltersModal.svelte +72 -0
- package/dist/components/FiltersModal.svelte.d.ts +25 -0
- package/dist/components/PaginationBar.svelte.d.ts +15 -0
- package/{src → dist}/components/filters/FilterColumn.svelte +10 -3
- package/dist/components/filters/FilterColumn.svelte.d.ts +19 -0
- package/dist/components/filters/FilterDateRange.svelte.d.ts +19 -0
- package/{src → dist}/components/filters/FilterValueList.svelte +43 -10
- package/dist/components/filters/FilterValueList.svelte.d.ts +33 -0
- package/dist/components/filters/useFilterState.svelte.d.ts +25 -0
- package/dist/components/flowbite/DataTableControls.svelte +528 -0
- package/dist/components/flowbite/DataTableControls.svelte.d.ts +39 -0
- package/{src/components → dist/components/flowbite}/FiltersModal.svelte +5 -4
- package/dist/components/flowbite/FiltersModal.svelte.d.ts +25 -0
- package/dist/filterUtils.d.ts +76 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.flowbite.d.ts +3 -0
- package/dist/index.flowbite.js +9 -0
- package/{src/lib → dist}/index.js +7 -7
- package/{src/lib → dist}/styles.css +11 -1
- package/package.json +37 -18
- package/src/components/DataTable.svelte +0 -234
- package/src/components/DataTableControls.svelte +0 -270
- package/src/lib/dist/styles.css +0 -287
- /package/{src → dist}/components/PaginationBar.svelte +0 -0
- /package/{src → dist}/components/filters/FilterDateRange.svelte +0 -0
- /package/{src → dist}/components/filters/useFilterState.svelte.js +0 -0
- /package/{src/lib → dist}/filterUtils.js +0 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export { default as DataTableControls } from "./components/DataTableControls.svelte";
|
|
2
|
+
export { default as DataTableFilters } from "./components/DataTableFilters.svelte";
|
|
3
|
+
export { default as DataTable } from "./components/DataTable.svelte";
|
|
4
|
+
export { default as FilterColumn } from "./components/filters/FilterColumn.svelte";
|
|
5
|
+
export { default as FilterValueList } from "./components/filters/FilterValueList.svelte";
|
|
6
|
+
export { default as FilterDateRange } from "./components/filters/FilterDateRange.svelte";
|
|
7
|
+
export { useFilterState } from "./components/filters/useFilterState.svelte.js";
|
|
8
|
+
/**
|
|
9
|
+
* Unified column definition for DataTable.
|
|
10
|
+
* Pass an array of `ColumnDef` objects as the `columns` prop to configure
|
|
11
|
+
* visible keys, widths, sorting, filters, and custom snippets from a single place.
|
|
12
|
+
*/
|
|
13
|
+
export type ColumnDef<T extends Record<string, unknown> = Record<string, unknown>> = {
|
|
14
|
+
/**
|
|
15
|
+
* - Data key. Must match a property on the row item.
|
|
16
|
+
*/
|
|
17
|
+
key: string;
|
|
18
|
+
/**
|
|
19
|
+
* - Display label for the column header. Defaults to `key`.
|
|
20
|
+
*/
|
|
21
|
+
label?: string;
|
|
22
|
+
/**
|
|
23
|
+
* - Column width: a stretch weight (number) or a
|
|
24
|
+
* CSS width value such as `'120px'`. Defaults to `1` (equal stretch).
|
|
25
|
+
*/
|
|
26
|
+
width?: number | string;
|
|
27
|
+
/**
|
|
28
|
+
* - Whether clicking the column header sorts the
|
|
29
|
+
* table. Defaults to `true`.
|
|
30
|
+
*/
|
|
31
|
+
sortable?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Filter UI to render for this column:
|
|
34
|
+
* - `'value'` — checkbox list of unique values (default)
|
|
35
|
+
* - `'daterange'` — date-only range picker
|
|
36
|
+
* - `'datetimerange'` — datetime range picker
|
|
37
|
+
* - `'none'` — no filter UI for this column
|
|
38
|
+
*/
|
|
39
|
+
filterType?: "value" | "daterange" | "datetimerange" | "none";
|
|
40
|
+
/**
|
|
41
|
+
* Custom Svelte 5 snippet rendered inside the `<th>`. Receives
|
|
42
|
+
* `{ key, label, sortKey, sortDir }`.
|
|
43
|
+
*/
|
|
44
|
+
headerSnippet?: import("svelte").Snippet<[{
|
|
45
|
+
key: string;
|
|
46
|
+
label: string;
|
|
47
|
+
sortKey: string | null;
|
|
48
|
+
sortDir: string;
|
|
49
|
+
}]>;
|
|
50
|
+
/**
|
|
51
|
+
* Custom Svelte 5 snippet rendered inside each `<td>` for this column.
|
|
52
|
+
* Receives `{ item, value, index }`. When omitted the raw value is rendered.
|
|
53
|
+
*/
|
|
54
|
+
cellSnippet?: import("svelte").Snippet<[{
|
|
55
|
+
item: T;
|
|
56
|
+
value: unknown;
|
|
57
|
+
index: number;
|
|
58
|
+
}]>;
|
|
59
|
+
};
|
|
60
|
+
export { getUniqueValuesWithCounts, buildColumnFilters, applyFilters, matchesDateRange, hasActiveFilters, countActiveFilters, clearAllFilters, filtersToSearchParams, searchParamsToFilters } from "./filterUtils.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Flowbite-flavoured adapter components.
|
|
2
|
+
// Import from '@zhangt58/svelte-vtable/flowbite' to use these.
|
|
3
|
+
// Requires flowbite-svelte as a peer dependency.
|
|
4
|
+
export { default as DataTableControls } from './components/flowbite/DataTableControls.svelte';
|
|
5
|
+
export { default as FiltersModal } from './components/flowbite/FiltersModal.svelte';
|
|
6
|
+
|
|
7
|
+
// Re-export everything from the headless entrypoint so consumers can import
|
|
8
|
+
// DataTable, DataTableFilters, and utilities from a single path.
|
|
9
|
+
export * from './index.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export { default as DataTableControls } from '
|
|
2
|
-
export { default as DataTableFilters } from '
|
|
3
|
-
export { default as DataTable } from '
|
|
1
|
+
export { default as DataTableControls } from './components/DataTableControls.svelte';
|
|
2
|
+
export { default as DataTableFilters } from './components/DataTableFilters.svelte';
|
|
3
|
+
export { default as DataTable } from './components/DataTable.svelte';
|
|
4
4
|
|
|
5
5
|
// Filter sub-components (individually importable)
|
|
6
|
-
export { default as FilterColumn } from '
|
|
7
|
-
export { default as FilterValueList } from '
|
|
8
|
-
export { default as FilterDateRange } from '
|
|
9
|
-
export { useFilterState } from '
|
|
6
|
+
export { default as FilterColumn } from './components/filters/FilterColumn.svelte';
|
|
7
|
+
export { default as FilterValueList } from './components/filters/FilterValueList.svelte';
|
|
8
|
+
export { default as FilterDateRange } from './components/filters/FilterDateRange.svelte';
|
|
9
|
+
export { useFilterState } from './components/filters/useFilterState.svelte.js';
|
|
10
10
|
|
|
11
11
|
// Export filter utility functions
|
|
12
12
|
export {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
min-width: 0;
|
|
18
18
|
height: 100%;
|
|
19
19
|
overflow: auto;
|
|
20
|
+
isolation: isolate;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
:global(.datatable-table) {
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
:global(.datatable-table) thead.sticky-header {
|
|
37
38
|
position: sticky;
|
|
38
39
|
top: 0;
|
|
39
|
-
z-index:
|
|
40
|
+
z-index: 2;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
/* Header visual styles - only bottom border */
|
|
@@ -170,6 +171,15 @@
|
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
/* Shared control styles (inputs, pagination, column filters) used by page components */
|
|
174
|
+
|
|
175
|
+
/* Accent-color focus ring for search input and per-page select — respects --vtable-color-accent */
|
|
176
|
+
:global(.vtable-search-input:focus),
|
|
177
|
+
:global(.vtable-perpage-select:focus) {
|
|
178
|
+
border-color: var(--vtable-color-accent-border);
|
|
179
|
+
box-shadow: 0 0 0 2px color-mix(in srgb, var(--vtable-color-accent) 20%, transparent);
|
|
180
|
+
outline: none;
|
|
181
|
+
}
|
|
182
|
+
|
|
173
183
|
:global(.datatable-input) {
|
|
174
184
|
padding: 0.375rem 0.75rem;
|
|
175
185
|
font-size: 0.95rem;
|
package/package.json
CHANGED
|
@@ -1,26 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhangt58/svelte-vtable",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "A Svelte 5 library for virtualized data tables with sorting, selection, and pagination controls.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"*.css"
|
|
8
|
+
],
|
|
9
|
+
"svelte": "./dist/index.js",
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
9
13
|
"exports": {
|
|
10
14
|
".": {
|
|
11
|
-
"svelte": "./
|
|
12
|
-
"
|
|
13
|
-
"
|
|
15
|
+
"svelte": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./controls": {
|
|
20
|
+
"svelte": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
14
23
|
},
|
|
15
|
-
"./
|
|
24
|
+
"./flowbite": {
|
|
25
|
+
"svelte": "./dist/index.flowbite.js",
|
|
26
|
+
"types": "./dist/index.flowbite.d.ts",
|
|
27
|
+
"import": "./dist/index.flowbite.js"
|
|
28
|
+
},
|
|
29
|
+
"./styles.css": "./dist/styles.css"
|
|
16
30
|
},
|
|
17
31
|
"scripts": {
|
|
18
|
-
"check": "svelte-check --tsconfig ./
|
|
32
|
+
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
19
33
|
"build:styles": "node ./scripts/build-styles.cjs",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
34
|
+
"build": "svelte-package -i src/lib",
|
|
35
|
+
"prepare": "npm run build:styles && npm run build",
|
|
36
|
+
"prepublishOnly": "npm run build && npm run check && npm run test",
|
|
22
37
|
"format": "prettier --write .",
|
|
23
|
-
"format:check": "prettier --check ."
|
|
38
|
+
"format:check": "prettier --check .",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"test:watch": "vitest"
|
|
24
41
|
},
|
|
25
42
|
"keywords": [
|
|
26
43
|
"svelte",
|
|
@@ -43,25 +60,27 @@
|
|
|
43
60
|
},
|
|
44
61
|
"homepage": "https://github.com/zhangt58/svelte-vtable#readme",
|
|
45
62
|
"peerDependencies": {
|
|
46
|
-
"flowbite-svelte": "^1.28.1",
|
|
47
|
-
"flowbite-svelte-icons": "^3.0.0",
|
|
48
63
|
"svelte": "^5.43.5",
|
|
49
64
|
"svelte-virtuallists": "^1.4.2",
|
|
50
65
|
"tailwindcss": "^4.1.17"
|
|
51
66
|
},
|
|
67
|
+
"optionalPeerDependencies": {
|
|
68
|
+
"flowbite-svelte": "^1.28.1"
|
|
69
|
+
},
|
|
52
70
|
"devDependencies": {
|
|
71
|
+
"@sveltejs/package": "^2.5.7",
|
|
53
72
|
"@sveltejs/vite-plugin-svelte": "^6.2.1",
|
|
54
73
|
"flowbite-svelte": "^1.28.1",
|
|
55
|
-
"
|
|
74
|
+
"prettier": "^3.7.4",
|
|
75
|
+
"prettier-plugin-svelte": "^3.4.1",
|
|
56
76
|
"svelte": "^5.0.0",
|
|
57
77
|
"svelte-check": "^4.3.4",
|
|
58
78
|
"svelte-virtuallists": "^1.4.2",
|
|
59
79
|
"vite": "^7.2.2",
|
|
60
|
-
"
|
|
61
|
-
"prettier-plugin-svelte": "^3.4.1"
|
|
80
|
+
"vitest": "^2.1.9"
|
|
62
81
|
},
|
|
63
82
|
"files": [
|
|
64
|
-
"
|
|
83
|
+
"dist",
|
|
65
84
|
"README.md",
|
|
66
85
|
"LICENSE"
|
|
67
86
|
]
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import { VirtualList } from 'svelte-virtuallists';
|
|
3
|
-
|
|
4
|
-
// Runic props: accept props via $props() so the component matches the
|
|
5
|
-
// project's runes-style components. Include the `select` callback prop.
|
|
6
|
-
let {
|
|
7
|
-
items = [],
|
|
8
|
-
// Unified column definitions array (required).
|
|
9
|
-
// @type {import('../lib/index.js').ColumnDef[]}
|
|
10
|
-
columns = [],
|
|
11
|
-
// sortKey/sortDir are bindable so parents can observe or control sort state.
|
|
12
|
-
sortKey = $bindable(null),
|
|
13
|
-
sortDir = $bindable('asc'),
|
|
14
|
-
className = '',
|
|
15
|
-
style = '',
|
|
16
|
-
emptyMessage = 'No items to display.',
|
|
17
|
-
selected = null,
|
|
18
|
-
// onselect({ item, index }) — called when a row is selected
|
|
19
|
-
onselect = undefined,
|
|
20
|
-
// onsort({ key, dir }) is called whenever sort changes.
|
|
21
|
-
// When provided, no local sorting is applied (server-side sort pattern).
|
|
22
|
-
onsort = undefined,
|
|
23
|
-
// Allow consumers to disable virtualization (useful when paginating by fixed item counts).
|
|
24
|
-
// If `virtualize` is false we ask the wrapped VirtualList to render as a normal list/table
|
|
25
|
-
// by setting its `isDisabled` prop. Default: true (virtualization enabled).
|
|
26
|
-
virtualize = true,
|
|
27
|
-
} = $props();
|
|
28
|
-
|
|
29
|
-
// --- Derived values from ColumnDef[] ---
|
|
30
|
-
|
|
31
|
-
// Keys of columns to display.
|
|
32
|
-
const effectiveVisibleKeys = $derived(columns.map((c) => c.key));
|
|
33
|
-
|
|
34
|
-
// Width configuration: build an object keyed by column key.
|
|
35
|
-
const effectiveColWidths = $derived(
|
|
36
|
-
Object.fromEntries(columns.map((c) => [c.key, c.width ?? 1])),
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
// Fast lookup map: key → ColumnDef.
|
|
40
|
-
const colDefMap = $derived(Object.fromEntries(columns.map((c) => [c.key, c])));
|
|
41
|
-
|
|
42
|
-
// Internal sorted array derived from items + current sort state.
|
|
43
|
-
// When onsort is provided the parent manages sorting (server-side), so we
|
|
44
|
-
// pass items through unchanged. Otherwise we sort locally.
|
|
45
|
-
const sortedItems = $derived.by(() => {
|
|
46
|
-
if (onsort !== undefined || !sortKey) return items;
|
|
47
|
-
|
|
48
|
-
const key = sortKey;
|
|
49
|
-
const dir = sortDir;
|
|
50
|
-
return [...items].sort((a, b) => {
|
|
51
|
-
const aVal = a[key];
|
|
52
|
-
const bVal = b[key];
|
|
53
|
-
|
|
54
|
-
// Handle null/undefined values
|
|
55
|
-
if (aVal == null && bVal == null) return 0;
|
|
56
|
-
if (aVal == null) return 1;
|
|
57
|
-
if (bVal == null) return -1;
|
|
58
|
-
|
|
59
|
-
// Convert to strings for comparison
|
|
60
|
-
const aStr = String(aVal);
|
|
61
|
-
const bStr = String(bVal);
|
|
62
|
-
|
|
63
|
-
// Alphabetical comparison
|
|
64
|
-
const comparison = aStr.localeCompare(bStr, undefined, {
|
|
65
|
-
numeric: true,
|
|
66
|
-
sensitivity: 'base',
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
return dir === 'asc' ? comparison : -comparison;
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// expose selection via the callback prop (if provided)
|
|
74
|
-
function selectItem(item, index) {
|
|
75
|
-
selected = item;
|
|
76
|
-
try {
|
|
77
|
-
if (onselect !== undefined) {
|
|
78
|
-
onselect({ item, index });
|
|
79
|
-
}
|
|
80
|
-
} catch (err) {
|
|
81
|
-
try {
|
|
82
|
-
console.error('onselect threw:', err);
|
|
83
|
-
} catch (e) {}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// When a header is clicked, toggle/update sortKey and sortDir, then notify
|
|
88
|
-
// the parent via onsort. Parents using bind:sortKey / bind:sortDir will
|
|
89
|
-
// receive the updated values automatically.
|
|
90
|
-
function handleSort(key) {
|
|
91
|
-
if (sortKey === key) {
|
|
92
|
-
sortDir = sortDir === 'asc' ? 'desc' : 'asc';
|
|
93
|
-
} else {
|
|
94
|
-
sortKey = key;
|
|
95
|
-
sortDir = 'asc';
|
|
96
|
-
}
|
|
97
|
-
try {
|
|
98
|
-
if (onsort) onsort({ key: sortKey, dir: sortDir });
|
|
99
|
-
} catch (err) {
|
|
100
|
-
try {
|
|
101
|
-
console.error('onsort threw:', err);
|
|
102
|
-
} catch (e) {}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Normalize colWidths: treat numeric values as stretch weights and pass through CSS strings.
|
|
107
|
-
// Memoized: only recomputes when effectiveVisibleKeys or effectiveColWidths changes.
|
|
108
|
-
const colWidthMap = $derived(normalizeColWidths());
|
|
109
|
-
|
|
110
|
-
function normalizeColWidths() {
|
|
111
|
-
const map = {};
|
|
112
|
-
const keys = effectiveVisibleKeys;
|
|
113
|
-
const widths = effectiveColWidths;
|
|
114
|
-
|
|
115
|
-
const numeric = [];
|
|
116
|
-
const otherStrings = [];
|
|
117
|
-
|
|
118
|
-
for (const key of keys) {
|
|
119
|
-
const v = widths[key];
|
|
120
|
-
if (typeof v === 'number' && !Number.isNaN(v)) {
|
|
121
|
-
numeric.push({ key, w: v });
|
|
122
|
-
} else if (typeof v === 'string') {
|
|
123
|
-
const s = v.trim();
|
|
124
|
-
if (!s.endsWith('%')) {
|
|
125
|
-
otherStrings.push({ key, v: s });
|
|
126
|
-
}
|
|
127
|
-
// percent strings are intentionally unsupported — ignore silently
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const totalWeight = numeric.reduce((s, r) => s + r.w, 0);
|
|
132
|
-
const availablePct = 100;
|
|
133
|
-
|
|
134
|
-
if (numeric.length > 0 && totalWeight > 0) {
|
|
135
|
-
let acc = 0;
|
|
136
|
-
numeric.forEach((n, idx) => {
|
|
137
|
-
const pct =
|
|
138
|
-
idx === numeric.length - 1
|
|
139
|
-
? Math.max(0, Math.round((availablePct - acc) * 100) / 100)
|
|
140
|
-
: Math.round((n.w / totalWeight) * availablePct * 100) / 100;
|
|
141
|
-
map[n.key] = `${pct}%`;
|
|
142
|
-
acc += pct;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Copy through non-percent CSS strings (e.g. '120px')
|
|
147
|
-
for (const o of otherStrings) {
|
|
148
|
-
map[o.key] = o.v;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return map;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Compute column width by key (fallback to even distribution)
|
|
155
|
-
function calcColWidth(key) {
|
|
156
|
-
if (colWidthMap[key] !== undefined) return String(colWidthMap[key]);
|
|
157
|
-
const n = Math.max(1, effectiveVisibleKeys.length);
|
|
158
|
-
return Math.floor(100 / n) + '%';
|
|
159
|
-
}
|
|
160
|
-
</script>
|
|
161
|
-
|
|
162
|
-
<section class="virtual-data-table {className}" {style}>
|
|
163
|
-
{#if items && items.length > 0}
|
|
164
|
-
<!-- When `virtualize` is false we instruct VirtualList to render as a normal list/table
|
|
165
|
-
by setting `isDisabled`. This ensures pagination based on item counts shows the
|
|
166
|
-
exact number of rows expected (useful when rows have variable height). -->
|
|
167
|
-
<VirtualList
|
|
168
|
-
items={sortedItems}
|
|
169
|
-
isTable
|
|
170
|
-
isDisabled={!virtualize}
|
|
171
|
-
class="datatable-table max-w-full max-h-full overflow-auto"
|
|
172
|
-
>
|
|
173
|
-
<!-- colgroup enforces the column widths so table-layout: fixed distributes as intended -->
|
|
174
|
-
{#snippet header()}
|
|
175
|
-
<colgroup>
|
|
176
|
-
{#each effectiveVisibleKeys as key}
|
|
177
|
-
<col style="width: {calcColWidth(key)}" />
|
|
178
|
-
{/each}
|
|
179
|
-
</colgroup>
|
|
180
|
-
<thead class="sticky-header">
|
|
181
|
-
<tr>
|
|
182
|
-
{#each effectiveVisibleKeys as key}
|
|
183
|
-
{@const colDef = colDefMap[key]}
|
|
184
|
-
{@const label = colDef?.label ?? key}
|
|
185
|
-
{@const isSortable = colDef?.sortable !== false}
|
|
186
|
-
<th
|
|
187
|
-
style="width: {calcColWidth(key)}"
|
|
188
|
-
class={isSortable ? 'cursor-pointer select-none' : 'select-none'}
|
|
189
|
-
onclick={isSortable ? () => handleSort(key) : undefined}
|
|
190
|
-
aria-sort={sortKey === key
|
|
191
|
-
? sortDir === 'asc'
|
|
192
|
-
? 'ascending'
|
|
193
|
-
: 'descending'
|
|
194
|
-
: 'none'}
|
|
195
|
-
>
|
|
196
|
-
{#if colDef?.headerSnippet}
|
|
197
|
-
{@render colDef.headerSnippet({ key, label, sortKey, sortDir })}
|
|
198
|
-
{:else}
|
|
199
|
-
<div class="inline-flex items-center gap-1">
|
|
200
|
-
<span>{label}</span>
|
|
201
|
-
{#if sortKey === key}
|
|
202
|
-
<span aria-hidden="true">{sortDir === 'asc' ? '▲' : '▼'}</span>
|
|
203
|
-
{/if}
|
|
204
|
-
</div>
|
|
205
|
-
{/if}
|
|
206
|
-
</th>
|
|
207
|
-
{/each}
|
|
208
|
-
</tr>
|
|
209
|
-
</thead>
|
|
210
|
-
{/snippet}
|
|
211
|
-
|
|
212
|
-
{#snippet vl_slot({ index, item })}
|
|
213
|
-
<!-- Default row rendering using each column's cellSnippet or raw value -->
|
|
214
|
-
<tr onclick={() => selectItem(item, index)} class={selected === item ? 'selected' : ''}>
|
|
215
|
-
{#each columns as col}
|
|
216
|
-
<td>
|
|
217
|
-
{#if col.cellSnippet}
|
|
218
|
-
{@render col.cellSnippet({ item, value: item[col.key], index })}
|
|
219
|
-
{:else}
|
|
220
|
-
{item[col.key] ?? ''}
|
|
221
|
-
{/if}
|
|
222
|
-
</td>
|
|
223
|
-
{/each}
|
|
224
|
-
</tr>
|
|
225
|
-
{/snippet}
|
|
226
|
-
</VirtualList>
|
|
227
|
-
{:else}
|
|
228
|
-
<div class="p-4 text-center text-slate-500">{emptyMessage}</div>
|
|
229
|
-
{/if}
|
|
230
|
-
</section>
|
|
231
|
-
|
|
232
|
-
<style>
|
|
233
|
-
@import '../lib/dist/styles.css';
|
|
234
|
-
</style>
|