Skip to content

Commit bb260af

Browse files
committed
Document grid view customization
1 parent e95e86a commit bb260af

File tree

2 files changed

+79
-2
lines changed

2 files changed

+79
-2
lines changed

docs/php/api/grid_views.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,83 @@ class ExampleGridView extends AbstractGridView
308308
Grid Views and List Views share the same filters.
309309
A complete list of available filters can be found in the [List View documentation](list_views.md#filtering).
310310

311+
## Customization
312+
313+
### Number of Items
314+
315+
By default, grid views use a pagination that shows 20 rows per page. You can set a custom number of rows per page:
316+
317+
```php
318+
class ExampleGridView extends AbstractGridView
319+
{
320+
public function __construct()
321+
{
322+
$this->setRowsPerPage(50);
323+
}
324+
}
325+
```
326+
327+
328+
### Additional Parameters
329+
330+
A grid view can be provided with additional parameters, e.g. to filter them by a specific category:
331+
332+
```php
333+
class ExampleGridView extends AbstractGridView
334+
{
335+
public function __construct(public readonly int $categoryID)
336+
{
337+
parent::__construct();
338+
}
339+
340+
#[\Override]
341+
protected function createObjectList(): DatabaseObjectList
342+
{
343+
$list = new ExampleList();
344+
$list->getConditionBuilder()->add('categoryID = ?', [$this->categoryID]);
345+
346+
return $list;
347+
}
348+
349+
#[\Override]
350+
public function getParameters(): array
351+
{
352+
return ['categoryID' => $this->categoryID];
353+
}
354+
}
355+
```
356+
357+
```php
358+
class ExampleListPage extends AbstractGridViewPage
359+
{
360+
public int $categoryID = 0;
361+
362+
#[\Override]
363+
public function readParameters()
364+
{
365+
parent::readParameters();
366+
367+
if (isset($_REQUEST['categoryID'])) {
368+
$this->categoryID = \intval($_REQUEST['categoryID']);
369+
}
370+
}
371+
372+
#[\Override]
373+
protected function createGridView(): AbstractGridView
374+
{
375+
return new ExampleGridView($this->categoryID);
376+
}
377+
378+
#[\Override]
379+
protected function getBaseUrlParameters(): array
380+
{
381+
return [
382+
'categoryID' => $this->categoryID,
383+
];
384+
}
385+
}
386+
```
387+
311388
## Events
312389

313390
Existing grid views can be modified using events.

docs/php/api/list_views.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,11 @@ class ExampleListPage extends AbstractListViewPage
359359
#[\Override]
360360
public function readParameters()
361361
{
362+
parent::readParameters();
363+
362364
if (isset($_REQUEST['categoryID'])) {
363365
$this->categoryID = \intval($_REQUEST['categoryID']);
364366
}
365-
366-
parent::readParameters();
367367
}
368368

369369
#[\Override]

0 commit comments

Comments
 (0)