You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: 7.x-dev/crud-filters.md
+95-1
Original file line number
Diff line number
Diff line change
@@ -621,6 +621,100 @@ CRUD::filter('trashed')
621
621
<aname="tips-and-tricks"></a>
622
622
## Tips and Tricks
623
623
624
+
<aname="using-filters-on-admin-page"></a>
625
+
### Use Filters on custom admin panel pages
626
+
627
+
Filters can be added to any admin panel page, not just the main CRUD table. Imagine that you want to have a dashboard page, with a few widgets that show some data. You can add filters to that page, and use them to filter the data shown in the widgets.
You start by [creating a new page](/docs/{{version}}/base-about#custom-pages-1) to hold your custom content, eg: a reports page.
633
+
634
+
```bash
635
+
php artisan backpack:page Reports
636
+
```
637
+
638
+
To use filters on a custom admin panel page, you should edit the blade file (in this example the `resources/views/admin/reports.blade.php` file) to **add the filters navbar** and **the event listeners**:
That's it, you should now have the filters navbar on your reports page. You can use the event listeners to update the data shown on the page based on the filters selected by the user.
713
+
Here are the Javascript events you can listen to:
714
+
-`backpack:filter:changed` when a filter is changed;
715
+
-`backpack:filter:cleared` when a filter is cleared;
716
+
-`backpack:filters:cleared` when all filters are cleared;
717
+
624
718
<aname="debouncing-filters"></a>
625
719
### Add a debounce time to filters
626
720
@@ -639,7 +733,7 @@ CRUD::filter('name')
639
733
All filter types accept a `debounce`, like for example the simple filter, range filter etc.
640
734
641
735
<aname="adding-a-filter-using-array-syntax"></a>
642
-
### Adding a filter using array syntax
736
+
### Add a filter using array syntax
643
737
644
738
In Backpack v4-v5 we used an "array syntax" to add and manipulate filters. That syntax is still supported for backwards-compatiblity. But it most cases it's easier to use the fluent syntax.
Starting with this Backpack version, you can use the [filters](/docs/{{version}}/crud-filters) in custom pages too. Instead of being tied to DataTables, filters now trigger generic Javascript events like `backpack:filter:changed`. You can catch those events using custom code in Javascript or Livewire... and do stuff. This it possible to use filters on completely custom pages - like custom dashboards, custom reports or custom operations. [Read more](/docs/{{version}}/crud-filters#use-filters-on-custom-admin-panel-pages).
0 commit comments