Download the PHP package pugx/filter-bundle without Composer
On this page you can find all versions of the php package pugx/filter-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package filter-bundle
PUGX FilterBundle
The purpose of this bundle is providing a way to get some filters, that stay in session, to be able to use them when displaying a list of items. It also supports sorting.
- Setup
- Basic Usage
- Form Example
- Sorting
- Translation
- JavaScript
- Helpers
Setup
Run composer require pugx/filter-bundle
. No configuration is required.
Basic Usage
Inject provided service in your controller and use it with a form.
Your form should use GET
as method, use some fields that make sense on your list of item,
and not use CSRF protection.
First step is to save filter with a name (if form is submitted). Then, you can get
a key/value array in $filter->filter('foo')
, where "foo" is the name you provided above.
Using such array to retrieve filtered value is up to you: this bundle makes no assumptions on your domain and doesn't do magic.
Here is an example:
Form Example
Sorting
You can use provided Twig extension for column sorting functionality.
Example of template:
You need to provide a route/action to perform sorting, using $filter->sort('foo', $field, $direction)
.
Then, you'll find an addtional value inside your filter array, like this:
You can use this value to perform your sorting (again, this is up to you and it depends on your domain logic).
Translation
Translations are available (for now, only for English/French/Italian).
If you're using Symfony 4.4+, translatons should be automatically discovered.
On older Symfony versions, add this to your configuration:
JavaScript
A jQuery helper is provided, to enhance UX. You can use it by requiring the following line in your package.json file:
Then you can do something like the following:
The basic results will be that icon in the toggle button will be toggled along, and the arrow will point to right when filters are shown (and back to bottom when filters are collapsed).
You can pass an option object to pugxFilter
function.
Currently supported options are:
callbackHide
a callback to be used when filters are collapsedcallbackShow
a callback to be used when filters are shown
If you prefer vanilla js with Bootstrap, you can use the following snippet:
Helpers
Following helper functions are available as functions in twig templates:
filter_has
: tells if a filter is enabled (e.g. if a session for filter exists)filter_is
: tells if a filter field is selectedfilter_is_not
: tells if a filter field is not selected
All versions of filter-bundle with dependencies
symfony/config Version ^6.4 || ^7.0
symfony/dependency-injection Version ^6.4 || ^7.0
symfony/form Version ^6.4 || ^7.0
symfony/http-kernel Version ^6.4 || ^7.0
twig/twig Version ^3.8