Skip to content

Commit f1afc79

Browse files
committed
Add filtration usage doc and missing config options
1 parent 0379d12 commit f1afc79

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

doc/pager/config.md

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ The list of existing options are:
1919
| sortFieldWhitelist | array | [] | SortableSubscriber |
2020
| sortFieldParameterName | string | sort | SortableSubscriber |
2121
| sortDirectionParameterName | string | sort | SortableSubscriber |
22+
| defaultFilterFields | string\|array* | | FiltrationSubscriber |
23+
| filterFieldWhitelist | array | | FiltrationSubscriber |
2224
| filterFieldParameterName | string | filterParam | FiltrationSubscriber |
2325
| filterValueParameterName | string | filterValue | FiltrationSubscriber |
2426

@@ -45,3 +47,8 @@ you have to set `wrap-queries` to `true`. Otherwise you will get an exception wi
4547
Used as default field name for the sorting. It can take an array for sorting by multiple fields.
4648

4749
\* **Attention**: Arrays are only supported for *Doctrine's ORM*.
50+
51+
52+
### `defaultFilterFields`
53+
54+
Used as default field names for the filtration. It can take an array for filtering by multiple fields.

doc/pager/usage.md

+16
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,19 @@ $pagination = $paginator->paginate($query, 1/*page number*/, 20/*limit per page*
9595

9696
The Paginator will add an `ORDER BY` automatically for each attribute for the
9797
`defaultSortFieldName` option.
98+
99+
## Filtering database query results by multiple columns (only Doctrine ORM and Propel)
100+
101+
You can also filter the result of a database query by multiple columns.
102+
For example users should be filtered by lastname or by firstname:
103+
104+
```php
105+
$query = $entityManager->createQuery('SELECT u FROM User');
106+
107+
$pagination = $paginator->paginate($query, 1/*page number*/, 20/*limit per page*/, array(
108+
'defaultFilterFields' => array('u.lastname', 'u.firstname'),
109+
));
110+
```
111+
112+
If the `filterValue` parameter is set, the Paginator will add an `WHERE` condition automatically
113+
for each attribute for the `defaultFilterFields` option. The conditions are `OR`-linked.

0 commit comments

Comments
 (0)