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: docs/table-features/filters.md
+128-1Lines changed: 128 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -722,11 +722,138 @@ class DishTable extends PowerGridComponent
722
722
}
723
723
```
724
724
725
+
## Default Filter Values
726
+
727
+
PowerGrid allows you to set default values for filters. These values will be applied automatically when the table loads, filtering the data before displaying it to the user.
728
+
729
+
### Usage
730
+
731
+
Use the `default()` method to set a default value for any filter.
732
+
733
+
```php
734
+
use PowerComponents\LivewirePowerGrid\Facades\Filter;
735
+
736
+
public function filters(): array
737
+
{
738
+
return [
739
+
Filter::select('category_name', 'category_id')
740
+
->dataSource(Category::all())
741
+
->optionLabel('name')
742
+
->optionValue('id')
743
+
->default(1), // [!code ++]
744
+
745
+
Filter::boolean('in_stock')
746
+
->label('In Stock', 'Out of Stock')
747
+
->default(true), // [!code ++]
748
+
];
749
+
}
750
+
```
751
+
752
+
---
753
+
754
+
### Supported Filter Types
755
+
756
+
The following filter types support default values:
757
+
758
+
#### Select Filter
759
+
760
+
```php
761
+
Filter::select('category_name', 'category_id')
762
+
->dataSource(Category::all())
763
+
->optionLabel('name')
764
+
->optionValue('id')
765
+
->default(1), // Single value matching the optionValue
|`inputText`| String or array with `value` and `operator` keys |
846
+
|`number`| Number or array with `start` and `end` keys |
847
+
|`datepicker`| Array with `start` and `end` keys |
848
+
|`datetimepicker`| Array with `start` and `end` keys |
849
+
850
+
---
851
+
725
852
## Custom Components
726
853
727
854
If you need to further customize your filters, you may render Blade Components with the Filter. This is useful when working with external packages like [WireUI](https://livewire-wireui.com/).
728
855
729
-
To render a component, chain the `component()` method to your Filter passing the Blade View and the attributes you may want to use in your component(E.g, wire:model or classes).
856
+
To render a component, chain the `component()` method to your Filter passing the Blade View and the attributes you may want to use in your component(E.g., wire:model or classes).
730
857
731
858
To use default PowerGrid attributes, just call `$attributes->getAttributes()` within your component.
0 commit comments