@@ -76,7 +76,11 @@ export interface RowPinningRow {
76
76
}
77
77
78
78
export interface RowPinningInstance < TData extends RowData > {
79
- _getPinnedRows : ( position : 'top' | 'bottom' ) => Row < TData > [ ]
79
+ _getPinnedRows : (
80
+ visiblePinnedRows : Array < Row < TData > > ,
81
+ pinnedRowIds : Array < string > | undefined ,
82
+ position : 'top' | 'bottom'
83
+ ) => Row < TData > [ ]
80
84
/**
81
85
* Returns all bottom pinned rows.
82
86
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getbottomrows)
@@ -199,9 +203,9 @@ export const RowPinning: TableFeature = {
199
203
const position = row . getIsPinned ( )
200
204
if ( ! position ) return - 1
201
205
202
- const visiblePinnedRowIds = table
203
- . _getPinnedRows ( position )
204
- ?. map ( ( { id } ) => id )
206
+ const visiblePinnedRowIds = (
207
+ position === 'top' ? table . getTopRows ( ) : table . getBottomRows ( )
208
+ ) ?. map ( ( { id } ) => id )
205
209
206
210
return visiblePinnedRowIds ?. indexOf ( row . id ) ?? - 1
207
211
}
@@ -226,36 +230,36 @@ export const RowPinning: TableFeature = {
226
230
return Boolean ( pinningState [ position ] ?. length )
227
231
}
228
232
229
- table . _getPinnedRows = memo (
230
- position => [
231
- table . getRowModel ( ) . rows ,
232
- table . getState ( ) . rowPinning [ position ! ] ,
233
- position ,
234
- ] ,
235
- ( visibleRows , pinnedRowIds , position ) => {
236
- const rows =
237
- table . options . keepPinnedRows ?? true
238
- ? //get all rows that are pinned even if they would not be otherwise visible
239
- //account for expanded parent rows, but not pagination or filtering
240
- ( pinnedRowIds ?? [ ] ) . map ( rowId => {
241
- const row = table . getRow ( rowId , true )
242
- return row . getIsAllParentsExpanded ( ) ? row : null
243
- } )
244
- : //else get only visible rows that are pinned
245
- ( pinnedRowIds ?? [ ] ) . map (
246
- rowId => visibleRows . find ( row => row . id === rowId ) !
247
- )
233
+ table . _getPinnedRows = ( visibleRows , pinnedRowIds , position ) => {
234
+ const rows =
235
+ table . options . keepPinnedRows ?? true
236
+ ? //get all rows that are pinned even if they would not be otherwise visible
237
+ //account for expanded parent rows, but not pagination or filtering
238
+ ( pinnedRowIds ?? [ ] ) . map ( rowId => {
239
+ const row = table . getRow ( rowId , true )
240
+ return row . getIsAllParentsExpanded ( ) ? row : null
241
+ } )
242
+ : //else get only visible rows that are pinned
243
+ ( pinnedRowIds ?? [ ] ) . map (
244
+ rowId => visibleRows . find ( row => row . id === rowId ) !
245
+ )
248
246
249
- return rows
250
- . filter ( Boolean )
251
- . map ( d => ( { ...d , position } ) ) as Row < TData > [ ]
252
- } ,
253
- getMemoOptions ( table . options , 'debugRows' , '_getPinnedRows' )
254
- )
247
+ return rows . filter ( Boolean ) . map ( d => ( { ...d , position } ) ) as Row < TData > [ ]
248
+ }
255
249
256
- table . getTopRows = ( ) => table . _getPinnedRows ( 'top' )
250
+ table . getTopRows = memo (
251
+ ( ) => [ table . getRowModel ( ) . rows , table . getState ( ) . rowPinning . top ] ,
252
+ ( allRows , topPinnedRowIds ) =>
253
+ table . _getPinnedRows ( allRows , topPinnedRowIds , 'top' ) ,
254
+ getMemoOptions ( table . options , 'debugRows' , 'getTopRows' )
255
+ )
257
256
258
- table . getBottomRows = ( ) => table . _getPinnedRows ( 'bottom' )
257
+ table . getBottomRows = memo (
258
+ ( ) => [ table . getRowModel ( ) . rows , table . getState ( ) . rowPinning . bottom ] ,
259
+ ( allRows , bottomPinnedRowIds ) =>
260
+ table . _getPinnedRows ( allRows , bottomPinnedRowIds , 'bottom' ) ,
261
+ getMemoOptions ( table . options , 'debugRows' , 'getBottomRows' )
262
+ )
259
263
260
264
table . getCenterRows = memo (
261
265
( ) => [
0 commit comments