Skip to content

Commit

Permalink
Pagination updates (rappasoft#1136)
Browse files Browse the repository at this point in the history
* Pagination Updates
* Updating ChangeLog

---------

Co-authored-by: lrljoe <lrljoe@users.noreply.github.com>
  • Loading branch information
lrljoe and lrljoe authored Mar 31, 2023
1 parent 8a17b57 commit 825621b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
- Set Row for Filter (setFilterSlidedownRow(())
- Set ColSpan for Filter (setFilterSlidedownColspan())
- Workflow (run-phpstan) - Introducing PHP-Stan at Level 3 to ensure code-quality persists - https://github.com/rappasoft/laravel-livewire-tables/pull/1133
- Added getPerPageDisplayedItemIds() and getPerPageDisplayedItemCount() along with public variables to allow retrieval of currently paginated PrimayKey and Item Count https://github.com/rappasoft/laravel-livewire-tables/pull/1136

### Changed

Expand Down
16 changes: 16 additions & 0 deletions docs/pagination/available-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,19 @@ public function configure(): void
$this->setPaginationMethod('simple');
}
```

## getPerPageDisplayedItemIds

Returns the Primary Key for the currently visible rows in an array. This should be used in a blade to ensure accuracy.

```php
$this->getPerPageDisplayedItemIds();
```

## getPerPageDisplayedItemCount

Returns the number of rows that are currently displayed. This should be used in a blade to ensure accuracy.

```php
$this->getPerPageDisplayedItemCount();
```
16 changes: 16 additions & 0 deletions src/Traits/Helpers/PaginationHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,20 @@ public function isPaginationMethod(string $paginationMethod): bool
{
return $this->paginationMethod === $paginationMethod;
}

/**
* @return array<mixed>
*/
public function getPerPageDisplayedItemIds(): array
{
return $this->paginationCurrentItems;
}

/**
* @return int
*/
public function getPerPageDisplayedItemCount(): int
{
return $this->paginationCurrentCount;
}
}
7 changes: 6 additions & 1 deletion src/Traits/WithData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ public function getRows()
{
$this->baseQuery();

return $this->executeQuery();
$executedQuery = $this->executeQuery();

$this->paginationCurrentItems = $executedQuery->pluck($this->getPrimaryKey())->toArray() ?? [];
$this->paginationCurrentCount = $executedQuery->count() ?? 0;

return $executedQuery;
}

protected function baseQuery(): Builder
Expand Down
2 changes: 2 additions & 0 deletions src/Traits/WithPagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ trait WithPagination
public bool $paginationVisibilityStatus = true;
public bool $perPageVisibilityStatus = true;
public string $paginationMethod = 'standard';
public array $paginationCurrentItems = [];
public int $paginationCurrentCount = 0;

// TODO: Test
public function setupPagination(): void
Expand Down
14 changes: 14 additions & 0 deletions tests/Traits/Visuals/PaginationVisualsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,18 @@ public function per_page_dropdown_only_renders_with_accepted_values(): void
Livewire::test(PetsTable::class)
->call('setPerPage', 15);
}

/** @test */
public function can_get_currently_displayed_ids(): void
{
Livewire::test(PetsTable::class)->assertSet('paginationCurrentItems', [1,2,3,4,5])
->assertNotSet('paginationCurrentItems', [1,2,3,4,5,6,7,8,9]);
}

/** @test */
public function can_get_currently_displayed_count(): void
{
Livewire::test(PetsTable::class)->assertSet('paginationCurrentCount', 5)
->assertNotSet('paginationCurrentCount', 125);
}
}

0 comments on commit 825621b

Please sign in to comment.