4
4
5
5
namespace Atk4 \Ui ;
6
6
7
+ use Atk4 \Data \Field ;
7
8
use Atk4 \Ui \Js \JsExpression ;
8
9
9
10
/**
@@ -16,14 +17,9 @@ class ItemsPerPageSelector extends View
16
17
public $ ui = 'selection compact dropdown ' ;
17
18
18
19
/** @var list<int> Default page length menu items. */
19
- public $ pageLengthItems = [10 , 25 , 50 , 100 ];
20
+ public $ pageLengthItems = [10 , 100 , 1000 ];
20
21
21
- /**
22
- * Default button label.
23
- * - [ipp] will be replace by the number of pages selected.
24
- *
25
- * @var string
26
- */
22
+ /** @var string */
27
23
public $ label = 'Items per page: ' ;
28
24
29
25
/** @var int The current number of item per page. */
@@ -32,6 +28,11 @@ class ItemsPerPageSelector extends View
32
28
/** @var Callback|null The callback function. */
33
29
public $ cb ;
34
30
31
+ private function formatInteger (int $ value ): string
32
+ {
33
+ return $ this ->getApp ()->uiPersistence ->typecastSaveField (new Field (['type ' => 'integer ' ]), $ value );
34
+ }
35
+
35
36
protected function init (): void
36
37
{
37
38
parent ::init ();
@@ -45,7 +46,7 @@ protected function init(): void
45
46
if (!$ this ->currentIpp ) {
46
47
$ this ->currentIpp = $ this ->pageLengthItems [0 ];
47
48
}
48
- $ this ->set (( string ) $ this ->currentIpp );
49
+ $ this ->set ($ this -> formatInteger ( $ this ->currentIpp ) );
49
50
}
50
51
51
52
/**
@@ -59,8 +60,7 @@ public function onPageLengthSelect(\Closure $fx): void
59
60
{
60
61
$ this ->cb ->set (function () use ($ fx ) {
61
62
$ ipp = isset ($ _GET ['ipp ' ]) ? (int ) $ _GET ['ipp ' ] : null ;
62
- // $this->pageLength->set(preg_replace("/\[ipp\]/", $ipp, $this->label));
63
- $ this ->set ($ ipp ); // @phpstan-ignore-line TODO https://github.com/atk4/ui/issues/2016
63
+ $ this ->set ($ this ->formatInteger ($ ipp ));
64
64
$ reload = $ fx ($ ipp );
65
65
if ($ reload ) {
66
66
$ this ->getApp ()->terminateJson ($ reload );
@@ -71,8 +71,8 @@ public function onPageLengthSelect(\Closure $fx): void
71
71
protected function renderView (): void
72
72
{
73
73
$ menuItems = [];
74
- foreach ($ this ->pageLengthItems as $ key => $ item ) {
75
- $ menuItems [] = ['name ' => $ item , 'value ' => $ item ];
74
+ foreach ($ this ->pageLengthItems as $ item ) {
75
+ $ menuItems [] = ['name ' => $ this -> formatInteger ( $ item) , 'value ' => $ item ];
76
76
}
77
77
78
78
$ function = new JsExpression ('function (value, text, item) {
0 commit comments