Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean/Toggle Filter #1830

Merged
merged 19 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@
/resources/js/partials/filter-date-range.js export-ignore
/resources/js/partials/filter-number-range.js export-ignore
/resources/js/partials/reorder.js export-ignore
/minifyJs export-ignore
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ phpunit.xml.dist.dev
phpunit.xml.bak
phpstan.txt
coverage.xml
./tmp/**
./tmp/**
2 changes: 1 addition & 1 deletion docs/column-types/sum_column.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ weight: 13

Sum columns provide an easy way to display the "Sum" of a field on a relation.

```
```php
SumColumn::make('Total Age of Related Users')
->setDataSource('users','age')
->sortable(),
Expand Down
6 changes: 3 additions & 3 deletions docs/columns/reusable-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ To mitigate the pain of maintaining this, two new methods have been introduced.
These methods both function in exactly the same way as your standard columns(), and expect an array of columns.

Any columns defined in prependColumns() will be the first columns in your list of columns.
```
```php
public function prependColumns(): array
{
return [];
}
```

Any columns defined in appendColumns() will be the last columns in your list of columns.
```
```php
public function appendColumns(): array
{
return [];
Expand All @@ -28,7 +28,7 @@ public function appendColumns(): array
You can call these in your trait, and they will be automatically appended/prepended to tables.

For example, to append a Column for Updated At
```
```php
public function appendColumns(): array
{
return [
Expand Down
39 changes: 39 additions & 0 deletions docs/filter-types/filters-boolean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Boolean Filters (beta)
weight: 2
---

## Beta
This is currently in beta, and will only work with Tailwind.

## Details

The BooleanFilter is designed so that you can toggle a more complex query/filter, as opposed to being a yes/no type of filter (which is what the SelectFilter is perfect for)

For example, your filter may look like this, toggling the filter from true to false would apply/not apply a more complex query to the query.

```php
BooleanFilter::make('Limit to Older Enabled Users')
->filter(function (Builder $builder, bool $enabled) {
if ($enabled)
{
$builder->where('status',true)->where('age', '>', 60);
}
})
```

Many of the standard methods are available, for example
```php
BooleanFilter::make('Limit to Older Enabled Users')
->filter(function (Builder $builder, bool $enabled) {
if ($enabled)
{
$builder->where('status',true)->where('age', '>', 60);
}
})
->setFilterPillValues([
true => 'Active',
false => 'Inactive',
])
->setFilterDefaultValue(true)
```
2 changes: 1 addition & 1 deletion docs/filter-types/filters-date.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Date Filters
weight: 2
weight: 3
---

Date filters are HTML date elements.
Expand Down
26 changes: 13 additions & 13 deletions docs/filter-types/filters-daterange.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: DateRange Filters
weight: 3
weight: 4
---

DateRange filters are Flatpickr based components, and simply filtering by a date range. If you would like to more smoothly filter your query by a start and end date, you can use the DateRangeFilter:
Expand Down Expand Up @@ -70,17 +70,17 @@ A full list of options is below, please see the Flatpickr documentation for refe

You may use this to set a default value for the filter that will be applied on first load (but may be cleared by the user). This should be an array:

```
```php
DateRangeFilter::make('EMail Verified Range')
->setFilterDefaultValue(['minDate' => '2024-05-05', 'maxDate' => '2024-06-06'])
```
or
```
```php
DateRangeFilter::make('EMail Verified Range')
->setFilterDefaultValue(['min' => '2024-05-05', 'max' => '2024-06-06'])
```
or
```
```php
DateRangeFilter::make('EMail Verified Range')
->setFilterDefaultValue(['2024-05-05', '2024-06-06'])
```
Expand Down Expand Up @@ -117,26 +117,26 @@ public function filters(): array
By default, this filter will inject the Flatpickr JS Library and CSS. However, you can customise this behaviour using the configuration file.

### Option 1 - The default behaviour:
```
```php
'inject_third_party_assets_enabled' => true,
```

### Option 2 - Bundled
If you choose to bundle the Tables JS/CSS (recommended) by adding the following to your build process:

```
```js
'vendor/rappasoft/laravel-livewire-tables/resources/js/laravel-livewire-tables-thirdparty.min.js';
```

or in your app.js

```
```js
import '../../vendor/rappasoft/livewire-tables/resources/js/laravel-livewire-tables-thirdparty.min.js';
```

Then you should disable injection to avoid conflicts:

```
```php
'inject_third_party_assets_enabled' => false,
```

Expand All @@ -146,12 +146,12 @@ You must ensure that Flatpickr is present PRIOR to the tables loading. For exam
It is typically recommended not to utilise the CDN approach, as changes to core code may impact behaviour, and you may need to implement changes to your CSP if present.

If using the CDN approach, ensure the following config matches:
```
```js
'inject_third_party_assets_enabled' => false,
```

Then include the following in your layout:
```
```html
// Flatpickr Core Script
<script src="https://npmcdn.com/flatpickr" async></script>

Expand All @@ -161,7 +161,7 @@ Then include the following in your layout:

### Option 4 - Locally Installed
If you have a locally installed version of Flatpickr already, you can set injection to false, and your local version will be used instead.
```
```js
'inject_third_party_assets_enabled' => false,
```

Expand All @@ -170,7 +170,7 @@ The default installation includes only the English (en) locale.

### Bundling
Should you wish to localise, you must include the Flatpickr locale files in your build pipeline. This applies to only the specific locales that you require in your app.js (requires adding the flatpickr library to your package.json by executing "npm i flatpickr --save")
```
```js
import { Arabic } from "../imports/flatpickr/l10n/ar.js";
import { Catalan } from "../imports/flatpickr/l10n/cat.js";
import { Danish } from "../imports/flatpickr/l10n/da.js";
Expand All @@ -192,6 +192,6 @@ import { Ukrainian } from "../imports/flatpickr/l10n/uk.js"
You can also add locales using the Flatpickr CDN, ensuring that these are loaded before the page renders.

For example to add German (de), ensure that the following is in the "head" section of your layout, ideally before your app.js
```
```html
<script src="https://npmcdn.com/flatpickr/dist/l10n/de.js" async></script>
```
2 changes: 1 addition & 1 deletion docs/filter-types/filters-datetime.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: DateTime Filters
weight: 4
weight: 5
---

DateTime filters are HTML datetime-local elements and act the same as date filters.
Expand Down
2 changes: 1 addition & 1 deletion docs/filter-types/filters-livewire-component.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Livewire Custom Filter (Beta)
weight: 11
weight: 12
---

**IN BETA**
Expand Down
2 changes: 1 addition & 1 deletion docs/filter-types/filters-multiselect-dropdown.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Multi-Select Dropdown Filters
weight: 5
weight: 6
---

Multi-select dropdown filters are a simple dropdown list. The user can select multiple options from the list. There is also an 'All' option that will select all values
Expand Down
2 changes: 1 addition & 1 deletion docs/filter-types/filters-multiselect.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Multi-Select Filters
weight: 6
weight: 7
---

Multi-select filters are a list of checkboxes. The user can select multiple options from the list. There is also an 'All' option that will select all values.
Expand Down
2 changes: 1 addition & 1 deletion docs/filter-types/filters-number-range.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: NumberRange Filters
weight: 7
weight: 8
---

NumberRange filters allow for a minimum and maximum value to be input on a single slider.
Expand Down
2 changes: 1 addition & 1 deletion docs/filter-types/filters-number.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Number Filters
weight: 8
weight: 9
---

Number filters are just HTML number inputs.
Expand Down
4 changes: 2 additions & 2 deletions docs/filter-types/filters-select.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Select Filters
weight: 9
weight: 10
---

Select filters are a simple dropdown list. The user selects one choice from the list.
Expand Down Expand Up @@ -54,6 +54,6 @@ public function filters(): array
}
```
To set a default "All" option at the start of the dropdown, you can do so by utilising the
```
```php
->setFirstOption('NAME')
```
2 changes: 1 addition & 1 deletion docs/filter-types/filters-text.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Text Filters
weight: 10
weight: 11
---

Text filters are just simple text filters, allowing you to pass a string value into a builder query.
Expand Down
3 changes: 3 additions & 0 deletions docs/filter-types/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ weight: 1
There are several Filter types available for use, offering a range of capabilities to filter your data.

<ul>
<li>
<a href="https://rappasoft.com/docs/laravel-livewire-tables/v3/filter-types/filters-boolean">Boolean Filter</a>
</li>
<li>
<a href="https://rappasoft.com/docs/laravel-livewire-tables/v3/filter-types/filters-date">Date Filter</a>
</li>
Expand Down
10 changes: 4 additions & 6 deletions docs/filters/available-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ You may override this using the following methods, on any of the above Filter ty

#### setWireBlur()
Forces the filter to use a wire:model.blur approach
```
```php
TextFilter::make('Name')
->config([
'placeholder' => 'Search Name',
Expand All @@ -426,7 +426,7 @@ Forces the filter to use a wire:model.blur approach

#### setWireDefer()
Forces the filter to use a wire:model approach
```
```php
TextFilter::make('Name')
->config([
'placeholder' => 'Search Name',
Expand All @@ -437,7 +437,7 @@ Forces the filter to use a wire:model approach

#### setWireLive()
Forces the fitler to use a wire:model.live approach
```
```php
TextFilter::make('Name')
->config([
'placeholder' => 'Search Name',
Expand All @@ -448,13 +448,11 @@ Forces the fitler to use a wire:model.live approach

#### setWireDebounce(int $debounceDelay)
Allows you to pass a string to use a wire:model.live.debounce.Xms approach
```
```
```php
TextFilter::make('Name')
->config([
'placeholder' => 'Search Name',
'maxlength' => '25',
])
->setWireDebounce(50)
```
```
4 changes: 2 additions & 2 deletions docs/misc/saving-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ weight: 6
There may be occasions that you'd like to save the table state, for example if you have a complex set of filters, search parameters, or simply to remember which page you were on!

You may call the following method to retrieve the state of the table:
```
```php
$this->getTableStateToArray();
```

And to restore it, you should call the following method, passing the stored array.
```
```php
$this->restoreStateFromArray(array $storedArray)
```
6 changes: 6 additions & 0 deletions minifyJs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
minify ./resources/js/partials/filter-boolean.js > ./resources/js/partials/filter-boolean.min.js \
&& minify ./resources/js/partials/filter-date-range.js > ./resources/js/partials/filter-date-range.min.js \
&& minify ./resources/js/partials/filter-number-range.js > ./resources/js/partials/filter-number-range.min.js \
&& minify ./resources/js/partials/reorder.js > ./resources/js/partials/reorder.min.js \
&& minify ./resources/js/partials/tableWrapper.js > ./resources/js/partials/tableWrapper.min.js \
&& minify ./resources/js/laravel-livewire-tables.js > ./resources/js/laravel-livewire-tables.min.js
Loading
Loading