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

Small fixes #100

Merged
merged 1 commit into from
May 13, 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
75 changes: 46 additions & 29 deletions docs/table-features/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,21 +548,29 @@ Dynamic Filter lets you use an external component as a PowerGrid Filter. This is
The example below renders the `<x-select>` component in the chosen column header.

```php
// app/Livewire/DishTable.php

use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\Facades\Filter;

public function filters(): array
class DishTable extends PowerGridComponent
{
Filter::dynamic('in_stock', 'in_stock')
->component('select')
->attributes([
'class' => 'min-w-[170px]',
'async-data' => route('categories.index'),
'option-label' => 'name',
'multiselect' => false,
'option-value' => 'id',
'placeholder' => 'Test',
'wire:model.lazy' => 'filters.select.in_stock'
]),
public function filters(): array
{
return [
Filter::dynamic('in_stock', 'in_stock')
->component('select')
->attributes([
'class' => 'min-w-[170px]',
'async-data' => route('categories.index'),
'option-label' => 'name',
'multiselect' => false,
'option-value' => 'id',
'placeholder' => 'Test',
'wire:model.lazy' => 'filters.select.in_stock'
]),
];
}
}
```

Expand All @@ -587,29 +595,38 @@ To create a dependent filter in PowerGrid, you must chain the method `depends()`
In the example below, choosing a category will affect the chef filter, displaying only chefs in the selected category.

```php
use PowerComponents\LivewirePowerGrid\Facades\Filter;
// app/Livewire/DishTable.php

use Illuminate\Database\Eloquent\Builder;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\Facades\Filter;
use App\Models\Chef;

return [
class DishTable extends PowerGridComponent
{
public function filters(): array
{
return [
Filter::select('category_name', 'category_id')
->dataSource(Category::all())
->optionLabel('name')
->optionValue('id'),

Filter::select('chef_name', 'chef_id')
->depends(['category_id'])
->dataSource(fn ($depends) => Chef::query()
->when(isset($depends['category_id']),
fn (Builder $query) => $query->whereRelation('categories',
fn (Builder $builder) => $builder->where('id', $depends['category_id'])
->dataSource(Category::all())
->optionLabel('name')
->optionValue('id'),

Filter::select('chef_name', 'chef_id')
->depends(['category_id'])
->dataSource(fn ($depends) => Chef::query()
->when(isset($depends['category_id']),
fn (Builder $query) => $query->whereRelation('categories',
fn (Builder $builder) => $builder->where('id', $depends['category_id'])
)
)
->get()
)
->get()
)
->optionLabel('name')
->optionValue('id'),
];
->optionLabel('name')
->optionValue('id'),
];
}
}
```

:::info 🌎 Online Demo
Expand Down
16 changes: 8 additions & 8 deletions docs/table-features/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ Sometimes, you may need to change the default URL page parameter (`?page=`). Thi

The example below shows how to use a different pageName for each component.

The component "Customer Page", configured to use ?customerPage=:
The `DishTable` component is set to utilize the `dishPage` parameter, while the `UserTable` component is set to utilize the userPage parameter from the URL: `http://myapp.test/?dishPage=2&usersPage=5`.

```php
::: code-group

```php [DishTable.php]
// app/Livewire/DishTable.php

use PowerComponents\LivewirePowerGrid\PowerGridComponent;
Expand All @@ -129,7 +131,7 @@ class DishTable extends PowerGridComponent
}
```

```php
```php [UserTable.php]
// app/Livewire/UserTable.php

use PowerComponents\LivewirePowerGrid\PowerGridComponent;
Expand All @@ -147,18 +149,16 @@ class UserTable extends PowerGridComponent
}
```

The blade view will look similar to this:

```php
```php [my-view.blade.php]
// resources/views/my-view.blade.php

<div>
<livewire:customers-table />
<livewire:customers-table />// [!code ++:2]
<livewire:users-table />
</div>
```

Consequently, the page url will have both page names: `http://myapp.test/?dishPage=2&usersPage=5`
:::

## Custom Pagination Component

Expand Down
4 changes: 4 additions & 0 deletions docs/table-features/rows.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Here you will find:

To enable checkboxes on Table rows, call the `showCheckBox()` in your Component's `setUp()` method.

By default, `showCheckBox()` reference the field `id`. If you need to reference another field, simply pass the field name to the parameter `$attribute`.

Example:

```php
Expand All @@ -34,6 +36,8 @@ See an interactive example of [Checkboxes](https://demo.livewire-powergrid.com/e

To enable radio buttons on Table rows, call the `showRadioButton()` in your Component's `setUp()` method.

By default, `showRadioButton()` reference the field `id`. If you need to reference another field, simply pass the field name to the parameter `$attribute`.

Example:

```php
Expand Down