Skip to content

Commit

Permalink
impl. proper fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jun 19, 2023
1 parent aab82ce commit 4700e7d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ItemsPerPageSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Atk4\Ui;

use Atk4\Data\Field;
use Atk4\Ui\Js\JsExpression;

/**
Expand All @@ -27,6 +28,11 @@ class ItemsPerPageSelector extends View
/** @var Callback|null The callback function. */
public $cb;

private function formatInteger(int $value): string
{
return $this->getApp()->uiPersistence->typecastSaveField(new Field(['type' => 'integer']), $value);
}

protected function init(): void
{
parent::init();
Expand All @@ -40,7 +46,7 @@ protected function init(): void
if (!$this->currentIpp) {
$this->currentIpp = $this->pageLengthItems[0];
}
$this->set((string) $this->currentIpp);
$this->set($this->formatInteger($this->currentIpp));
}

/**
Expand All @@ -54,7 +60,7 @@ public function onPageLengthSelect(\Closure $fx): void
{
$this->cb->set(function () use ($fx) {
$ipp = isset($_GET['ipp']) ? (int) $_GET['ipp'] : null;
$this->set((string) $ipp);
$this->set($this->formatInteger($ipp));
$reload = $fx($ipp);
if ($reload) {
$this->getApp()->terminateJson($reload);
Expand All @@ -65,8 +71,8 @@ public function onPageLengthSelect(\Closure $fx): void
protected function renderView(): void
{
$menuItems = [];
foreach ($this->pageLengthItems as $key => $item) {
$menuItems[] = ['name' => $item, 'value' => $item];
foreach ($this->pageLengthItems as $item) {
$menuItems[] = ['name' => $this->formatInteger($item), 'value' => $item];
}

$function = new JsExpression('function (value, text, item) {
Expand Down

0 comments on commit 4700e7d

Please sign in to comment.