Skip to content

Commit bf4dea3

Browse files
author
a.dmitryuk
committed
[feature] Paginator add list size per page
1 parent ba1a6cd commit bf4dea3

File tree

9 files changed

+56
-5
lines changed

9 files changed

+56
-5
lines changed

assets/js/app.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class App {
3232
this.#createModalWindowsForDeleteActions();
3333
this.#createPopovers();
3434
this.#createTooltips();
35+
this.#createPaginator();
3536

3637
document.addEventListener('ea.collection.item-added', () => this.#createAutoCompleteFields());
3738
}
@@ -456,4 +457,18 @@ class App {
456457
});
457458
});
458459
}
460+
461+
#createPaginator() {
462+
document
463+
.querySelectorAll('.list-pagination-counter select[data-ea-paginator-list-size-per-page]')
464+
.forEach((element) => {
465+
element.addEventListener('change', (event) => {
466+
const url = new URL(window.location.href);
467+
url.searchParams.set('size', event.currentTarget.value);
468+
url.searchParams.set('page', '1');
469+
470+
window.location.replace(url.toString());
471+
});
472+
});
473+
}
459474
}

public/app.92065ad6.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

public/app.b25cfb59.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/entrypoints.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"/app.54fc226c.css"
66
],
77
"js": [
8-
"/app.92065ad6.js"
8+
"/app.b25cfb59.js"
99
]
1010
},
1111
"form": {

public/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"app.css": "app.54fc226c.css",
3-
"app.js": "app.92065ad6.js",
3+
"app.js": "app.b25cfb59.js",
44
"form.js": "form.875c88d4.js",
55
"page-layout.js": "page-layout.6e9fe55d.js",
66
"page-color-scheme.js": "page-color-scheme.30cb23c2.js",

src/Config/Crud.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class Crud
3939
private bool $paginatorFetchJoinCollection = true;
4040
private ?bool $paginatorUseOutputWalkers = null;
4141

42+
/** @var int[] */
43+
private array $listSizePerPage = [
44+
10, 20, 30, 40, 50, 100, 150,
45+
];
46+
4247
private function __construct(private readonly CrudDto $dto)
4348
{
4449
}
@@ -326,6 +331,14 @@ public function setPaginatorPageSize(int $maxResultsPerPage): self
326331
return $this;
327332
}
328333

334+
/**
335+
* @param int[] $listSizePerPage
336+
*/
337+
public function setListSizePerPage(array $listSizePerPage): void
338+
{
339+
$this->listSizePerPage = $listSizePerPage;
340+
}
341+
329342
public function setPaginatorRangeSize(int $maxPagesOnEachSide): self
330343
{
331344
if ($maxPagesOnEachSide < 0) {
@@ -439,7 +452,13 @@ public function hideNullValues(bool $hide = true): self
439452

440453
public function getAsDto(): CrudDto
441454
{
442-
$this->dto->setPaginator(new PaginatorDto($this->paginatorPageSize, $this->paginatorRangeSize, 1, $this->paginatorFetchJoinCollection, $this->paginatorUseOutputWalkers));
455+
$this->dto->setPaginator(new PaginatorDto(
456+
$this->paginatorPageSize,
457+
$this->paginatorRangeSize, 1,
458+
$this->listSizePerPage,
459+
$this->paginatorFetchJoinCollection,
460+
$this->paginatorUseOutputWalkers
461+
));
443462

444463
return $this->dto;
445464
}

src/Dto/PaginatorDto.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ final class PaginatorDto
99
{
1010
private ?int $pageNumber = null;
1111

12+
/**
13+
* @param int[] $listSizePerPage
14+
*/
1215
public function __construct(
1316
private readonly int $pageSize,
1417
private readonly int $rangeSize,
1518
private readonly int $rangeEdgeSize,
19+
private readonly array $listSizePerPage,
1620
private readonly bool $fetchJoinCollection,
1721
private readonly ?bool $useOutputWalkers,
1822
) {
@@ -52,4 +56,12 @@ public function useOutputWalkers(): ?bool
5256
{
5357
return $this->useOutputWalkers;
5458
}
59+
60+
/**
61+
* @return int[]
62+
*/
63+
public function getListSizePerPage(): array
64+
{
65+
return $this->listSizePerPage;
66+
}
5567
}

templates/crud/paginator.html.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
<div class="list-pagination">
77
<div class="list-pagination-counter">
8+
<select data-ea-paginator-list-size-per-page class="form-select flex d-inline w-auto me-1">
9+
{% for size in ea.crud.paginator.listSizePerPage %}
10+
<option value="{{ size }}" {{ ea.crud.paginator.pageSize == size ? 'selected' : '' }}>{{ size }}</option>
11+
{% endfor %}
12+
</select>
813
{% if render_detailed_pagination is defined ? render_detailed_pagination : true %}
914
{{ 'paginator.results'|trans({'%count%': paginator.numResults|format})|raw }}
1015
{% endif %}

0 commit comments

Comments
 (0)