From 8043fb91fea60a1514664d2ff7059c0a6943abc9 Mon Sep 17 00:00:00 2001 From: pxpm Date: Mon, 22 Jun 2026 14:49:23 +0100 Subject: [PATCH 1/2] filter values --- 7.x/crud-filters.md | 82 ++++++++++++++++++++++++++++++ 7.x/crud-operation-list-entries.md | 8 +++ 2 files changed, 90 insertions(+) diff --git a/7.x/crud-filters.md b/7.x/crud-filters.md index f4d2cf14..cb580241 100644 --- a/7.x/crud-filters.md +++ b/7.x/crud-filters.md @@ -116,6 +116,20 @@ CRUD::filter('active') - ```->apply()``` - By chaining **apply()** on a filter after you've specified the filtering logic using `whenActive()` or `whenInactive()`, you immediately call the appropriate closure; in most cases this isn't necessary, because the List operation automatically performs an `apply()` on all filters; but in some cases, where the filtering closures want to stop or change execution, you can use `apply()` to have that logic applied before the next bits of code get executed; +- ```->showFilterValues($value = true)``` - By chaining **showFilterValues()** on a filter you control whether this filter's current value is shown as a badge below the filter navbar. Pass `false` to hide the badge for this specific filter. If not called, the filter inherits the navbar-level or global setting. See [Filter Value Badges](#filter-value-badges). + +```php +CRUD::filter('status')->showFilterValues(); // show badge for this filter +CRUD::filter('notes')->showFilterValues(false); // hide badge for this filter +``` + +- ```->filterValuesLabel('template')``` - By chaining **filterValuesLabel()** on a filter you define a custom label template for the filter badge. Use `:value` as a placeholder for the filter's current display value. If not set, the default format is `Label: Value`. See [Filter Value Badges](#filter-value-badges). + +```php +CRUD::filter('category_id')->filterValuesLabel(':value selected'); // "Electronics selected" +CRUD::filter('price')->filterValuesLabel('$:value'); // "$10 → 100" +``` + #### Other Chained Methods @@ -557,6 +571,74 @@ Inside this file, you'll have:
+ +## Filter Value Badges + +By default, when you select a filter value, the filter dropdown closes and there's no visual indicator of what you're filtering by — you have to re-open the dropdown to see the active value. + +Backpack can show **badges/chips** below the filter navbar that display the active filter values. Each badge shows the filter label and its current value, with an "×" button to quickly remove that filter: + +![Backpack CRUD Filter Badges](https://backpackforlaravel.com/uploads/docs-4-0/filters/filter-badges.png) + +### Enabling Filter Badges + +Filter badges can be enabled at four levels (highest priority first): + +**1. Per filter** — enable or disable badges for a specific filter, with an optional custom label: + +```php +CRUD::filter('status') + ->type('dropdown') + ->values([1 => 'Active', 2 => 'Inactive']) + ->showFilterValues() // enable badge for this filter + ->filterValuesLabel('Status: :value') // custom badge label with :value placeholder + ->whenActive(function($value) { + CRUD::addClause('where', 'status', $value); + }); + +// To hide the badge for a specific filter: +CRUD::filter('notes') + ->type('text') + ->showFilterValues(false); +``` + +**2. Per filters navbar** — when including the navbar standalone: + +```blade +@include('crud::inc.filters_navbar', ['showFilterValues' => true]) +``` + +**3. Per datatable component** — when using the `` component: + +```blade + +``` + +**4. Globally** — in `config/backpack/operations/list.php`: + +```php +'showFilterValues' => true, +``` + +### Custom Badge Labels + +You can customize the badge label for any filter using `filterValuesLabel()`. The `:value` placeholder will be replaced with the filter's current display value: + +```php +CRUD::filter('category_id') + ->type('select2_ajax') + // ... other configuration ... + ->filterValuesLabel(':value selected'); // "Electronics selected" + +CRUD::filter('price') + ->type('range') + ->filterValuesLabel('$:value'); // "$10 → 100" +``` + +For `select2_ajax` filters, the badge automatically shows the human-readable text (not the raw ID), using the `_text` URL parameter that Backpack already stores. + +> **Note:** Filter badges are disabled by default to avoid breaking existing layouts. Enable them explicitly at any level. + ## Examples diff --git a/7.x/crud-operation-list-entries.md b/7.x/crud-operation-list-entries.md index a6e5c11a..9048d08a 100644 --- a/7.x/crud-operation-list-entries.md +++ b/7.x/crud-operation-list-entries.md @@ -119,6 +119,14 @@ To learn more about buttons, **check out the [Buttons](/docs/{{version}}/crud-bu Filters show up right before the actual table, and provide a way for the admin to filter the results in the ListEntries table. To learn more about filters, **check out the [Filters](/docs/{{version}}/crud-filters) documentation page**. Please note that filters are a PRO feature. Check out more differences in [FREE vs PRO](/docs/{{version}}/features-free-vs-paid#features). +You can show the currently active filter values as badges/chips below the filter navbar by enabling `showFilterValues` in the List operation config (`config/backpack/operations/list.php`), or per CRUD: + +```php +CRUD::setOperationSetting('showFilterValues', true); +``` + +See the [Filter Value Badges](/docs/{{version}}/crud-filters#filter-value-badges) section for details. + ### Other Features From 9789ef9f0050a42710c37f90b027fae3bb9db38f Mon Sep 17 00:00:00 2001 From: pxpm Date: Mon, 22 Jun 2026 14:59:53 +0100 Subject: [PATCH 2/2] fix image url --- 7.x/crud-filters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/7.x/crud-filters.md b/7.x/crud-filters.md index cb580241..86f64aca 100644 --- a/7.x/crud-filters.md +++ b/7.x/crud-filters.md @@ -578,7 +578,7 @@ By default, when you select a filter value, the filter dropdown closes and there Backpack can show **badges/chips** below the filter navbar that display the active filter values. Each badge shows the filter label and its current value, with an "×" button to quickly remove that filter: -![Backpack CRUD Filter Badges](https://backpackforlaravel.com/uploads/docs-4-0/filters/filter-badges.png) +![Backpack CRUD Filter Badges](https://backpackforlaravel.com/uploads/docs/filters/filter-badges.png) ### Enabling Filter Badges