Skip to content

Commit 6f96fca

Browse files
committed
Updates
- Updated search and row click sections of read me to be more clear. - Added resetPage to per page dropdown and filters.
1 parent 30441ec commit 6f96fca

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
1111
### Changed
1212

1313
- Removed calls to custom primary color with indigo
14+
- Updated search and row click sections of read me to be more clear.
15+
- Added resetPage to per page dropdown and filters.
1416

1517
## [1.0.2] - 2021-04-17
1618

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ public function getTableRowUrl($row): string
160160
}
161161
```
162162

163+
**Note:** When you have a clickable row, you might have issues with other clickable items in your cells following the row URL instead of the items action. As of right now I'd advise against using both until there is a better solution.
164+
163165
### Using the included blade components in the row view:
164166

165167
To create cells, you should use the `<x-livewire-tables::table.cell>` table cell component, which will be rendered to:
@@ -326,11 +328,30 @@ The search is a special built-in filter that is managed by the component, but yo
326328
public function query(): Builder
327329
{
328330
return User::query()
329-
->when($this->getFilter('search'), fn ($query, $term) => $query->search($term));
331+
->when($this->getFilter('search'), fn ($query, $term) => $query->where('name', 'like', '%'.$term.'%')->orWhere('email', 'like', '%'.$term.'%'));
332+
}
333+
```
334+
335+
You can make this even more streamlined by adding a search scope to your model like so:
336+
337+
```php
338+
public function scopeSearch($query, $term)
339+
{
340+
return $query->where(
341+
fn ($query) => $query->where('name', 'like', '%'.$term.'%')
342+
->orWhere('email', 'like', '%'.$term.'%')
343+
);
330344
}
331345
```
332346

333-
You can make this even more streamlined by adding a search scope like demonstrated above. Or you can use regular where/orWhere clauses.
347+
And then using it like this:
348+
349+
```php
350+
{
351+
return User::query()
352+
->when($this->getFilter('search'), fn ($query, $term) => $query->search($term));
353+
}
354+
```
334355

335356
### Creating Bulk Actions
336357

src/Traits/WithFilters.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public function resetFilters(): void
2020
$this->filters['search'] = $search;
2121
}
2222

23+
public function updatingFilters(): void
24+
{
25+
$this->resetPage();
26+
}
27+
2328
public function resetAll(): void
2429
{
2530
$this->resetFilters();

src/Traits/WithPerPagePagination.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public function updatedPerPage($value): void
2626
} else {
2727
session()->put($this->tableName.'-perPage', 10);
2828
}
29+
30+
$this->resetPage();
2931
}
3032

3133
public function applyPagination($query)

0 commit comments

Comments
 (0)