This commit is contained in:
Thomas Peterson 2025-11-17 09:45:29 +01:00
parent ef75fe4ea1
commit 29b14379e7
2 changed files with 27 additions and 0 deletions

View File

@ -522,6 +522,26 @@ class Container extends Component
]; ];
} }
/**
* Get current scroll position.
*/
public function getScrollPosition(): array
{
return [
'x' => $this->scrollX,
'y' => $this->scrollY,
];
}
/**
* Restore scroll position (used e.g. after re-rendering children).
*/
public function setScrollPosition(float $x, float $y): void
{
$this->scrollX = max(0, $x);
$this->scrollY = max(0, $y);
}
private function renderScrollbars(&$renderer, array $overflow): void private function renderScrollbars(&$renderer, array $overflow): void
{ {
$scrollbarColor = [120, 120, 120, 230]; $scrollbarColor = [120, 120, 120, 230];

View File

@ -202,6 +202,10 @@ class Table extends Container
*/ */
public function selectRow(int $rowIndex): void public function selectRow(int $rowIndex): void
{ {
// Remember current scroll position of the body so that selection
// does not reset scrolling back to the top.
$scrollPosition = $this->bodyContainer->getScrollPosition();
$this->selectedRowIndex = $rowIndex; $this->selectedRowIndex = $rowIndex;
// Trigger callback // Trigger callback
@ -211,6 +215,9 @@ class Table extends Container
// Re-render rows to update selection // Re-render rows to update selection
$this->setData($this->rows); $this->setData($this->rows);
// Restore scroll position
$this->bodyContainer->setScrollPosition($scrollPosition['x'], $scrollPosition['y']);
} }
/** /**