|
4 | 4 | [](https://packagist.org/packages/digital-creative/nova-mega-filter)
|
5 | 5 | [](https://github.com/dcasia/nova-mega-filter/blob/master/LICENSE)
|
6 | 6 |
|
7 |
| -This package allows you to control the columns and filters shown on your nova resources. |
| 7 | +Display all your filters in a card instead of a tiny dropdown! |
| 8 | + |
| 9 | +<picture> |
| 10 | + <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/dcasia/nova-mega-filter/nova4/screenshots/dark.png"> |
| 11 | + <img alt="Nova Mega Filter in Action" src="https://raw.githubusercontent.com/dcasia/nova-mega-filter/nova4/screenshots/light.png"> |
| 12 | +</picture> |
8 | 13 |
|
9 | 14 | # Installation
|
10 | 15 |
|
11 | 16 | You can install the package via composer:
|
12 | 17 |
|
13 |
| -``` |
| 18 | +```shell |
14 | 19 | composer require digital-creative/nova-mega-filter
|
15 | 20 | ```
|
16 | 21 |
|
17 | 22 | ## Basic Usage
|
18 | 23 |
|
19 |
| -Basic demo showing the power of this field: |
| 24 | +Basic demo showing the power of this package: |
20 | 25 |
|
21 | 26 | ```php
|
22 | 27 |
|
23 | 28 | use DigitalCreative\MegaFilter\MegaFilter;
|
24 |
| -use DigitalCreative\MegaFilter\HasMegaFilterTrait; |
25 |
| -use DigitalCreative\MegaFilter\Column; |
| 29 | +use DigitalCreative\MegaFilter\MegaFilterTrait; |
26 | 30 |
|
27 | 31 | class ExampleNovaResource extends Resource {
|
28 | 32 |
|
29 |
| - use HasMegaFilterTrait; // Important!! |
| 33 | + use MegaFilterTrait; |
30 | 34 |
|
31 |
| - public function cards(Request $request) |
| 35 | + public function filters(RequestRequest $request): array |
32 | 36 | {
|
33 | 37 | return [
|
34 | 38 | MegaFilter::make([
|
35 |
| - 'filters' => [ |
36 |
| - new DateOfBirthFilter(), |
37 |
| - new UserTypeFilter() |
38 |
| - ], |
39 |
| - 'columns' => [ |
40 |
| - Column::make('Customer Name', 'name')->addFilter(new ActiveFilter()), |
41 |
| - Column::make('Assets'), |
42 |
| - Column::make('Payments') |
43 |
| - ] |
44 |
| - ]) |
| 39 | + DateOfBirthFilter::make(), |
| 40 | + UserTypeFilter::make(), |
| 41 | + ]), |
45 | 42 | ];
|
46 | 43 | }
|
47 | 44 |
|
48 | 45 | }
|
49 | 46 | ```
|
50 | 47 |
|
51 |
| -### Columns |
52 |
| - |
53 |
| -Columns reflects every column that is normally shown on your table resource, however you are free to give your user the |
54 |
| -ability to toggle it on/off: |
55 |
| - |
56 |
| - |
57 |
| - |
58 |
| -```php |
59 |
| -use DigitalCreative\MegaFilter\Column; |
60 |
| -use DigitalCreative\MegaFilter\HasMegaFilterTrait; |
61 |
| -use DigitalCreative\MegaFilter\MegaFilter; |
62 |
| - |
63 |
| -MegaFilter::make([ |
64 |
| - 'columns' => [ |
65 |
| - Column::make($label), |
66 |
| - Column::make($label, $attribute), |
67 |
| - Column::make($label, $attribute, $filters), |
68 |
| - new Column($label, $attribute, $filters), |
69 |
| - ], |
70 |
| -]) |
71 |
| -``` |
72 |
| - |
73 |
| -You can add additional filters that only appears when the desired column is enabled: |
74 |
| - |
75 |
| -```php |
76 |
| -MegaFilter::make([ |
77 |
| - 'columns' => [ |
78 |
| - Column::make('Gender')->addFilter(new GenderFilter()) |
79 |
| - ], |
80 |
| -]) |
81 |
| -``` |
82 |
| - |
83 |
| - |
| 48 | +And you are done! |
84 | 49 |
|
85 |
| -> If you want to have filters that are always shown, use the 'filters' option bellow |
| 50 | +Previously this package also had the ability to toggle columns, but since the nova 4 upgrade this functionality has been |
| 51 | +moved away to its own package: https://github.com/dcasia/column-toggler |
86 | 52 |
|
87 |
| -You can also define columns that can not be toggled by the user and will be always present on the table resource: |
88 |
| - |
89 |
| -```php |
90 |
| -MegaFilter::make([ |
91 |
| - 'columns' => [ |
92 |
| - Column::make('Name')->permanent() |
93 |
| - ], |
94 |
| -]) |
95 |
| -``` |
| 53 | +--- |
96 | 54 |
|
97 |
| -When using `->permanent()` every filter that the column may define will be also present |
98 |
| - |
99 |
| -Other column methods include the ability to have a column default checked |
| 55 | +You can also add other fields alongside your Mega Filters, they will be rendered as usual: |
100 | 56 |
|
101 | 57 | ```php
|
102 |
| -MegaFilter::make([ |
103 |
| - 'columns' => [ |
104 |
| - Column::make('Name')->checked() // Checked by default |
105 |
| - ], |
106 |
| -]) |
107 |
| -``` |
108 |
| - |
109 |
| -### Filters |
110 | 58 |
|
111 |
| -The `filters` key accepts an array of any instance of the default Nova filter class or third party. |
112 |
| - |
113 |
| -```php |
114 |
| -MegaFilter::make([ |
115 |
| - 'filters' => [ |
116 |
| - new BirthdayFilter(), |
117 |
| - new UserTypeFilter(), |
118 |
| - new GenderFilter(), |
119 |
| - ], |
120 |
| -]) |
121 |
| -``` |
122 |
| - |
123 |
| -### Actions |
124 |
| - |
125 |
| -Actions will use the same Nova action mechanism |
126 |
| - |
127 |
| -```php |
128 |
| -MegaFilter::make([ |
129 |
| - 'actions' => [ |
130 |
| - new ExportClientAsExcell(), |
131 |
| - ], |
132 |
| -]) |
133 |
| -``` |
134 |
| - |
135 |
| - |
136 |
| - |
137 |
| -If you have multiple actions defined, a dropdown will be shown: |
138 |
| - |
139 |
| - |
140 |
| - |
141 |
| -The columns selected will also be given to your action, you can access them directly from the request: |
| 59 | +use DigitalCreative\MegaFilter\MegaFilter; |
| 60 | +use DigitalCreative\MegaFilter\MegaFilterTrait; |
142 | 61 |
|
143 |
| -```php |
144 |
| -public function handle(ActionFields $fields, Collection $models) |
145 |
| -{ |
| 62 | +class ExampleNovaResource extends Resource { |
146 | 63 |
|
147 |
| - $columns = json_decode(request()->input('columns')); |
| 64 | + use MegaFilterTrait; |
148 | 65 |
|
149 |
| - dd($columns); |
| 66 | + public function filters(RequestRequest $request): array |
| 67 | + { |
| 68 | + return [ |
| 69 | + MegaFilter::make([ ... ]), |
| 70 | + |
| 71 | + // These will be rendered as normal on the usual tiny filter dropdown |
| 72 | + DateOfBirthFilter::make(), |
| 73 | + UserTypeFilter::make(), |
| 74 | + ]; |
| 75 | + } |
150 | 76 |
|
151 | 77 | }
|
152 | 78 | ```
|
153 | 79 |
|
154 |
| -### Settings |
155 |
| - |
156 |
| -The settings key is optional as it comes with some good defaults, but feel free to override it to suit your needs. |
157 |
| - |
158 |
| -```php |
159 |
| -MegaFilter::make([ |
160 |
| - 'settings' => [ |
161 |
| - |
162 |
| - /** |
163 |
| - * Tailwind width classes: w-full w-1/2 w-1/3 w-1/4 etc. |
164 |
| - */ |
165 |
| - 'columnsWidth' => 'w-1/4', |
166 |
| - 'filtersWidth' => 'w-1/2', |
167 |
| - |
168 |
| - /** |
169 |
| - * The default state of the main toggle buttons |
170 |
| - */ |
171 |
| - 'columnsActive' => false, |
172 |
| - 'filtersActive' => true, |
173 |
| - 'actionsActive' => true, |
174 |
| - |
175 |
| - /** |
176 |
| - * Show/Hide elements |
177 |
| - */ |
178 |
| - 'showHeader' => true, |
179 |
| - |
180 |
| - /** |
181 |
| - * Labels |
182 |
| - */ |
183 |
| - 'headerLabel' => 'Menu', |
184 |
| - 'columnsLabel' => 'Columns', |
185 |
| - 'filtersLabel' => 'Filters', |
186 |
| - 'actionsLabel' => 'Actions', |
187 |
| - 'columnsSectionTitle' => 'Additional Columns', |
188 |
| - 'filtersSectionTitle' => 'Filters', |
189 |
| - 'actionsSectionTitle' => 'Actions', |
190 |
| - 'columnsResetLinkTitle' => 'Reset Columns', |
191 |
| - 'filtersResetLinkTitle' => 'Reset Filters', |
192 |
| - |
193 |
| - ], |
194 |
| -]) |
195 |
| -``` |
| 80 | +> Note: At the moment this package only works with a single Mega Filter per resource, adding multiple on the same resource may result in unexpected behavior. |
196 | 81 |
|
197 | 82 | ## License
|
198 | 83 |
|
|
0 commit comments