@@ -29,6 +29,7 @@ struct DataGridIdentity: Equatable {
2929 let reloadVersion : Int
3030 let resultVersion : Int
3131 let metadataVersion : Int
32+ let paginationVersion : Int
3233 let rowCount : Int
3334 let columnCount : Int
3435 let isEditable : Bool
@@ -41,6 +42,7 @@ struct DataGridView: NSViewRepresentable {
4142 var changeManager : AnyChangeManager
4243 var resultVersion : Int = 0
4344 var metadataVersion : Int = 0
45+ var paginationVersion : Int = 0
4446 let isEditable : Bool
4547 var onRefresh : ( ( ) -> Void ) ?
4648 var onCellEdit : ( ( Int , Int , String ? ) -> Void ) ?
@@ -228,6 +230,7 @@ struct DataGridView: NSViewRepresentable {
228230 reloadVersion: changeManager. reloadVersion,
229231 resultVersion: resultVersion,
230232 metadataVersion: metadataVersion,
233+ paginationVersion: paginationVersion,
231234 rowCount: rowProvider. totalRowCount,
232235 columnCount: rowProvider. columns. count,
233236 isEditable: isEditable,
@@ -355,12 +358,15 @@ struct DataGridView: NSViewRepresentable {
355358
356359 syncSortDescriptors ( tableView: tableView, coordinator: coordinator)
357360
361+ let paginationChanged = previousIdentity. map { $0. paginationVersion != paginationVersion } ?? false
362+
358363 reloadAndSyncSelection (
359364 tableView: tableView,
360365 coordinator: coordinator,
361366 needsFullReload: needsFullReload,
362367 versionChanged: versionChanged,
363- metadataChanged: metadataChanged
368+ metadataChanged: metadataChanged,
369+ paginationChanged: paginationChanged
364370 )
365371 }
366372
@@ -546,7 +552,8 @@ struct DataGridView: NSViewRepresentable {
546552 coordinator: TableViewCoordinator ,
547553 needsFullReload: Bool ,
548554 versionChanged: Bool ,
549- metadataChanged: Bool = false
555+ metadataChanged: Bool = false ,
556+ paginationChanged: Bool = false
550557 ) {
551558 if needsFullReload {
552559 tableView. reloadData ( )
@@ -591,6 +598,11 @@ struct DataGridView: NSViewRepresentable {
591598
592599 coordinator. lastReloadVersion = changeManager. reloadVersion
593600
601+ // Scroll to first row when page changes
602+ if paginationChanged && tableView. numberOfRows > 0 {
603+ tableView. scrollRowToVisible ( 0 )
604+ }
605+
594606 // Sync selection
595607 let currentSelection = tableView. selectedRowIndexes
596608 let targetSelection = IndexSet ( selectedRowIndices)
0 commit comments