@zhangt58/svelte-vtable 0.4.2 → 0.5.0

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 CHANGED
@@ -142,26 +142,27 @@ A virtualized table component for efficient rendering of large datasets. The com
142
142
 
143
143
  #### Props
144
144
 
145
- | Prop | Type | Default | Description |
146
- | --------------- | ----------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
147
- | `items` | `Array` | `[]` | Array of data items to display |
148
- | `columns` | `ColumnDef[]` | `undefined` | **Unified column definitions** (recommended). When provided, `visibleKeys`, `colWidths`, and `rowSnippet` may be omitted. See [ColumnDef](#columndef) below. |
149
- | `visibleKeys` | `Array` | `[]` | _(Legacy)_ Array of keys to display as column headers. Ignored when `columns` is provided. |
150
- | `sortKey` | `string \| null` | `null` | Current sort key (column header); supports `bind:sortKey` |
151
- | `sortDir` | `'asc' \| 'desc'` | `'asc'` | Sort direction; supports `bind:sortDir` |
152
- | `className` | `string` | `''` | Additional CSS classes |
153
- | `style` | `string` | `''` | Inline styles |
154
- | `emptyMessage` | `string` | `'No items to display.'` | Message when no items |
155
- | `colWidths` | `object \| Array` | `{}` | _(Legacy)_ Column width configuration (stretch weights or pixel values). Ignored when `columns` is provided. |
156
- | `selected` | `any` | `null` | Currently selected item |
157
- | `onselect` | `function` | `undefined` | Callback when a row is selected: `({item, index}) => void` |
158
- | `onsort` | `function` | `undefined` | Callback when sort changes: `({key, dir}) => void`. When provided, local sorting is skipped (server-side sort pattern). Omit entirely (do not pass `() => {}`) to enable local sorting. |
159
- | `inlineFilters` | `boolean` | `false` | Renders column filter buttons in table headers. Without `onfilter`, filters are applied locally to `items`. |
160
- | `columnFilters` | `Array \| null` | `null` | Optional explicit filter configurations, usually from `buildColumnFilters(rows, columns)`. Overrides derived filter options. |
161
- | `filterItems` | `Array \| null` | `null` | Base data source used to derive inline filter options when `columnFilters` is omitted. Defaults to `items`; pass the unpaged/search-scoped rows when `items` is paged. |
162
- | `activeFilters` | `Object` | `{}` | Controlled filter state for inline header filters. |
163
- | `onfilter` | `function` | `undefined` | Callback when inline filters change: `({key, values, allFilters}) => void`. When provided, parent code is responsible for applying filters. |
164
- | `rowSnippet` | `Snippet` | `undefined` | Svelte 5 snippet for rendering rows. Optional when `columns` is provided (a default row is rendered using each column's `cellSnippet` or raw value). |
145
+ | Prop | Type | Default | Description |
146
+ | --------------- | ---------------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
147
+ | `items` | `Array` | `[]` | Array of data items to display |
148
+ | `columns` | `ColumnDef[]` | `undefined` | **Unified column definitions** (recommended). When provided, `visibleKeys`, `colWidths`, and `rowSnippet` may be omitted. See [ColumnDef](#columndef) below. |
149
+ | `visibleKeys` | `Array` | `[]` | _(Legacy)_ Array of keys to display as column headers. Ignored when `columns` is provided. |
150
+ | `sortKey` | `string \| null` | `null` | Current sort key (column header); supports `bind:sortKey` |
151
+ | `sortDir` | `'asc' \| 'desc'` | `'asc'` | Sort direction; supports `bind:sortDir` |
152
+ | `className` | `string` | `''` | Additional CSS classes |
153
+ | `style` | `string` | `''` | Inline styles |
154
+ | `emptyMessage` | `string` | `'No items to display.'` | Message when no items |
155
+ | `colWidths` | `object \| Array` | `{}` | _(Legacy)_ Column width configuration (stretch weights or pixel values). Ignored when `columns` is provided. |
156
+ | `selected` | `any` | `null` | Currently selected item |
157
+ | `onselect` | `function` | `undefined` | Callback when a row is selected: `({item, index}) => void` |
158
+ | `onsort` | `function` | `undefined` | Callback when sort changes: `({key, dir}) => void`. When provided, local sorting is skipped (server-side sort pattern). Omit entirely (do not pass `() => {}`) to enable local sorting. |
159
+ | `inlineFilters` | `boolean` | `false` | Renders column filter buttons in table headers. Without `onfilter`, filters are applied locally to `items`. |
160
+ | `columnFilters` | `Array \| null` | `null` | Optional explicit filter configurations, usually from `buildColumnFilters(rows, columns)`. Overrides derived filter options. |
161
+ | `filterItems` | `Array \| null` | `null` | Base data source used to derive inline filter options when `columnFilters` is omitted. Defaults to `items`; pass the unpaged/search-scoped rows when `items` is paged. |
162
+ | `activeFilters` | `Object` | `{}` | Controlled filter state for inline header filters. |
163
+ | `onfilter` | `function` | `undefined` | Callback when inline filters change: `({key, values, allFilters}) => void`. When provided, parent code is responsible for applying filters. |
164
+ | `rowSnippet` | `Snippet` | `undefined` | Svelte 5 snippet for rendering rows. Optional when `columns` is provided (a default row is rendered using each column's `cellSnippet` or raw value). |
165
+ | `density` | `'comfortable' \| 'compact'` | `'comfortable'` | Row density. `'compact'` tightens the body cell padding so more rows fit. |
165
166
 
166
167
  #### Row Snippet Parameters
167
168
 
@@ -184,7 +185,9 @@ The `rowSnippet` receives an object with:
184
185
  | --------------- | --------------------------------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------- |
185
186
  | `key` | `string` | required | Data key. Must match a property on the row item. |
186
187
  | `label` | `string` | `key` | Column header label. Defaults to `key`. |
187
- | `width` | `number \| string` | `1` | Stretch weight (number) or CSS value (e.g. `'120px'`). |
188
+ | `width` | `number \| string` | `1` | Stretch weight (number) or CSS value (e.g. `'120px'`). A CSS length is also the column's minimum width. |
189
+ | `minWidth` | `string` | `undefined` | Minimum width as a CSS length (e.g. `'12rem'`). When the minimums exceed the container, the table scrolls sideways. |
190
+ | `sticky` | `'left' \| 'right'` | `undefined` | Keep the column in view while the table scrolls sideways. See [Sticky columns](#sticky-columns). |
188
191
  | `sortable` | `boolean` | `true` | Whether clicking the header sorts the table. |
189
192
  | `filterType` | `'value' \| 'list' \| 'daterange' \| 'datetimerange' \| 'none'` | `'value'` | Filter UI for this column. `'list'` is an alias for value-list filters; `'none'` excludes it from `buildColumnFilters`. |
190
193
  | `headerSnippet` | `Snippet<[{key, label, sortKey, sortDir}]>` | `undefined` | Custom Svelte 5 snippet rendered inside `<th>`. |
@@ -262,6 +265,32 @@ Column widths can be specified as:
262
265
  - **Stretch weights** (numbers): Distributed proportionally, e.g., `{ name: 1, description: 3 }`
263
266
  - **Pixel values** (strings): Fixed widths, e.g., `{ id: '80px', name: '200px' }`
264
267
 
268
+ A CSS-length width (or `minWidth`) is a real minimum: when the columns' minimums are
269
+ wider than the container, the table scrolls sideways instead of squeezing them.
270
+
271
+ #### Sticky columns
272
+
273
+ Set `sticky: 'left'` or `sticky: 'right'` on a column to keep it in view while the
274
+ table scrolls sideways — e.g. an identifier and a name on the left, row actions on
275
+ the right:
276
+
277
+ ```js
278
+ const columns = [
279
+ { key: 'id', label: 'ID', width: '80px', sticky: 'left' },
280
+ { key: 'name', label: 'Name', width: '200px', sticky: 'left' },
281
+ // … wide columns …
282
+ { key: 'actions', label: 'Actions', width: '140px', sticky: 'right' },
283
+ ];
284
+ ```
285
+
286
+ - Several columns may stick per side; their offsets are measured, so any width type works.
287
+ - Put left-sticky columns first and right-sticky columns last: a sticky cell only stays
288
+ within its row, so a right-sticky column in the middle still scrolls off to the left.
289
+ - The innermost sticky column of each side casts a soft shadow while columns are
290
+ scrolled under it. The table root carries `data-scrolled-start` / `data-scrolled-end`
291
+ while it is scrolled away from the start / not at the end, for custom styling.
292
+ - Sticky body cells take their row's background (striping, hover, selection).
293
+
265
294
  #### Row Snippet Parameters
266
295
 
267
296
  The `rowSnippet` receives an object with:
@@ -51,6 +51,8 @@
51
51
  // If `virtualize` is false we ask the wrapped VirtualList to render as a normal list/table
52
52
  // by setting its `isDisabled` prop. Default: true (virtualization enabled).
53
53
  virtualize = true,
54
+ // Row density: 'comfortable' (default) or 'compact' (tighter cell padding).
55
+ density = 'comfortable',
54
56
  } = $props();
55
57
 
56
58
  // --- Derived values from ColumnDef[] ---
@@ -66,6 +68,78 @@
66
68
  // Fast lookup map: key → ColumnDef.
67
69
  const colDefMap = $derived(Object.fromEntries(columns.map((c) => [c.key, c])));
68
70
 
71
+ // --- Sticky columns ---
72
+ // Header cell widths of sticky columns, measured (bind:offsetWidth), so the
73
+ // offsets hold whatever the width type (stretch weight or CSS length).
74
+ let stickyWidths = $state({});
75
+
76
+ // key → { side, offset, edge } for columns with `sticky: 'left' | 'right'`.
77
+ // A left column's offset is the width of the left sticky columns before it;
78
+ // a right column's, of the right sticky columns after it. `edge` marks the
79
+ // innermost column of each side, which draws the divider shadow.
80
+ const stickyMap = $derived.by(() => {
81
+ const map = {};
82
+ const left = columns.filter((c) => c.sticky === 'left');
83
+ const right = columns.filter((c) => c.sticky === 'right').reverse();
84
+ let acc = 0;
85
+ left.forEach((c, i) => {
86
+ map[c.key] = { side: 'left', offset: acc, edge: i === left.length - 1 };
87
+ acc += stickyWidths[c.key] ?? 0;
88
+ });
89
+ acc = 0;
90
+ right.forEach((c, i) => {
91
+ map[c.key] = { side: 'right', offset: acc, edge: i === right.length - 1 };
92
+ acc += stickyWidths[c.key] ?? 0;
93
+ });
94
+ return map;
95
+ });
96
+
97
+ function stickyClass(key) {
98
+ const st = stickyMap[key];
99
+ if (!st) return '';
100
+ return `vtable-sticky vtable-sticky-${st.side}${st.edge ? ` vtable-sticky-edge-${st.side}` : ''}`;
101
+ }
102
+
103
+ // A column's minimum width: ColumnDef.minWidth, else a CSS-length width.
104
+ // Set on the header content, it is a real minimum (a <col> width is only a
105
+ // hint under automatic table layout), so wide tables scroll sideways
106
+ // instead of squeezing their columns.
107
+ function minWidthStyle(key) {
108
+ const c = colDefMap[key];
109
+ const w =
110
+ c?.minWidth ??
111
+ (typeof c?.width === 'string' && !c.width.trim().endsWith('%') ? c.width : null);
112
+ return w ? `min-width: ${w};` : '';
113
+ }
114
+
115
+ function stickyStyle(key) {
116
+ const st = stickyMap[key];
117
+ return st ? `${st.side}: ${st.offset}px;` : '';
118
+ }
119
+
120
+ // Horizontal scroll position, so the sticky edges cast a shadow only while
121
+ // columns are scrolled under them.
122
+ let scroller = $state(null);
123
+ let scrolledFromStart = $state(false);
124
+ let scrolledToEnd = $state(true);
125
+
126
+ function updateHorizontalScroll() {
127
+ if (!scroller) return;
128
+ const { scrollLeft, scrollWidth, clientWidth } = scroller;
129
+ scrolledFromStart = scrollLeft > 0;
130
+ scrolledToEnd = scrollLeft + clientWidth >= scrollWidth - 1;
131
+ }
132
+
133
+ $effect(() => {
134
+ if (!scroller || typeof ResizeObserver === 'undefined') return;
135
+ const ro = new ResizeObserver(updateHorizontalScroll);
136
+ ro.observe(scroller);
137
+ const table = scroller.querySelector('table');
138
+ if (table) ro.observe(table);
139
+ updateHorizontalScroll();
140
+ return () => ro.disconnect();
141
+ });
142
+
69
143
  const effectiveColumnFilters = $derived.by(() => {
70
144
  return resolveColumnFilters({
71
145
  columnFilters,
@@ -238,7 +312,14 @@
238
312
 
239
313
  <svelte:window onclick={closeFilter} onkeydown={handleKeydown} />
240
314
 
241
- <section class="virtual-data-table {className}" {style}>
315
+ <section
316
+ class="virtual-data-table {className}"
317
+ {style}
318
+ bind:this={scroller}
319
+ onscroll={updateHorizontalScroll}
320
+ data-scrolled-start={scrolledFromStart ? '' : undefined}
321
+ data-scrolled-end={scrolledToEnd ? undefined : ''}
322
+ >
242
323
  {#if columns.length > 0}
243
324
  <!-- When `virtualize` is false we instruct VirtualList to render as a normal list/table
244
325
  by setting `isDisabled`. This ensures pagination based on item counts shows the
@@ -247,7 +328,9 @@
247
328
  items={Array.isArray(sortedItems) ? sortedItems : []}
248
329
  isTable
249
330
  isDisabled={!virtualize}
250
- class="datatable-table max-w-full max-h-full overflow-auto"
331
+ class="datatable-table max-w-full max-h-full overflow-auto{density === 'compact'
332
+ ? ' compact'
333
+ : ''}"
251
334
  >
252
335
  <!-- colgroup enforces the column widths so table-layout: fixed distributes as intended -->
253
336
  {#snippet header()}
@@ -266,15 +349,18 @@
266
349
  {@const selection = filterDef ? filterState.selections[filterDef.key] : undefined}
267
350
  {@const isFilterActive = hasActiveFilterValue(selection)}
268
351
  <th
269
- style="width: {calcColWidth(key)}"
270
- class="select-none"
352
+ style="width: {calcColWidth(key)}; {stickyStyle(key)}"
353
+ class="select-none {stickyClass(key)}{filterDef && openFilterKey === filterDef.key
354
+ ? ' vtable-filter-open'
355
+ : ''}"
356
+ bind:offsetWidth={stickyWidths[key]}
271
357
  aria-sort={sortKey === key
272
358
  ? sortDir === 'asc'
273
359
  ? 'ascending'
274
360
  : 'descending'
275
361
  : 'none'}
276
362
  >
277
- <div class="vtable-header-content">
363
+ <div class="vtable-header-content" style={minWidthStyle(key) || undefined}>
278
364
  {#if colDef?.headerSnippet}
279
365
  <div class="min-w-0 flex-1">
280
366
  {@render colDef.headerSnippet({ key, label, sortKey, sortDir })}
@@ -329,7 +415,7 @@
329
415
  <!-- Default row rendering using each column's cellSnippet or raw value -->
330
416
  <tr onclick={() => selectItem(item, index)} class={selected === item ? 'selected' : ''}>
331
417
  {#each columns as col}
332
- <td>
418
+ <td class={stickyClass(col.key) || undefined} style={stickyStyle(col.key) || undefined}>
333
419
  {#if col.cellSnippet}
334
420
  {@render col.cellSnippet({ item, value: item[col.key], index })}
335
421
  {:else}
@@ -372,7 +458,6 @@
372
458
  display: table;
373
459
  width: 100%;
374
460
  min-width: 0;
375
- border-collapse: collapse;
376
461
  box-sizing: border-box;
377
462
  font-size: 0.875rem; /* 14px - smaller, more compact */
378
463
  font-family:
@@ -380,12 +465,49 @@
380
465
  line-height: 1.4;
381
466
  border: none;
382
467
  }
383
- /* Sticky header support */
384
- :global(.datatable-table) thead.sticky-header {
468
+ /* Sticky header: each header cell sticks (rather than the <thead>), so a
469
+ cell can also stick horizontally for sticky columns. */
470
+ :global(.datatable-table thead.sticky-header th) {
385
471
  position: sticky;
386
472
  top: 0;
387
473
  z-index: 2;
388
474
  }
475
+ /* separate + 0 spacing looks like collapse here (bottom borders only) but
476
+ keeps each border on its cell, so borders move with sticky cells. Set on
477
+ the inner <table> itself: Tailwind's preflight collapses every table. */
478
+ :global(.datatable-table table.vtlist-inner) {
479
+ border-collapse: separate;
480
+ border-spacing: 0;
481
+ }
482
+ /* Sticky columns (ColumnDef.sticky). Body cells take the row's background
483
+ (striping, hover, selection) so scrolled cells do not show through. The
484
+ <tbody> is rendered by VirtualList, hence fully global. */
485
+ :global(.datatable-table tbody td.vtable-sticky) {
486
+ position: sticky;
487
+ z-index: 1;
488
+ background-color: inherit;
489
+ }
490
+ :global(.datatable-table thead.sticky-header th.vtable-sticky) {
491
+ z-index: 3;
492
+ }
493
+ /* Keep an open header filter above the sticky header cells */
494
+ :global(.datatable-table thead.sticky-header th.vtable-filter-open) {
495
+ z-index: 4;
496
+ }
497
+ /* Divider shadow on the innermost sticky column, only while columns are
498
+ scrolled under it */
499
+ :global(.virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left) {
500
+ box-shadow: 6px 0 6px -4px rgba(15, 23, 42, 0.18);
501
+ }
502
+ :global(.virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
503
+ box-shadow: -6px 0 6px -4px rgba(15, 23, 42, 0.18);
504
+ }
505
+ :global(.dark .virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left) {
506
+ box-shadow: 6px 0 6px -4px rgba(0, 0, 0, 0.6);
507
+ }
508
+ :global(.dark .virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
509
+ box-shadow: -6px 0 6px -4px rgba(0, 0, 0, 0.6);
510
+ }
389
511
  /* Header visual styles - only bottom border */
390
512
  :global(.datatable-table) thead th {
391
513
  background-color: #f8f9fa;
@@ -464,7 +586,7 @@
464
586
  }
465
587
  /* Compact variant */
466
588
  :global(.datatable-table.compact tbody td) {
467
- padding: 0.1rem 0.3rem;
589
+ padding: 0.25rem 0.5rem;
468
590
  }
469
591
  /* Header content alignment helper */
470
592
  :global(.datatable-table thead th > div) {
@@ -472,9 +594,6 @@
472
594
  align-items: center;
473
595
  gap: 0.25rem;
474
596
  }
475
- :global(.datatable-table thead th) {
476
- position: relative;
477
- }
478
597
  :global(.datatable-table thead th .vtable-header-content) {
479
598
  display: flex;
480
599
  align-items: center;
@@ -28,6 +28,7 @@ declare const DataTable: import("svelte").Component<{
28
28
  emitDebounce?: number;
29
29
  relativeRangePresets?: typeof DEFAULT_RELATIVE_RANGE_PRESETS;
30
30
  virtualize?: boolean;
31
+ density?: string;
31
32
  }, {}, "sortKey" | "sortDir">;
32
33
  type $$ComponentProps = {
33
34
  items?: any[];
@@ -54,5 +55,6 @@ type $$ComponentProps = {
54
55
  emitDebounce?: number;
55
56
  relativeRangePresets?: typeof DEFAULT_RELATIVE_RANGE_PRESETS;
56
57
  virtualize?: boolean;
58
+ density?: string;
57
59
  };
58
60
  import { DEFAULT_RELATIVE_RANGE_PRESETS } from '../filterUtils.js';
@@ -193,9 +193,11 @@
193
193
  </script>
194
194
 
195
195
  <div class="w-full">
196
- <div class="flex items-center w-full gap-3 px-0 py-0">
196
+ <!-- Search, range and per-page sit together on the left; pagination is
197
+ pushed to the right and wraps below on narrow widths. -->
198
+ <div class="flex flex-wrap items-center w-full gap-x-3 gap-y-1 px-0 py-0">
197
199
  <!-- Search field on the left -->
198
- <div class="flex-1">
200
+ <div class="min-w-0">
199
201
  <div class="flex items-center gap-2">
200
202
  <!-- Styled button to open/close filters modal -->
201
203
  {#if showFilters}
@@ -242,7 +244,7 @@
242
244
  </div>
243
245
  {/if}
244
246
 
245
- <div class="vtable-search-wrapper relative flex items-center">
247
+ <div class="vtable-search-wrapper relative flex items-center w-64 max-w-full">
246
248
  <svg
247
249
  class="absolute left-3 h-4 w-4 text-gray-400 pointer-events-none"
248
250
  xmlns="http://www.w3.org/2000/svg"
@@ -298,9 +300,9 @@
298
300
  </div>
299
301
 
300
302
  <!-- Range count badge + per-page selector -->
301
- <div class="flex-2 flex items-center gap-2">
303
+ <div class="flex shrink-0 items-center gap-2">
302
304
  <span
303
- class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-200 whitespace-nowrap"
305
+ class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium tabular-nums bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-200 whitespace-nowrap"
304
306
  >
305
307
  Showing {startItem} to {endItem} of {totalItems}
306
308
  </span>
@@ -309,6 +311,7 @@
309
311
  <div class="flex items-center gap-2">
310
312
  <select
311
313
  id={perPageSelectId}
314
+ aria-label="Rows per page"
312
315
  class="vtable-perpage-select py-1 pl-3 pr-7 text-sm rounded-md border border-gray-300 bg-white dark:bg-gray-700 dark:border-gray-600 dark:text-gray-100"
313
316
  bind:value={perPage}
314
317
  >
@@ -320,7 +323,9 @@
320
323
  </div>
321
324
 
322
325
  <!-- Pagination navigation -->
323
- <PaginationBar {pages} {currentPage} onpage={goTo} />
326
+ <div class="ml-auto shrink-0">
327
+ <PaginationBar {pages} {currentPage} onpage={goTo} />
328
+ </div>
324
329
  </div>
325
330
  </div>
326
331
 
@@ -360,7 +365,6 @@
360
365
  display: table;
361
366
  width: 100%;
362
367
  min-width: 0;
363
- border-collapse: collapse;
364
368
  box-sizing: border-box;
365
369
  font-size: 0.875rem; /* 14px - smaller, more compact */
366
370
  font-family:
@@ -368,12 +372,49 @@
368
372
  line-height: 1.4;
369
373
  border: none;
370
374
  }
371
- /* Sticky header support */
372
- :global(.datatable-table) thead.sticky-header {
375
+ /* Sticky header: each header cell sticks (rather than the <thead>), so a
376
+ cell can also stick horizontally for sticky columns. */
377
+ :global(.datatable-table thead.sticky-header th) {
373
378
  position: sticky;
374
379
  top: 0;
375
380
  z-index: 2;
376
381
  }
382
+ /* separate + 0 spacing looks like collapse here (bottom borders only) but
383
+ keeps each border on its cell, so borders move with sticky cells. Set on
384
+ the inner <table> itself: Tailwind's preflight collapses every table. */
385
+ :global(.datatable-table table.vtlist-inner) {
386
+ border-collapse: separate;
387
+ border-spacing: 0;
388
+ }
389
+ /* Sticky columns (ColumnDef.sticky). Body cells take the row's background
390
+ (striping, hover, selection) so scrolled cells do not show through. The
391
+ <tbody> is rendered by VirtualList, hence fully global. */
392
+ :global(.datatable-table tbody td.vtable-sticky) {
393
+ position: sticky;
394
+ z-index: 1;
395
+ background-color: inherit;
396
+ }
397
+ :global(.datatable-table thead.sticky-header th.vtable-sticky) {
398
+ z-index: 3;
399
+ }
400
+ /* Keep an open header filter above the sticky header cells */
401
+ :global(.datatable-table thead.sticky-header th.vtable-filter-open) {
402
+ z-index: 4;
403
+ }
404
+ /* Divider shadow on the innermost sticky column, only while columns are
405
+ scrolled under it */
406
+ :global(.virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left) {
407
+ box-shadow: 6px 0 6px -4px rgba(15, 23, 42, 0.18);
408
+ }
409
+ :global(.virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
410
+ box-shadow: -6px 0 6px -4px rgba(15, 23, 42, 0.18);
411
+ }
412
+ :global(.dark .virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left) {
413
+ box-shadow: 6px 0 6px -4px rgba(0, 0, 0, 0.6);
414
+ }
415
+ :global(.dark .virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
416
+ box-shadow: -6px 0 6px -4px rgba(0, 0, 0, 0.6);
417
+ }
377
418
  /* Header visual styles - only bottom border */
378
419
  :global(.datatable-table) thead th {
379
420
  background-color: #f8f9fa;
@@ -452,7 +493,7 @@
452
493
  }
453
494
  /* Compact variant */
454
495
  :global(.datatable-table.compact tbody td) {
455
- padding: 0.1rem 0.3rem;
496
+ padding: 0.25rem 0.5rem;
456
497
  }
457
498
  /* Header content alignment helper */
458
499
  :global(.datatable-table thead th > div) {
@@ -460,9 +501,6 @@
460
501
  align-items: center;
461
502
  gap: 0.25rem;
462
503
  }
463
- :global(.datatable-table thead th) {
464
- position: relative;
465
- }
466
504
  :global(.datatable-table thead th .vtable-header-content) {
467
505
  display: flex;
468
506
  align-items: center;
@@ -311,7 +311,6 @@
311
311
  display: table;
312
312
  width: 100%;
313
313
  min-width: 0;
314
- border-collapse: collapse;
315
314
  box-sizing: border-box;
316
315
  font-size: 0.875rem; /* 14px - smaller, more compact */
317
316
  font-family:
@@ -319,12 +318,49 @@
319
318
  line-height: 1.4;
320
319
  border: none;
321
320
  }
322
- /* Sticky header support */
323
- :global(.datatable-table) thead.sticky-header {
321
+ /* Sticky header: each header cell sticks (rather than the <thead>), so a
322
+ cell can also stick horizontally for sticky columns. */
323
+ :global(.datatable-table thead.sticky-header th) {
324
324
  position: sticky;
325
325
  top: 0;
326
326
  z-index: 2;
327
327
  }
328
+ /* separate + 0 spacing looks like collapse here (bottom borders only) but
329
+ keeps each border on its cell, so borders move with sticky cells. Set on
330
+ the inner <table> itself: Tailwind's preflight collapses every table. */
331
+ :global(.datatable-table table.vtlist-inner) {
332
+ border-collapse: separate;
333
+ border-spacing: 0;
334
+ }
335
+ /* Sticky columns (ColumnDef.sticky). Body cells take the row's background
336
+ (striping, hover, selection) so scrolled cells do not show through. The
337
+ <tbody> is rendered by VirtualList, hence fully global. */
338
+ :global(.datatable-table tbody td.vtable-sticky) {
339
+ position: sticky;
340
+ z-index: 1;
341
+ background-color: inherit;
342
+ }
343
+ :global(.datatable-table thead.sticky-header th.vtable-sticky) {
344
+ z-index: 3;
345
+ }
346
+ /* Keep an open header filter above the sticky header cells */
347
+ :global(.datatable-table thead.sticky-header th.vtable-filter-open) {
348
+ z-index: 4;
349
+ }
350
+ /* Divider shadow on the innermost sticky column, only while columns are
351
+ scrolled under it */
352
+ :global(.virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left) {
353
+ box-shadow: 6px 0 6px -4px rgba(15, 23, 42, 0.18);
354
+ }
355
+ :global(.virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
356
+ box-shadow: -6px 0 6px -4px rgba(15, 23, 42, 0.18);
357
+ }
358
+ :global(.dark .virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left) {
359
+ box-shadow: 6px 0 6px -4px rgba(0, 0, 0, 0.6);
360
+ }
361
+ :global(.dark .virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
362
+ box-shadow: -6px 0 6px -4px rgba(0, 0, 0, 0.6);
363
+ }
328
364
  /* Header visual styles - only bottom border */
329
365
  :global(.datatable-table) thead th {
330
366
  background-color: #f8f9fa;
@@ -403,7 +439,7 @@
403
439
  }
404
440
  /* Compact variant */
405
441
  :global(.datatable-table.compact tbody td) {
406
- padding: 0.1rem 0.3rem;
442
+ padding: 0.25rem 0.5rem;
407
443
  }
408
444
  /* Header content alignment helper */
409
445
  :global(.datatable-table thead th > div) {
@@ -411,9 +447,6 @@
411
447
  align-items: center;
412
448
  gap: 0.25rem;
413
449
  }
414
- :global(.datatable-table thead th) {
415
- position: relative;
416
- }
417
450
  :global(.datatable-table thead th .vtable-header-content) {
418
451
  display: flex;
419
452
  align-items: center;
package/dist/index.d.ts CHANGED
@@ -25,6 +25,18 @@ export type ColumnDef<T extends Record<string, unknown> = Record<string, unknown
25
25
  * CSS width value such as `'120px'`. Defaults to `1` (equal stretch).
26
26
  */
27
27
  width?: number | string;
28
+ /**
29
+ * - Minimum column width as a CSS length (e.g. `'12rem'`).
30
+ * A CSS-length `width` is also a minimum. When the minimums exceed the
31
+ * container, the table scrolls sideways instead of squeezing its columns.
32
+ */
33
+ minWidth?: string;
34
+ /**
35
+ * - Keep the column in view while the table
36
+ * scrolls sideways, pinned to that edge. Several columns may stick per side;
37
+ * offsets are measured, so any width type works.
38
+ */
39
+ sticky?: "left" | "right";
28
40
  /**
29
41
  * - Whether clicking the column header sorts the
30
42
  * table. Defaults to `true`.
package/dist/index.js CHANGED
@@ -40,6 +40,12 @@ export {
40
40
  * @property {string} [label] - Display label for the column header. Defaults to `key`.
41
41
  * @property {number|string} [width] - Column width: a stretch weight (number) or a
42
42
  * CSS width value such as `'120px'`. Defaults to `1` (equal stretch).
43
+ * @property {string} [minWidth] - Minimum column width as a CSS length (e.g. `'12rem'`).
44
+ * A CSS-length `width` is also a minimum. When the minimums exceed the
45
+ * container, the table scrolls sideways instead of squeezing its columns.
46
+ * @property {'left'|'right'} [sticky] - Keep the column in view while the table
47
+ * scrolls sideways, pinned to that edge. Several columns may stick per side;
48
+ * offsets are measured, so any width type works.
43
49
  * @property {boolean} [sortable] - Whether clicking the column header sorts the
44
50
  * table. Defaults to `true`.
45
51
  * @property {'value'|'list'|'daterange'|'datetimerange'|'none'} [filterType]
package/dist/styles.css CHANGED
@@ -24,7 +24,6 @@
24
24
  display: table;
25
25
  width: 100%;
26
26
  min-width: 0;
27
- border-collapse: collapse;
28
27
  box-sizing: border-box;
29
28
  font-size: 0.875rem; /* 14px - smaller, more compact */
30
29
  font-family:
@@ -33,13 +32,58 @@
33
32
  border: none;
34
33
  }
35
34
 
36
- /* Sticky header support */
37
- :global(.datatable-table) thead.sticky-header {
35
+ /* Sticky header: each header cell sticks (rather than the <thead>), so a
36
+ cell can also stick horizontally for sticky columns. */
37
+ :global(.datatable-table thead.sticky-header th) {
38
38
  position: sticky;
39
39
  top: 0;
40
40
  z-index: 2;
41
41
  }
42
42
 
43
+ /* separate + 0 spacing looks like collapse here (bottom borders only) but
44
+ keeps each border on its cell, so borders move with sticky cells. Set on
45
+ the inner <table> itself: Tailwind's preflight collapses every table. */
46
+ :global(.datatable-table table.vtlist-inner) {
47
+ border-collapse: separate;
48
+ border-spacing: 0;
49
+ }
50
+
51
+ /* Sticky columns (ColumnDef.sticky). Body cells take the row's background
52
+ (striping, hover, selection) so scrolled cells do not show through. The
53
+ <tbody> is rendered by VirtualList, hence fully global. */
54
+ :global(.datatable-table tbody td.vtable-sticky) {
55
+ position: sticky;
56
+ z-index: 1;
57
+ background-color: inherit;
58
+ }
59
+
60
+ :global(.datatable-table thead.sticky-header th.vtable-sticky) {
61
+ z-index: 3;
62
+ }
63
+
64
+ /* Keep an open header filter above the sticky header cells */
65
+ :global(.datatable-table thead.sticky-header th.vtable-filter-open) {
66
+ z-index: 4;
67
+ }
68
+
69
+ /* Divider shadow on the innermost sticky column, only while columns are
70
+ scrolled under it */
71
+ :global(.virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left) {
72
+ box-shadow: 6px 0 6px -4px rgba(15, 23, 42, 0.18);
73
+ }
74
+
75
+ :global(.virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
76
+ box-shadow: -6px 0 6px -4px rgba(15, 23, 42, 0.18);
77
+ }
78
+
79
+ :global(.dark .virtual-data-table[data-scrolled-start] .vtable-sticky-edge-left) {
80
+ box-shadow: 6px 0 6px -4px rgba(0, 0, 0, 0.6);
81
+ }
82
+
83
+ :global(.dark .virtual-data-table[data-scrolled-end] .vtable-sticky-edge-right) {
84
+ box-shadow: -6px 0 6px -4px rgba(0, 0, 0, 0.6);
85
+ }
86
+
43
87
  /* Header visual styles - only bottom border */
44
88
  :global(.datatable-table) thead th {
45
89
  background-color: #f8f9fa;
@@ -129,7 +173,7 @@
129
173
 
130
174
  /* Compact variant */
131
175
  :global(.datatable-table.compact tbody td) {
132
- padding: 0.1rem 0.3rem;
176
+ padding: 0.25rem 0.5rem;
133
177
  }
134
178
 
135
179
  /* Header content alignment helper */
@@ -139,10 +183,6 @@
139
183
  gap: 0.25rem;
140
184
  }
141
185
 
142
- :global(.datatable-table thead th) {
143
- position: relative;
144
- }
145
-
146
186
  :global(.datatable-table thead th .vtable-header-content) {
147
187
  display: flex;
148
188
  align-items: center;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhangt58/svelte-vtable",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "A Svelte 5 library for virtualized data tables with sorting, selection, and pagination controls.",
5
5
  "type": "module",
6
6
  "sideEffects": [