@svgrid/grid 2.2.31 → 2.2.33

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 (196) hide show
  1. package/README.md +1 -1
  2. package/dist/DockNodeView.svelte +1 -1
  3. package/dist/GridFooter.svelte +0 -40
  4. package/dist/GridMenus.svelte +0 -77
  5. package/dist/SvAvatar.svelte +1 -1
  6. package/dist/SvCheckBox.svelte +2 -1
  7. package/dist/SvCircularProgress.svelte +1 -1
  8. package/dist/SvDateRangeInput.svelte +1 -1
  9. package/dist/SvGrid.controller.svelte.d.ts +20 -0
  10. package/dist/SvGrid.controller.svelte.js +358 -18
  11. package/dist/SvGrid.css +103 -3
  12. package/dist/SvGrid.svelte +164 -35
  13. package/dist/SvGrid.types.d.ts +81 -0
  14. package/dist/SvGridChart.svelte +2 -10
  15. package/dist/SvGridDropdown.svelte +38 -6
  16. package/dist/SvGridDropdown.svelte.d.ts +4 -0
  17. package/dist/SvGridSelect.svelte +12 -5
  18. package/dist/SvGridSelect.svelte.d.ts +6 -0
  19. package/dist/SvGroupCell.svelte +9 -2
  20. package/dist/SvKbd.svelte +1 -1
  21. package/dist/SvList.svelte +1 -1
  22. package/dist/SvMenubar.svelte +1 -1
  23. package/dist/SvMultiSelect.svelte +12 -4
  24. package/dist/SvMultiSelect.svelte.d.ts +6 -0
  25. package/dist/SvOtpInput.svelte +1 -1
  26. package/dist/SvPasswordInput.svelte +1 -1
  27. package/dist/SvProgress.svelte +1 -1
  28. package/dist/SvRating.svelte +1 -1
  29. package/dist/SvResult.svelte +1 -1
  30. package/dist/SvRichText.svelte +35 -16
  31. package/dist/SvRichText.svelte.d.ts +9 -0
  32. package/dist/SvSwitchButton.svelte +2 -1
  33. package/dist/SvToaster.svelte +1 -1
  34. package/dist/SvTour.svelte +4 -0
  35. package/dist/SvTree.svelte +9 -2
  36. package/dist/SvTree.svelte.d.ts +5 -0
  37. package/dist/SvTreeSelect.svelte +6 -4
  38. package/dist/build-api.js +16 -0
  39. package/dist/cdn/{GridMenus-Ds3OpzZT.js → GridMenus-B7XhhqdN.js} +34 -36
  40. package/dist/cdn/{GridMenus-Da_p7SKS.js → GridMenus-BxmIvCJh.js} +35 -37
  41. package/dist/cdn/{SvDateTimePicker-DB0aIEk8.js → SvDateTimePicker-ClqtVIj3.js} +2 -1
  42. package/dist/cdn/{SvDateTimePicker-B8GopjhC.js → SvDateTimePicker-o94wfSUa.js} +3 -2
  43. package/dist/cdn/{SvGridChart-BcLCYvw9.js → SvGridChart-Cr_90pPD.js} +1 -1
  44. package/dist/cdn/{SvGridChartPanel-DvjwxLvK.js → SvGridChartPanel-ICbxiUvK.js} +4 -4
  45. package/dist/cdn/{SvGridChartView-PwqI4s02.js → SvGridChartView-Bx42PMvf.js} +2 -2
  46. package/dist/cdn/{SvGridDropdown-hpnHvOGt.js → SvGridDropdown-CUOdm7YA.js} +93 -88
  47. package/dist/cdn/{SvGridDropdown-DjALc_4f.js → SvGridDropdown-D0VdjeR8.js} +129 -123
  48. package/dist/cdn/{disclose-version-DoD9AFD_.js → disclose-version-DljhZohK.js} +45 -45
  49. package/dist/cdn/{src-DYDCiC0D.js → src-erjBRYfX.js} +5952 -5615
  50. package/dist/cdn/{src-BLJfdyL0.js → src-ktbQVOk-.js} +4190 -3851
  51. package/dist/cdn/svgrid.js +9 -9
  52. package/dist/cdn/svgrid.svelte-external.js +8 -8
  53. package/dist/cell-render.d.ts +1 -0
  54. package/dist/cell-render.js +115 -1
  55. package/dist/cell-values.js +5 -0
  56. package/dist/chart.d.ts +2 -0
  57. package/dist/chart.js +1 -4
  58. package/dist/core.d.ts +80 -9
  59. package/dist/core.js +89 -0
  60. package/dist/createMenu.svelte.js +0 -1
  61. package/dist/createPopoverSelect.svelte.d.ts +2 -2
  62. package/dist/editing.js +1 -1
  63. package/dist/editor-contract.d.ts +12 -5
  64. package/dist/editor-registry.d.ts +18 -7
  65. package/dist/editor-registry.js +10 -1
  66. package/dist/export-format.js +3 -0
  67. package/dist/group-display.d.ts +39 -0
  68. package/dist/group-display.js +52 -0
  69. package/dist/index.d.ts +2 -2
  70. package/dist/index.js +2 -2
  71. package/dist/keyboard-handlers.js +16 -0
  72. package/dist/recurrence.js +3 -2
  73. package/dist/selection.js +0 -1
  74. package/dist/svgrid-wrapper.types.d.ts +8 -2
  75. package/dist/themes/index.d.ts +10 -0
  76. package/dist/themes/index.js +26 -0
  77. package/package.json +3 -2
  78. package/src/DockNodeView.svelte +1 -1
  79. package/src/GridFooter.svelte +0 -40
  80. package/src/GridMenus.svelte +0 -77
  81. package/src/SvAccordion.test.ts +5 -5
  82. package/src/SvAvatar.svelte +1 -1
  83. package/src/SvButtonGroup.test.ts +6 -6
  84. package/src/SvCalendar.test.ts +1 -1
  85. package/src/SvCheckBox.svelte +2 -1
  86. package/src/SvCircularProgress.svelte +1 -1
  87. package/src/SvDateRangeInput.svelte +1 -1
  88. package/src/SvFileUpload.test.ts +1 -1
  89. package/src/SvGrid.controller.svelte.ts +367 -22
  90. package/src/SvGrid.css +103 -3
  91. package/src/SvGrid.svelte +164 -35
  92. package/src/SvGrid.types.ts +81 -1
  93. package/src/SvGridChart.svelte +2 -10
  94. package/src/SvGridDropdown.svelte +38 -6
  95. package/src/SvGridSelect.svelte +12 -5
  96. package/src/SvGroupCell.svelte +9 -2
  97. package/src/SvKbd.svelte +1 -1
  98. package/src/SvList.svelte +1 -1
  99. package/src/SvMenubar.svelte +1 -1
  100. package/src/SvMultiSelect.svelte +12 -4
  101. package/src/SvOtpInput.svelte +1 -1
  102. package/src/SvPasswordInput.svelte +1 -1
  103. package/src/SvProgress.svelte +1 -1
  104. package/src/SvRating.svelte +1 -1
  105. package/src/SvResult.svelte +1 -1
  106. package/src/SvRichText.svelte +35 -16
  107. package/src/SvSwitchButton.svelte +2 -1
  108. package/src/SvToaster.svelte +1 -1
  109. package/src/SvTour.svelte +4 -0
  110. package/src/SvTree.svelte +9 -2
  111. package/src/SvTreeSelect.svelte +6 -4
  112. package/src/ai.test.ts +1 -1
  113. package/src/build-api.ts +15 -105
  114. package/src/builtin-editors.test.ts +3 -1
  115. package/src/cell-formatting.test.ts +1 -1
  116. package/src/cell-render.test.ts +27 -3
  117. package/src/cell-render.ts +122 -95
  118. package/src/cell-values.ts +4 -0
  119. package/src/chart-export.test.ts +2 -2
  120. package/src/chart.ts +1 -2
  121. package/src/clipboard.test.ts +0 -2
  122. package/src/clipboard.ts +0 -102
  123. package/src/columns.ts +0 -115
  124. package/src/core.ts +157 -8
  125. package/src/createMenu.svelte.ts +0 -1
  126. package/src/editing.test.ts +1 -1
  127. package/src/editing.ts +2 -105
  128. package/src/editor-contract.ts +12 -5
  129. package/src/editor-registry.grid.test.ts +48 -2
  130. package/src/editor-registry.test.ts +3 -1
  131. package/src/editor-registry.ts +23 -7
  132. package/src/export-format.ts +3 -0
  133. package/src/facet-buckets.test.ts +33 -33
  134. package/src/features.ts +0 -90
  135. package/src/group-display.test.ts +91 -1
  136. package/src/group-display.ts +83 -0
  137. package/src/index.ts +9 -0
  138. package/src/keyboard-handlers.coverage.test.ts +1 -1
  139. package/src/keyboard-handlers.ts +17 -120
  140. package/src/list-power.test.ts +2 -2
  141. package/src/menus.test.ts +4 -5
  142. package/src/menus.ts +0 -112
  143. package/src/named-views.coverage.test.ts +3 -3
  144. package/src/new-features.test.ts +3 -1
  145. package/src/recurrence.ts +3 -2
  146. package/src/row-drag.test.ts +1 -1
  147. package/src/row-resize.test.ts +41 -42
  148. package/src/scheduler-model.ts +1 -1
  149. package/src/scroll-sync.test.ts +4 -7
  150. package/src/scroll-sync.ts +0 -122
  151. package/src/selection.ts +0 -109
  152. package/src/server-data-source.coverage.test.ts +1 -1
  153. package/src/server-group-model.test.ts +8 -8
  154. package/src/spreadsheet.test.ts +0 -1
  155. package/src/summaries.ts +0 -112
  156. package/src/svgrid-wrapper.types.ts +11 -9
  157. package/src/svgrid.async-editor-options.test.ts +271 -0
  158. package/src/svgrid.auto-row-height.test.ts +204 -0
  159. package/src/svgrid.behavior.test.ts +0 -1
  160. package/src/svgrid.charting.test.ts +4 -4
  161. package/src/svgrid.column-reorder.test.ts +0 -8
  162. package/src/svgrid.comments-autocomplete.test.ts +8 -2
  163. package/src/svgrid.context-menu.test.ts +25 -9
  164. package/src/svgrid.filter-depth.test.ts +163 -0
  165. package/src/svgrid.filter-menu-listbox.svelte.test.ts +16 -2
  166. package/src/svgrid.filter-menu-scroll.test.ts +10 -2
  167. package/src/svgrid.grand-total.test.ts +188 -0
  168. package/src/svgrid.group-display-mode.test.ts +171 -0
  169. package/src/svgrid.group-footers.test.ts +121 -0
  170. package/src/svgrid.group-pagination.test.ts +153 -0
  171. package/src/svgrid.tree-data.test.ts +186 -0
  172. package/src/svgriddropdown.async-panel.svelte.test.ts +195 -0
  173. package/src/themes/index.ts +42 -0
  174. package/src/tree-edit.test.ts +4 -4
  175. package/src/tree-row-model.test.ts +168 -0
  176. package/src/ui-localization.test.ts +113 -0
  177. package/themes/ag-alpine.css +22 -0
  178. package/themes/antd.css +22 -0
  179. package/themes/atlassian.css +22 -0
  180. package/themes/bootstrap.css +22 -0
  181. package/themes/carbon.css +22 -0
  182. package/themes/catppuccin.css +22 -0
  183. package/themes/dracula.css +22 -0
  184. package/themes/ember.css +22 -0
  185. package/themes/excel.css +22 -0
  186. package/themes/fluent.css +22 -0
  187. package/themes/github.css +22 -0
  188. package/themes/linear.css +22 -0
  189. package/themes/material.css +22 -0
  190. package/themes/nord.css +22 -0
  191. package/themes/notion.css +22 -0
  192. package/themes/salesforce.css +22 -0
  193. package/themes/sap.css +22 -0
  194. package/themes/shadcn.css +22 -0
  195. package/themes/tailwind.css +22 -0
  196. package/themes/vercel.css +22 -0
