@svgrid/grid 2.2.31 → 2.2.32

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.
Files changed (145) hide show
  1. package/README.md +1 -1
  2. package/dist/SvAvatar.svelte +1 -1
  3. package/dist/SvCheckBox.svelte +2 -1
  4. package/dist/SvCircularProgress.svelte +1 -1
  5. package/dist/SvGrid.controller.svelte.d.ts +20 -0
  6. package/dist/SvGrid.controller.svelte.js +358 -18
  7. package/dist/SvGrid.css +103 -3
  8. package/dist/SvGrid.svelte +162 -10
  9. package/dist/SvGrid.types.d.ts +81 -0
  10. package/dist/SvGridDropdown.svelte +38 -6
  11. package/dist/SvGridDropdown.svelte.d.ts +4 -0
  12. package/dist/SvGridSelect.svelte +12 -3
  13. package/dist/SvGridSelect.svelte.d.ts +6 -0
  14. package/dist/SvGroupCell.svelte +9 -2
  15. package/dist/SvMultiSelect.svelte +12 -3
  16. package/dist/SvMultiSelect.svelte.d.ts +6 -0
  17. package/dist/SvPasswordInput.svelte +1 -1
  18. package/dist/SvProgress.svelte +1 -1
  19. package/dist/SvRating.svelte +1 -1
  20. package/dist/SvResult.svelte +1 -1
  21. package/dist/SvRichText.svelte +31 -16
  22. package/dist/SvRichText.svelte.d.ts +9 -0
  23. package/dist/SvSwitchButton.svelte +2 -1
  24. package/dist/SvToaster.svelte +1 -1
  25. package/dist/SvTree.svelte +9 -2
  26. package/dist/SvTree.svelte.d.ts +5 -0
  27. package/dist/SvTreeSelect.svelte +6 -2
  28. package/dist/build-api.js +16 -0
  29. package/dist/cdn/{GridMenus-Ds3OpzZT.js → GridMenus-C6ixSGWW.js} +33 -33
  30. package/dist/cdn/{GridMenus-Da_p7SKS.js → GridMenus-Cyk3qpJ7.js} +33 -33
  31. package/dist/cdn/{SvDateTimePicker-B8GopjhC.js → SvDateTimePicker-CdqaP61H.js} +2 -1
  32. package/dist/cdn/{SvDateTimePicker-DB0aIEk8.js → SvDateTimePicker-ClqtVIj3.js} +2 -1
  33. package/dist/cdn/{SvGridDropdown-DjALc_4f.js → SvGridDropdown-D0VdjeR8.js} +129 -123
  34. package/dist/cdn/{SvGridDropdown-hpnHvOGt.js → SvGridDropdown-Dh-2ej8j.js} +92 -87
  35. package/dist/cdn/{src-BLJfdyL0.js → src-BgHjWF0Q.js} +4193 -3837
  36. package/dist/cdn/{src-DYDCiC0D.js → src-CgD-wiuS.js} +5956 -5602
  37. package/dist/cdn/svgrid.js +8 -8
  38. package/dist/cdn/svgrid.svelte-external.js +8 -8
  39. package/dist/cell-render.d.ts +1 -0
  40. package/dist/cell-render.js +115 -1
  41. package/dist/cell-values.js +5 -0
  42. package/dist/core.d.ts +80 -9
  43. package/dist/core.js +89 -0
  44. package/dist/editor-contract.d.ts +12 -5
  45. package/dist/editor-registry.d.ts +18 -7
  46. package/dist/editor-registry.js +10 -1
  47. package/dist/group-display.d.ts +39 -0
  48. package/dist/group-display.js +52 -0
  49. package/dist/index.d.ts +2 -2
  50. package/dist/index.js +2 -2
  51. package/dist/keyboard-handlers.js +16 -0
  52. package/dist/recurrence.js +3 -2
  53. package/dist/svgrid-wrapper.types.d.ts +8 -2
  54. package/dist/themes/index.d.ts +10 -0
  55. package/dist/themes/index.js +26 -0
  56. package/package.json +1 -1
  57. package/src/SvAccordion.test.ts +5 -5
  58. package/src/SvAvatar.svelte +1 -1
  59. package/src/SvButtonGroup.test.ts +6 -6
  60. package/src/SvCheckBox.svelte +2 -1
  61. package/src/SvCircularProgress.svelte +1 -1
  62. package/src/SvFileUpload.test.ts +1 -1
  63. package/src/SvGrid.controller.svelte.ts +367 -17
  64. package/src/SvGrid.css +103 -3
  65. package/src/SvGrid.svelte +162 -10
  66. package/src/SvGrid.types.ts +81 -0
  67. package/src/SvGridDropdown.svelte +38 -6
  68. package/src/SvGridSelect.svelte +12 -3
  69. package/src/SvGroupCell.svelte +9 -2
  70. package/src/SvMultiSelect.svelte +12 -3
  71. package/src/SvPasswordInput.svelte +1 -1
  72. package/src/SvProgress.svelte +1 -1
  73. package/src/SvRating.svelte +1 -1
  74. package/src/SvResult.svelte +1 -1
  75. package/src/SvRichText.svelte +31 -16
  76. package/src/SvSwitchButton.svelte +2 -1
  77. package/src/SvToaster.svelte +1 -1
  78. package/src/SvTree.svelte +9 -2
  79. package/src/SvTreeSelect.svelte +6 -2
  80. package/src/build-api.ts +15 -0
  81. package/src/builtin-editors.test.ts +3 -1
  82. package/src/cell-render.test.ts +27 -3
  83. package/src/cell-render.ts +122 -1
  84. package/src/cell-values.ts +4 -0
  85. package/src/chart-export.test.ts +2 -2
  86. package/src/clipboard.test.ts +0 -2
  87. package/src/core.ts +157 -8
  88. package/src/editing.test.ts +1 -1
  89. package/src/editor-contract.ts +12 -5
  90. package/src/editor-registry.grid.test.ts +48 -0
  91. package/src/editor-registry.test.ts +3 -1
  92. package/src/editor-registry.ts +23 -7
  93. package/src/facet-buckets.test.ts +33 -33
  94. package/src/group-display.test.ts +91 -1
  95. package/src/group-display.ts +83 -0
  96. package/src/index.ts +9 -0
  97. package/src/keyboard-handlers.ts +17 -0
  98. package/src/list-power.test.ts +2 -2
  99. package/src/menus.test.ts +4 -4
  100. package/src/named-views.coverage.test.ts +3 -3
  101. package/src/recurrence.ts +3 -2
  102. package/src/row-resize.test.ts +40 -40
  103. package/src/scheduler-model.ts +1 -1
  104. package/src/server-data-source.coverage.test.ts +1 -1
  105. package/src/server-group-model.test.ts +6 -6
  106. package/src/spreadsheet.test.ts +0 -1
  107. package/src/svgrid-wrapper.types.ts +11 -9
  108. package/src/svgrid.async-editor-options.test.ts +271 -0
  109. package/src/svgrid.auto-row-height.test.ts +204 -0
  110. package/src/svgrid.charting.test.ts +4 -4
  111. package/src/svgrid.comments-autocomplete.test.ts +8 -2
  112. package/src/svgrid.context-menu.test.ts +25 -9
  113. package/src/svgrid.filter-depth.test.ts +163 -0
  114. package/src/svgrid.filter-menu-listbox.svelte.test.ts +16 -2
  115. package/src/svgrid.filter-menu-scroll.test.ts +10 -2
  116. package/src/svgrid.grand-total.test.ts +188 -0
  117. package/src/svgrid.group-display-mode.test.ts +171 -0
  118. package/src/svgrid.group-footers.test.ts +121 -0
  119. package/src/svgrid.group-pagination.test.ts +153 -0
  120. package/src/svgrid.tree-data.test.ts +186 -0
  121. package/src/svgriddropdown.async-panel.svelte.test.ts +195 -0
  122. package/src/themes/index.ts +42 -0
  123. package/src/tree-edit.test.ts +4 -4
  124. package/src/tree-row-model.test.ts +169 -0
  125. package/src/ui-localization.test.ts +113 -0
  126. package/themes/ag-alpine.css +22 -0
  127. package/themes/antd.css +22 -0
  128. package/themes/atlassian.css +22 -0
  129. package/themes/bootstrap.css +22 -0
  130. package/themes/carbon.css +22 -0
  131. package/themes/catppuccin.css +22 -0
  132. package/themes/dracula.css +22 -0
  133. package/themes/ember.css +22 -0
  134. package/themes/excel.css +22 -0
  135. package/themes/fluent.css +22 -0
  136. package/themes/github.css +22 -0
  137. package/themes/linear.css +22 -0
  138. package/themes/material.css +22 -0
  139. package/themes/nord.css +22 -0
  140. package/themes/notion.css +22 -0
  141. package/themes/salesforce.css +22 -0
  142. package/themes/sap.css +22 -0
  143. package/themes/shadcn.css +22 -0
  144. package/themes/tailwind.css +22 -0
  145. package/themes/vercel.css +22 -0
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Filtering depth, verified rather than assumed (#11, #12).
3
+ *
4
+ * Both of these were still listed as roadmap gaps. They are not: the filter row
5
+ * renders a per-column operator picker, and a column filter carries an optional
6
+ * second condition joined by AND/OR. These tests pin the behaviour so the claim
7
+ * is backed by something executable.
8
+ */
9
+ import { afterEach, describe, expect, it } from 'vitest'
10
+ import { mount, unmount } from 'svelte'
11
+ import SvGrid from './SvGrid.svelte'
12
+ import {
13
+ applyExcelFilter,
14
+ createCoreRowModel,
15
+ createFilteredRowModel,
16
+ createPaginatedRowModel,
17
+ createSortedRowModel,
18
+ sortFns,
19
+ tableFeatures,
20
+ rowSortingFeature,
21
+ columnFilteringFeature,
22
+ } from './index'
23
+
24
+ type Row = { id: number; name: string; amount: number }
25
+
26
+ const data: Row[] = [
27
+ { id: 1, name: 'alpha', amount: 5 },
28
+ { id: 2, name: 'beta', amount: 50 },
29
+ { id: 3, name: 'gamma', amount: 500 },
30
+ ]
31
+
32
+ const columns = [
33
+ { field: 'name', header: 'Name', width: 160 },
34
+ { field: 'amount', header: 'Amount', width: 120 },
35
+ ]
36
+
37
+ const features = tableFeatures({ rowSortingFeature, columnFilteringFeature })
38
+ const tick = () => new Promise<void>((r) => queueMicrotask(r))
39
+
40
+ function mountGrid() {
41
+ const target = document.createElement('div')
42
+ document.body.appendChild(target)
43
+ let api: never = null as never
44
+ const app = mount(SvGrid, {
45
+ target,
46
+ props: {
47
+ data,
48
+ columns,
49
+ features,
50
+ filterable: true,
51
+ showFilterRow: true,
52
+ onApiReady: (a: never) => { api = a },
53
+ _rowModels: {
54
+ coreRowModel: createCoreRowModel(),
55
+ filteredRowModel: createFilteredRowModel(),
56
+ sortedRowModel: createSortedRowModel(sortFns),
57
+ paginatedRowModel: createPaginatedRowModel(),
58
+ },
59
+ containerHeight: 400,
60
+ virtualization: false,
61
+ } as never,
62
+ })
63
+ return { target, getApi: () => api, destroy: () => { unmount(app); target.remove() } }
64
+ }
65
+
66
+ let cleanup: (() => void) | null = null
67
+ afterEach(() => { cleanup?.(); cleanup = null })
68
+
69
+ const bodyRows = (t: HTMLElement) =>
70
+ [...t.querySelectorAll('tbody tr.sv-grid-row')].filter(
71
+ (r) => !r.classList.contains('sv-grid-row-spacer'),
72
+ )
73
+
74
+ describe('filter row operator picker (#11)', () => {
75
+ it('renders an operator button per column in the filter row', async () => {
76
+ const { target, destroy } = mountGrid()
77
+ cleanup = destroy
78
+ await tick()
79
+ const btns = target.querySelectorAll('.sv-grid-filter-operator-btn')
80
+ expect(btns.length).toBe(columns.length)
81
+ })
82
+
83
+ it('exposes the active operator on the button for a screen reader', async () => {
84
+ const { target, destroy } = mountGrid()
85
+ cleanup = destroy
86
+ await tick()
87
+ const btn = target.querySelector('.sv-grid-filter-operator-btn')!
88
+ expect(btn.getAttribute('aria-label')).toMatch(/^Filter condition: /)
89
+ })
90
+
91
+ it('opens a menu of the operators valid for that column', async () => {
92
+ const { target, destroy } = mountGrid()
93
+ cleanup = destroy
94
+ await tick()
95
+ target.querySelector<HTMLButtonElement>('.sv-grid-filter-operator-btn')!.click()
96
+ await tick()
97
+ expect(target.querySelector('.sv-grid-filter-operator-btn.is-open')).not.toBeNull()
98
+ })
99
+ })
100
+
101
+ describe('two-condition column filter (#12)', () => {
102
+ // The model is what decides rows; these assert the AND/OR semantics directly.
103
+ const between = (v: unknown, lo: number, hi: number) =>
104
+ applyExcelFilter(v, { id: 'amount', operator: 'greaterThan', value: lo }) &&
105
+ applyExcelFilter(v, { id: 'amount', operator: 'lessThan', value: hi })
106
+
107
+ it('AND narrows to the intersection', () => {
108
+ expect(between(50, 10, 100)).toBe(true)
109
+ expect(between(5, 10, 100)).toBe(false)
110
+ expect(between(500, 10, 100)).toBe(false)
111
+ })
112
+
113
+ it('OR widens to the union', () => {
114
+ const or = (v: unknown) =>
115
+ applyExcelFilter(v, { id: 'name', operator: 'startsWith', value: 'al' }) ||
116
+ applyExcelFilter(v, { id: 'name', operator: 'endsWith', value: 'ma' })
117
+ expect(or('alpha')).toBe(true)
118
+ expect(or('gamma')).toBe(true)
119
+ expect(or('beta')).toBe(false)
120
+ })
121
+
122
+ it('applies a two-condition AND filter through the api', async () => {
123
+ const g = mountGrid()
124
+ cleanup = g.destroy
125
+ await tick()
126
+ const api = g.getApi() as never as {
127
+ setFilter: (id: string, f: Record<string, unknown>) => void
128
+ }
129
+ // amount > 10 AND amount < 100 -> only beta (50)
130
+ api.setFilter('amount', {
131
+ operator: 'greaterThan',
132
+ value: '10',
133
+ operator2: 'lessThan',
134
+ value2: '100',
135
+ join: 'AND',
136
+ })
137
+ await tick()
138
+ expect(bodyRows(g.target)).toHaveLength(1)
139
+ expect(g.target.textContent).toContain('beta')
140
+ })
141
+
142
+ it('applies a two-condition OR filter through the api', async () => {
143
+ const g = mountGrid()
144
+ cleanup = g.destroy
145
+ await tick()
146
+ const api = g.getApi() as never as {
147
+ setFilter: (id: string, f: Record<string, unknown>) => void
148
+ }
149
+ // name startsWith "al" OR name endsWith "ma" -> alpha + gamma
150
+ api.setFilter('name', {
151
+ operator: 'startsWith',
152
+ value: 'al',
153
+ operator2: 'endsWith',
154
+ value2: 'ma',
155
+ join: 'OR',
156
+ })
157
+ await tick()
158
+ expect(bodyRows(g.target)).toHaveLength(2)
159
+ expect(g.target.textContent).toContain('alpha')
160
+ expect(g.target.textContent).toContain('gamma')
161
+ expect(g.target.textContent).not.toContain('beta')
162
+ })
163
+ })
@@ -82,8 +82,22 @@ function mountGrid(data: Row[]) {
82
82
  async function openFilterMenu(target: HTMLElement) {
83
83
  const btn = target.querySelector('.sv-grid-col-filter-btn') as HTMLButtonElement
84
84
  btn.click()
85
- // GridMenus is a lazy chunk; poll until the popover mounts.
86
- await vi.waitFor(() => expect(target.querySelector('.sv-grid-filter-menu')).not.toBeNull())
85
+ // GridMenus is a lazy chunk, so poll until the popover mounts AND its value
86
+ // checklist has rendered.
87
+ //
88
+ // Waiting only for the popover element returns while the listbox is still
89
+ // empty: the chunk arrives, the menu element appears, and the values are
90
+ // snapshotted and windowed in a later flush. Callers then read option counts
91
+ // from a list that has not populated yet. It survives locally because those
92
+ // flushes land in the same task, but under parallel load the gap widens - it
93
+ // failed once that way in a full-suite run. Every caller here opens a menu on
94
+ // a column that has values, so a populated list is the settled state to wait
95
+ // for, and each test's own assertions are unchanged.
96
+ await vi.waitFor(() => {
97
+ const menu = target.querySelector('.sv-grid-filter-menu')
98
+ expect(menu).not.toBeNull()
99
+ expect(menu!.querySelectorAll('[role="option"]').length).toBeGreaterThan(0)
100
+ })
87
101
  return target.querySelector('.sv-grid-filter-menu') as HTMLElement
88
102
  }
89
103
 
@@ -64,8 +64,16 @@ async function openFilterMenu(target: HTMLElement) {
64
64
  const btn = target.querySelector('.sv-grid-col-filter-btn') as HTMLButtonElement
65
65
  expect(btn).not.toBeNull()
66
66
  btn.click()
67
- // GridMenus is a lazy chunk; poll until the popover mounts.
68
- await vi.waitFor(() => expect(target.querySelector('.sv-grid-filter-menu')).not.toBeNull())
67
+ // GridMenus is a lazy chunk, so poll until the popover mounts AND its value
68
+ // checklist is in the DOM. Waiting only for the popover element returns while
69
+ // the menu body is still filling in, so a caller that reaches for
70
+ // `.sv-listbox` can get null - which is how this file flaked under
71
+ // full-suite parallel load.
72
+ await vi.waitFor(() => {
73
+ const menu = target.querySelector('.sv-grid-filter-menu')
74
+ expect(menu).not.toBeNull()
75
+ expect(menu!.querySelector('.sv-listbox')).not.toBeNull()
76
+ })
69
77
  return target.querySelector('.sv-grid-filter-menu') as HTMLElement
70
78
  }
71
79
 
@@ -0,0 +1,188 @@
1
+ /**
2
+ * DOM: `grandTotalRow` appends one totals row for the whole filtered set.
3
+ *
4
+ * It is shaped like a group footer (so totals render under their own columns
5
+ * through the normal cell path) but closes the dataset rather than a group:
6
+ * it must appear exactly once, last, on the LAST page only, aggregate the
7
+ * LEAF rows (not the group banners, which already carry subtotals and would
8
+ * otherwise be counted twice), and follow the filtered set rather than the
9
+ * raw data.
10
+ */
11
+ import { afterEach, describe, expect, it } from 'vitest'
12
+ import { mount, unmount } from 'svelte'
13
+ import SvGrid from './SvGrid.svelte'
14
+ import {
15
+ createCoreRowModel,
16
+ createExpandedRowModel,
17
+ createFilteredRowModel,
18
+ createGroupedRowModel,
19
+ createPaginatedRowModel,
20
+ createSortedRowModel,
21
+ sortFns,
22
+ tableFeatures,
23
+ rowSortingFeature,
24
+ columnGroupingFeature,
25
+ } from './index'
26
+
27
+ type Row = { id: number; region: string; amount: number }
28
+
29
+ const data: Row[] = [
30
+ { id: 1, region: 'East', amount: 10 },
31
+ { id: 2, region: 'East', amount: 5 },
32
+ { id: 3, region: 'West', amount: 7 },
33
+ ]
34
+
35
+ const columns = [
36
+ { field: 'region', header: 'Region', width: 120 },
37
+ { field: 'amount', header: 'Amount', width: 100, aggregate: 'sum' },
38
+ ]
39
+
40
+ const features = tableFeatures({ rowSortingFeature, columnGroupingFeature })
41
+ const tick = () => new Promise<void>((r) => queueMicrotask(r))
42
+
43
+ type Api = {
44
+ setGroupBy: (ids: string[]) => void
45
+ nextPage: () => void
46
+ setState: (s: Record<string, unknown>) => void
47
+ }
48
+
49
+ function mountGrid(props: Record<string, unknown>) {
50
+ const target = document.createElement('div')
51
+ document.body.appendChild(target)
52
+ let api: Api | null = null
53
+ const app = mount(SvGrid, {
54
+ target,
55
+ props: {
56
+ data,
57
+ columns,
58
+ features,
59
+ groupable: true,
60
+ onApiReady: (a: never) => { api = a as never },
61
+ _rowModels: {
62
+ coreRowModel: createCoreRowModel(),
63
+ filteredRowModel: createFilteredRowModel(),
64
+ sortedRowModel: createSortedRowModel(sortFns),
65
+ groupedRowModel: createGroupedRowModel(),
66
+ expandedRowModel: createExpandedRowModel(),
67
+ paginatedRowModel: createPaginatedRowModel(),
68
+ },
69
+ containerHeight: 600,
70
+ virtualization: false,
71
+ ...props,
72
+ } as never,
73
+ })
74
+ return {
75
+ target,
76
+ api: () => api,
77
+ ready: async () => { await tick() },
78
+ group: async () => {
79
+ await tick()
80
+ api?.setGroupBy(['region'])
81
+ await tick()
82
+ for (const btn of target.querySelectorAll<HTMLButtonElement>('.sv-grid-group-toggle')) {
83
+ if (btn.getAttribute('aria-expanded') !== 'true') btn.click()
84
+ }
85
+ await tick()
86
+ },
87
+ destroy: () => { unmount(app); target.remove() },
88
+ }
89
+ }
90
+
91
+ let cleanup: (() => void) | null = null
92
+ afterEach(() => { cleanup?.(); cleanup = null })
93
+
94
+ const totals = (t: HTMLElement) => [...t.querySelectorAll('tr.sv-grid-grand-total-row')]
95
+
96
+ describe('grandTotalRow', () => {
97
+ it('renders nothing when off', async () => {
98
+ const g = mountGrid({})
99
+ cleanup = g.destroy
100
+ await g.ready()
101
+ expect(totals(g.target)).toHaveLength(0)
102
+ })
103
+
104
+ it('appends exactly one total row on a flat (ungrouped) grid', async () => {
105
+ const g = mountGrid({ grandTotalRow: true })
106
+ cleanup = g.destroy
107
+ await g.ready()
108
+ const rows = totals(g.target)
109
+ expect(rows).toHaveLength(1)
110
+ // 10 + 5 + 7
111
+ expect(rows[0]?.textContent).toContain('22')
112
+ })
113
+
114
+ it('is the last row in the body', async () => {
115
+ const g = mountGrid({ grandTotalRow: true })
116
+ cleanup = g.destroy
117
+ await g.ready()
118
+ const bodyRows = [...g.target.querySelectorAll('tbody tr')]
119
+ expect(bodyRows.at(-1)?.classList.contains('sv-grid-grand-total-row')).toBe(true)
120
+ })
121
+
122
+ it('counts leaf rows once when grouping is on (banners are not double-counted)', async () => {
123
+ const g = mountGrid({ grandTotalRow: true })
124
+ cleanup = g.destroy
125
+ await g.group()
126
+ const rows = totals(g.target)
127
+ expect(rows).toHaveLength(1)
128
+ // Still 22, not 44 - the East(15)/West(7) banners must not be summed too.
129
+ expect(rows[0]?.textContent).toContain('22')
130
+ expect(rows[0]?.textContent).not.toContain('44')
131
+ })
132
+
133
+ it('coexists with group footers without becoming one of them', async () => {
134
+ const g = mountGrid({ grandTotalRow: true, groupFooters: true })
135
+ cleanup = g.destroy
136
+ await g.group()
137
+ // Two group subtotals + one grand total, and the grand total is last.
138
+ expect(g.target.querySelectorAll('tr.sv-grid-group-footer-row')).toHaveLength(3)
139
+ expect(totals(g.target)).toHaveLength(1)
140
+ const bodyRows = [...g.target.querySelectorAll('tbody tr')]
141
+ expect(bodyRows.at(-1)?.classList.contains('sv-grid-grand-total-row')).toBe(true)
142
+ })
143
+
144
+ it('is not an expandable banner', async () => {
145
+ const g = mountGrid({ grandTotalRow: true })
146
+ cleanup = g.destroy
147
+ await g.ready()
148
+ const row = totals(g.target)[0]!
149
+ expect(row.classList.contains('sv-grid-group-row')).toBe(false)
150
+ expect(row.querySelector('.sv-grid-group-toggle')).toBeNull()
151
+ })
152
+
153
+ it('appears only on the last page when paginating', async () => {
154
+ // pageSize 2 over 3 rows: page 0 has no total, page 1 (the last) has it.
155
+ const g = mountGrid({ grandTotalRow: true, pageable: true, pageSize: 2 })
156
+ cleanup = g.destroy
157
+ await g.ready()
158
+ expect(totals(g.target)).toHaveLength(0)
159
+ g.api()?.nextPage()
160
+ await tick()
161
+ expect(totals(g.target)).toHaveLength(1)
162
+ // The total is over the whole set (22), not just the last page's row.
163
+ expect(totals(g.target)[0]?.textContent).toContain('22')
164
+ })
165
+
166
+ it('totals the FILTERED set, not the raw data', async () => {
167
+ const g = mountGrid({ grandTotalRow: true })
168
+ cleanup = g.destroy
169
+ await g.ready()
170
+ g.api()?.setState({ globalFilter: 'East' })
171
+ await tick()
172
+ // East only: 10 + 5 = 15.
173
+ expect(totals(g.target)[0]?.textContent).toContain('15')
174
+ })
175
+
176
+ it('renders no total row when no column declares an aggregate', async () => {
177
+ const g = mountGrid({
178
+ grandTotalRow: true,
179
+ columns: [
180
+ { field: 'region', header: 'Region', width: 120 },
181
+ { field: 'amount', header: 'Amount', width: 100 },
182
+ ],
183
+ })
184
+ cleanup = g.destroy
185
+ await g.ready()
186
+ expect(totals(g.target)).toHaveLength(0)
187
+ })
188
+ })
@@ -0,0 +1,171 @@
1
+ /**
2
+ * DOM: `groupDisplayMode` renders group state in COLUMNS instead of banners.
3
+ *
4
+ * `groupRows` (the default) draws a full-width banner per group. The two column
5
+ * modes fold that state into synthetic auto-group columns and let the group row
6
+ * render as an ordinary row - which is the point: its aggregate cells then line
7
+ * up under the real columns instead of sitting in a full-width strip.
8
+ *
9
+ * The grouped SOURCE columns are hidden in those modes, since their values have
10
+ * moved into the auto column.
11
+ */
12
+ import { afterEach, describe, expect, it } from 'vitest'
13
+ import { mount, unmount } from 'svelte'
14
+ import SvGrid from './SvGrid.svelte'
15
+ import {
16
+ createCoreRowModel,
17
+ createExpandedRowModel,
18
+ createFilteredRowModel,
19
+ createGroupedRowModel,
20
+ createPaginatedRowModel,
21
+ createSortedRowModel,
22
+ sortFns,
23
+ tableFeatures,
24
+ rowSortingFeature,
25
+ columnGroupingFeature,
26
+ } from './index'
27
+
28
+ type Row = { id: number; region: string; tier: string; amount: number }
29
+
30
+ const data: Row[] = [
31
+ { id: 1, region: 'East', tier: 'Gold', amount: 10 },
32
+ { id: 2, region: 'East', tier: 'Silver', amount: 5 },
33
+ { id: 3, region: 'West', tier: 'Gold', amount: 7 },
34
+ ]
35
+
36
+ const columns = [
37
+ { field: 'region', header: 'Region', width: 130 },
38
+ { field: 'tier', header: 'Tier', width: 120 },
39
+ { field: 'amount', header: 'Amount', width: 110, aggregate: 'sum' },
40
+ ]
41
+
42
+ const features = tableFeatures({ rowSortingFeature, columnGroupingFeature })
43
+ const tick = () => new Promise<void>((r) => queueMicrotask(r))
44
+
45
+ function mountGrid(props: Record<string, unknown>) {
46
+ const target = document.createElement('div')
47
+ document.body.appendChild(target)
48
+ let api: never = null as never
49
+ const app = mount(SvGrid, {
50
+ target,
51
+ props: {
52
+ data,
53
+ columns,
54
+ features,
55
+ groupable: true,
56
+ onApiReady: (a: never) => { api = a },
57
+ _rowModels: {
58
+ coreRowModel: createCoreRowModel(),
59
+ filteredRowModel: createFilteredRowModel(),
60
+ sortedRowModel: createSortedRowModel(sortFns),
61
+ groupedRowModel: createGroupedRowModel(),
62
+ expandedRowModel: createExpandedRowModel(),
63
+ paginatedRowModel: createPaginatedRowModel(),
64
+ },
65
+ containerHeight: 600,
66
+ virtualization: false,
67
+ ...props,
68
+ } as never,
69
+ })
70
+ return {
71
+ target,
72
+ group: (ids: string[]) => (api as never as { setGroupBy: (i: string[]) => void }).setGroupBy(ids),
73
+ destroy: () => { unmount(app); target.remove() },
74
+ }
75
+ }
76
+
77
+ let cleanup: (() => void) | null = null
78
+ afterEach(() => { cleanup?.(); cleanup = null })
79
+
80
+ async function grouped(props: Record<string, unknown>, by: string[] = ['region']) {
81
+ const g = mountGrid(props)
82
+ cleanup = g.destroy
83
+ await tick()
84
+ g.group(by)
85
+ await tick()
86
+ return g
87
+ }
88
+
89
+ const headers = (t: HTMLElement) =>
90
+ [...t.querySelectorAll('[data-svgrid-header-col]')].map((e) => e.getAttribute('data-svgrid-header-col'))
91
+ // Read labels from the SAME elements that carry the column id, so a gutter or
92
+ // spacer `th` cannot shift the two lists relative to each other.
93
+ const headerLabels = (t: HTMLElement) =>
94
+ [...t.querySelectorAll('[data-svgrid-header-col]')].map((e) => e.textContent?.trim() ?? '')
95
+ const banners = (t: HTMLElement) => t.querySelectorAll('tr.sv-grid-group-row')
96
+
97
+ describe('groupDisplayMode', () => {
98
+ it('defaults to groupRows - full-width banners, source column kept', async () => {
99
+ const g = await grouped({})
100
+ expect(banners(g.target).length).toBeGreaterThan(0)
101
+ expect(headers(g.target)).toContain('region')
102
+ expect(headers(g.target)).not.toContain('__autoGroup')
103
+ })
104
+
105
+ it('singleColumn adds one auto column and hides the grouped source', async () => {
106
+ const g = await grouped({ groupDisplayMode: 'singleColumn' })
107
+ const ids = headers(g.target)
108
+ expect(ids[0]).toBe('__autoGroup')
109
+ // The grouped column is folded in, so showing it too would duplicate it.
110
+ expect(ids).not.toContain('region')
111
+ expect(ids).toContain('amount')
112
+ // No banners - group rows render as ordinary rows now.
113
+ expect(banners(g.target)).toHaveLength(0)
114
+ })
115
+
116
+ it('singleColumn renders the group label + count with an expander', async () => {
117
+ const g = await grouped({ groupDisplayMode: 'singleColumn' })
118
+ const labels = [...g.target.querySelectorAll('.sv-grid-autogroup-label')].map((e) => e.textContent)
119
+ expect(labels).toEqual(['East', 'West'])
120
+ expect(g.target.querySelectorAll('.sv-grid-tree-toggle').length).toBe(2)
121
+ expect(g.target.textContent).toContain('(2)') // East has two rows
122
+ })
123
+
124
+ it('multipleColumns gives each grouped field its own column', async () => {
125
+ const g = await grouped({ groupDisplayMode: 'multipleColumns' }, ['region', 'tier'])
126
+ const ids = headers(g.target)
127
+ expect(ids.slice(0, 2)).toEqual(['__group_region', '__group_tier'])
128
+ expect(ids).not.toContain('region')
129
+ expect(ids).not.toContain('tier')
130
+ })
131
+
132
+ it('names the auto column after the source header', async () => {
133
+ const g = await grouped({ groupDisplayMode: 'multipleColumns' })
134
+ expect(headerLabels(g.target).some((t) => t.includes('Region'))).toBe(true)
135
+ })
136
+
137
+ it('honours autoGroupColumnHeader in singleColumn mode', async () => {
138
+ const g = await grouped({ groupDisplayMode: 'singleColumn', autoGroupColumnHeader: 'Breakdown' })
139
+ expect(headerLabels(g.target).some((t) => t.includes('Breakdown'))).toBe(true)
140
+ })
141
+
142
+ it('keeps header cells aligned with their columns', async () => {
143
+ // The header row indexes headers BY POSITION against the rendered columns,
144
+ // so a synthetic column with no engine header would shift every later
145
+ // header by one. Amount must still sit over Amount.
146
+ const g = await grouped({ groupDisplayMode: 'singleColumn' })
147
+ const ids = headers(g.target)
148
+ const labels = headerLabels(g.target)
149
+ expect(ids).toEqual(['__autoGroup', 'tier', 'amount'])
150
+ expect(labels[ids.indexOf('amount')]).toContain('Amount')
151
+ })
152
+
153
+ it('expands a group from the auto column', async () => {
154
+ const g = await grouped({ groupDisplayMode: 'singleColumn' })
155
+ const toggle = g.target.querySelector<HTMLButtonElement>('.sv-grid-tree-toggle')!
156
+ expect(toggle.getAttribute('aria-expanded')).toBe('false')
157
+ toggle.click()
158
+ await tick()
159
+ expect(g.target.querySelector('.sv-grid-tree-toggle')!.getAttribute('aria-expanded')).toBe('true')
160
+ })
161
+
162
+ it('reverts cleanly when grouping is cleared', async () => {
163
+ const g = await grouped({ groupDisplayMode: 'singleColumn' })
164
+ expect(headers(g.target)).toContain('__autoGroup')
165
+ g.group([])
166
+ await tick()
167
+ const ids = headers(g.target)
168
+ expect(ids).not.toContain('__autoGroup')
169
+ expect(ids).toEqual(['region', 'tier', 'amount'])
170
+ })
171
+ })
@@ -0,0 +1,121 @@
1
+ /**
2
+ * DOM: `groupFooters` renders a subtotal row after each group's children.
3
+ *
4
+ * The footer is a clone of the group banner, so it already carries the group's
5
+ * aggregate values and renders through the normal cell path - which is what puts
6
+ * each total under its own column instead of in a full-width strip. It must not
7
+ * behave like a banner: no expander, and no page budget (footers are inserted
8
+ * after paging).
9
+ */
10
+ import { afterEach, describe, expect, it } from 'vitest'
11
+ import { mount, unmount } from 'svelte'
12
+ import SvGrid from './SvGrid.svelte'
13
+ import {
14
+ createCoreRowModel,
15
+ createExpandedRowModel,
16
+ createFilteredRowModel,
17
+ createGroupedRowModel,
18
+ createPaginatedRowModel,
19
+ createSortedRowModel,
20
+ sortFns,
21
+ tableFeatures,
22
+ rowSortingFeature,
23
+ columnGroupingFeature,
24
+ } from './index'
25
+
26
+ type Row = { id: number; region: string; amount: number }
27
+
28
+ const data: Row[] = [
29
+ { id: 1, region: 'East', amount: 10 },
30
+ { id: 2, region: 'East', amount: 5 },
31
+ { id: 3, region: 'West', amount: 7 },
32
+ ]
33
+
34
+ const columns = [
35
+ { field: 'region', header: 'Region', width: 120 },
36
+ { field: 'amount', header: 'Amount', width: 100, aggregate: 'sum' },
37
+ ]
38
+
39
+ const features = tableFeatures({ rowSortingFeature, columnGroupingFeature })
40
+ const tick = () => new Promise<void>((r) => queueMicrotask(r))
41
+
42
+ function mountGrid(groupFooters: boolean) {
43
+ const target = document.createElement('div')
44
+ document.body.appendChild(target)
45
+ let api: { setGroupBy: (ids: string[]) => void } | null = null
46
+ const app = mount(SvGrid, {
47
+ target,
48
+ props: {
49
+ data,
50
+ columns,
51
+ features,
52
+ groupable: true,
53
+ groupFooters,
54
+ onApiReady: (a: never) => { api = a as never },
55
+ _rowModels: {
56
+ coreRowModel: createCoreRowModel(),
57
+ filteredRowModel: createFilteredRowModel(),
58
+ sortedRowModel: createSortedRowModel(sortFns),
59
+ groupedRowModel: createGroupedRowModel(),
60
+ expandedRowModel: createExpandedRowModel(),
61
+ paginatedRowModel: createPaginatedRowModel(),
62
+ },
63
+ containerHeight: 600,
64
+ virtualization: false,
65
+ } as never,
66
+ })
67
+ return {
68
+ target,
69
+ setup: async () => {
70
+ await tick()
71
+ api?.setGroupBy(['region'])
72
+ await tick()
73
+ for (const btn of target.querySelectorAll<HTMLButtonElement>('.sv-grid-group-toggle')) {
74
+ if (btn.getAttribute('aria-expanded') !== 'true') btn.click()
75
+ }
76
+ await tick()
77
+ },
78
+ destroy: () => { unmount(app); target.remove() },
79
+ }
80
+ }
81
+
82
+ let cleanup: (() => void) | null = null
83
+ afterEach(() => { cleanup?.(); cleanup = null })
84
+
85
+ const footers = (t: HTMLElement) => [...t.querySelectorAll('tr.sv-grid-group-footer-row')]
86
+
87
+ describe('groupFooters', () => {
88
+ it('renders nothing extra when off', async () => {
89
+ const g = mountGrid(false)
90
+ cleanup = g.destroy
91
+ await g.setup()
92
+ expect(footers(g.target)).toHaveLength(0)
93
+ })
94
+
95
+ it('renders one footer per group', async () => {
96
+ const g = mountGrid(true)
97
+ cleanup = g.destroy
98
+ await g.setup()
99
+ expect(footers(g.target)).toHaveLength(2)
100
+ })
101
+
102
+ it('carries the group aggregate under its own column', async () => {
103
+ const g = mountGrid(true)
104
+ cleanup = g.destroy
105
+ await g.setup()
106
+ // East totals 15, West totals 7 - in the Amount column, not a banner strip.
107
+ const text = footers(g.target).map((f) => f.textContent ?? '')
108
+ expect(text[0]).toContain('15')
109
+ expect(text[1]).toContain('7')
110
+ })
111
+
112
+ it('is not treated as an expandable banner', async () => {
113
+ const g = mountGrid(true)
114
+ cleanup = g.destroy
115
+ await g.setup()
116
+ for (const f of footers(g.target)) {
117
+ expect(f.classList.contains('sv-grid-group-row')).toBe(false)
118
+ expect(f.querySelector('.sv-grid-group-toggle')).toBeNull()
119
+ }
120
+ })
121
+ })