11import { describe , expect , it , vi } from 'vitest'
22import {
3+ columnGroupingFeature ,
34 constructTable ,
5+ createGroupedRowModel ,
46 createPaginatedRowModel ,
57 rowPaginationFeature ,
68 rowPinningFeature ,
@@ -21,6 +23,12 @@ const featuresWithPagination = testFeatures({
2123 paginatedRowModel : createPaginatedRowModel ( ) ,
2224} )
2325
26+ const featuresWithGrouping = testFeatures ( {
27+ columnGroupingFeature,
28+ rowPinningFeature,
29+ groupedRowModel : createGroupedRowModel ( ) ,
30+ } )
31+
2432function makeTable (
2533 options ?: Partial <
2634 Omit < TableOptions < typeof features , Person > , 'data' | 'columns' | 'features' >
@@ -137,6 +145,31 @@ describe('table methods', () => {
137145 } )
138146
139147 describe ( 'getTopRows/getBottomRows/getCenterRows' , ( ) => {
148+ it ( 'does not throw when a pinned grouped row disappears after ungrouping' , ( ) => {
149+ const data = generateTestData ( 3 )
150+ const table = constructTable ( {
151+ features : featuresWithGrouping ,
152+ data,
153+ columns : generateTestColumnDefs < typeof featuresWithGrouping > ( data ) ,
154+ initialState : {
155+ grouping : [ 'status' ] ,
156+ } ,
157+ } )
158+ const groupedRow = table . getRowModel ( ) . rows [ 0 ] !
159+
160+ groupedRow . pin ( 'top' )
161+ expect ( table . getTopRows ( ) ) . toEqual ( [ groupedRow ] )
162+
163+ table . setGrouping ( [ ] )
164+
165+ expect ( table . getTopRows ( ) ) . toEqual ( [ ] )
166+ expect ( table . atoms . rowPinning . get ( ) . top ) . toEqual ( [ groupedRow . id ] )
167+
168+ table . setGrouping ( [ 'status' ] )
169+
170+ expect ( table . getTopRows ( ) . map ( ( row ) => row . id ) ) . toEqual ( [ groupedRow . id ] )
171+ } )
172+
140173 it ( 'should return correct rows for each section' , ( ) => {
141174 const table = makeTable ( {
142175 initialState : {
0 commit comments