@@ -76,7 +76,11 @@ export interface RowPinningRow {
7676}
7777
7878export 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 > [ ]
8084 /**
8185 * Returns all bottom pinned rows.
8286 * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getbottomrows)
@@ -199,9 +203,9 @@ export const RowPinning: TableFeature = {
199203 const position = row . getIsPinned ( )
200204 if ( ! position ) return - 1
201205
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 )
205209
206210 return visiblePinnedRowIds ?. indexOf ( row . id ) ?? - 1
207211 }
@@ -226,36 +230,36 @@ export const RowPinning: TableFeature = {
226230 return Boolean ( pinningState [ position ] ?. length )
227231 }
228232
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+ )
248246
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+ }
255249
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+ )
257256
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+ )
259263
260264 table . getCenterRows = memo (
261265 ( ) => [
0 commit comments