Skip to content

Commit

Permalink
Add rowsRetrieved Lifecycle Hook (#1578)
Browse files Browse the repository at this point in the history
* Add AddRowsRetrievedHook, update ChangeLog

---------

Co-authored-by: lrljoe <[email protected]>
  • Loading branch information
lrljoe and lrljoe authored Dec 4, 2023
1 parent a5fb5d3 commit 55f7d36
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@

All notable changes to `laravel-livewire-tables` will be documented in this file

## UNRELEASED
## [v3.1.4] - 2023-12-04
### New Features
- Add capability to hide Column Label by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1512
- Add capability to set a custom script path for the scripts/styles by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1557
- Added rowsRetrieved Lifecycle Hook, expanded documentation for Lifecycle Hooks

### Bug Fixes
- Added missing tailwind background colour class for when hovering over the clear button in dark mode by @slakbal in https://github.com/rappasoft/laravel-livewire-tables/pull/1553
- Add capability to hide Column Label by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1512
- Revert previous splitting of JS Files
- Create additional Exception Classes (NoColumnsException, NoSearchableColumnsException, NoSortableColumnsException)
- Fixed extraneous space in config.php by @viliusvsx in in https://github.com/rappasoft/laravel-livewire-tables/pull/1577
- Changed table default vertical overflow to auto by @dmyers in https://github.com/rappasoft/laravel-livewire-tables/pull/1573
- Fix footer rendering issue with extra td displayed depending on bulk action statuses

### Tweaks
- Create additional Exception Classes (NoColumnsException, NoSearchableColumnsException, NoSortableColumnsException)
- Revert previous splitting of JS Files

## [v3.1.3] - 2023-11-03
- Add additional Lifecycle Hook by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1534
- SettingColumns/ColumnsSet
Expand Down
25 changes: 25 additions & 0 deletions docs/misc/lifecycle-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ weight: 7

With the migration to Livewire 3, there we are implementing several Lifecycle Hooks to assist with re-using methods across multiple Table Components.

You may use these either in your Table Component, or in a trait

## configuring
This is called immediately prior to the configure() method being called

Expand All @@ -16,3 +18,26 @@ This is called prior to setting up the available Columns via the columns() metho

## columnsSet
This is called immediately after the Columns are set up

## rowsRetrieved
This is called immediately after the query is executed, and is passed the result from the executed query.

## Use in Traits
To use these in a trait, append the Lifecycle Hook with your trait name, e.g.

```php
trait StandardTableMethods
{

protected function configuringStandardTableMethods()
{
// Your standard configure() options go here, anything set here will be over-ridden by the configure() method
}

protected function configuredStandardTableMethods()
{
// Your standard configure() options go here, anything set here will override those set in the configure() method
}

}
```
6 changes: 6 additions & 0 deletions src/Traits/WithData.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ trait WithData
// TODO: Test
public function getRows(): Collection|CursorPaginator|Paginator|LengthAwarePaginator
{
// Setup the Base Query
$this->baseQuery();

// Execute the Query
$executedQuery = $this->executeQuery();

// Get All Currently Paginated Items Primary Keys
Expand All @@ -27,6 +29,10 @@ public function getRows(): Collection|CursorPaginator|Paginator|LengthAwarePagin
// Get Count of Items in Current Page
$this->paginationCurrentCount = $executedQuery->count();

// Fire hook for rowsRetrieved
$this->callHook('rowsRetrieved', [$executedQuery]);
$this->callTraitHook('rowsRetrieved', [$executedQuery]);

return $executedQuery;
}

Expand Down

0 comments on commit 55f7d36

Please sign in to comment.