@@ -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
+ })
@@ -0,0 +1,153 @@
1
+ /**
2
+ * DOM: with grouping on, `pageSize` budgets DATA rows, not group banners (#73).
3
+ *
4
+ * The row model hands the view one flat list with group banners interleaved
5
+ * between their children. Slicing that list by `pageSize` spent the budget on
6
+ * banners: ten groups of two at `pageSize: 10` showed roughly three data rows,
7
+ * and with enough small groups a page could show almost none.
8
+ *
9
+ * Now the page window is measured in data rows, and each page reprints the
10
+ * banners its rows sit under - so a group split across a page boundary is
11
+ * labelled on both pages.
12
+ */
13
+ import { afterEach, describe, expect, it } from 'vitest'
14
+ import { mount, unmount } from 'svelte'
15
+ import SvGrid from './SvGrid.svelte'
16
+ import {
17
+ createCoreRowModel,
18
+ createExpandedRowModel,
19
+ createFilteredRowModel,
20
+ createGroupedRowModel,
21
+ createPaginatedRowModel,
22
+ createSortedRowModel,
23
+ sortFns,
24
+ tableFeatures,
25
+ rowSortingFeature,
26
+ columnGroupingFeature,
27
+ } from './index'
28
+
29
+ type Row = { id: number; region: string; amount: number }
30
+
31
+ // Ten groups of two rows - the shape from the report.
32
+ const data: Row[] = []
33
+ for (let g = 0; g < 10; g += 1) {
34
+ data.push({ id: g * 2, region: `R${g}`, amount: 1 })
35
+ data.push({ id: g * 2 + 1, region: `R${g}`, amount: 2 })
36
+ }
37
+
38
+ const columns = [
39
+ { field: 'region', header: 'Region', width: 120 },
40
+ { field: 'amount', header: 'Amount', width: 100 },
41
+ ]
42
+
43
+ const features = tableFeatures({ rowSortingFeature, columnGroupingFeature })
44
+ const tick = () => new Promise<void>((r) => queueMicrotask(r))
45
+
46
+ function mountGrid(pageSize: number, groupFooters = false) {
47
+ const target = document.createElement('div')
48
+ document.body.appendChild(target)
49
+ // Grouping state starts empty and is driven through the api - there is no
50
+ // initial-grouping prop - so group by region as soon as the api lands.
51
+ let api: { setGroupBy: (ids: string[]) => void } | null = null
52
+ const app = mount(SvGrid, {
53
+ target,
54
+ props: {
55
+ data,
56
+ columns,
57
+ features,
58
+ groupable: true,
59
+ groupFooters,
60
+ onApiReady: (a: never) => { api = a as never },
61
+ pageable: true,
62
+ pageSize,
63
+ _rowModels: {
64
+ coreRowModel: createCoreRowModel(),
65
+ filteredRowModel: createFilteredRowModel(),
66
+ sortedRowModel: createSortedRowModel(sortFns),
67
+ groupedRowModel: createGroupedRowModel(),
68
+ expandedRowModel: createExpandedRowModel(),
69
+ paginatedRowModel: createPaginatedRowModel(),
70
+ },
71
+ containerHeight: 900,
72
+ virtualization: false,
73
+ } as never,
74
+ })
75
+ return {
76
+ target,
77
+ groupByRegion: () => api?.setGroupBy(['region']),
78
+ /** Groups render collapsed by default; click every banner to open them. */
79
+ expandAll: () => {
80
+ for (const btn of target.querySelectorAll<HTMLButtonElement>('.sv-grid-group-toggle')) {
81
+ if (btn.getAttribute('aria-expanded') !== 'true') btn.click()
82
+ }
83
+ },
84
+ destroy: () => { unmount(app); target.remove() },
85
+ }
86
+ }
87
+
88
+ let cleanup: (() => void) | null = null
89
+ afterEach(() => { cleanup?.(); cleanup = null })
90
+
91
+ const dataRows = (t: HTMLElement) =>
92
+ [...t.querySelectorAll('tbody tr.sv-grid-row')].filter(
93
+ (r) => !r.classList.contains('sv-grid-group-row') && !r.classList.contains('sv-grid-row-spacer'),
94
+ )
95
+ const groupRows = (t: HTMLElement) => [...t.querySelectorAll('tbody tr.sv-grid-group-row')]
96
+
97
+ async function grouped(pageSize: number, expand = true, groupFooters = false) {
98
+ const g = mountGrid(pageSize, groupFooters)
99
+ cleanup = g.destroy
100
+ await tick()
101
+ g.groupByRegion()
102
+ await tick()
103
+ if (expand) {
104
+ g.expandAll()
105
+ await tick()
106
+ }
107
+ return g
108
+ }
109
+
110
+ describe('grouped pagination (#73)', () => {
111
+ it('fills the page with pageSize DATA rows, not banners', async () => {
112
+ const { target } = await grouped(10)
113
+ // Before the fix the flat slice returned 10 TOTAL rows - banners included -
114
+ // so only a handful of them were data.
115
+ expect(dataRows(target)).toHaveLength(10)
116
+ // Those 10 data rows span 5 groups, so 5 banners come along for free.
117
+ expect(groupRows(target)).toHaveLength(5)
118
+ })
119
+
120
+ it('reports the data-row count in the pager, not banners + data', async () => {
121
+ const { target } = await grouped(10)
122
+ // 20 data rows at pageSize 10 = 2 pages. Counting banners would say 30.
123
+ expect(target.textContent).toMatch(/of\s+20\b/)
124
+ })
125
+
126
+ it('reprints the banner for a group straddling a page boundary', async () => {
127
+ const { target } = await grouped(3)
128
+ // Page 0 holds R0's two rows plus R1's first, so both banners show.
129
+ const labels = groupRows(target).map((r) => r.textContent ?? '')
130
+ expect(labels.some((t) => t.includes('R0'))).toBe(true)
131
+ expect(labels.some((t) => t.includes('R1'))).toBe(true)
132
+ expect(dataRows(target)).toHaveLength(3)
133
+ })
134
+
135
+ it('does not spend page budget on group footers', async () => {
136
+ // Footers are inserted after paging, so turning them on must not push data
137
+ // rows onto the next page.
138
+ const { target } = await grouped(10, true, true)
139
+ expect(dataRows(target).filter((r) => !r.classList.contains('sv-grid-group-footer-row')))
140
+ .toHaveLength(10)
141
+ expect(target.textContent).toMatch(/of\s+20\b/)
142
+ })
143
+
144
+ it('still fills a page when every group is collapsed', async () => {
145
+ // Collapsed groups are the visible unit. Treating them as free headers
146
+ // emptied the page entirely - caught here, not by the pure helper.
147
+ const { target } = await grouped(4, false)
148
+ expect(groupRows(target)).toHaveLength(4)
149
+ expect(dataRows(target)).toHaveLength(0)
150
+ // 10 collapsed groups over pageSize 4.
151
+ expect(target.textContent).toMatch(/of\s+10\b/)
152
+ })
153
+ })