Skip to content

Commit

Permalink
bug fix toggle column not working on first time toogling (#1431)
Browse files Browse the repository at this point in the history
* bug fix toggle column not working on first time toogling after refresh browser

* Fix phpstan, add x-clock

---------

Co-authored-by: luanfreitasdev <[email protected]>
  • Loading branch information
jhonoryza and luanfreitasdev authored Feb 29, 2024
1 parent 7fff071 commit 0036907
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class="pg-btn-white dark:ring-pg-primary-600 dark:border-pg-primary-600 dark:hov
</button>

<div
x-cloak
x-show="open"
x-transition:enter="transition ease-out duration-100"
x-transition:enter-start="transform opacity-0 scale-95"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class="pg-btn-white dark:ring-pg-primary-600 dark:border-pg-primary-600 dark:hov
</button>

<div
x-cloak
x-show="open"
x-transition:enter="transition ease-out duration-100"
x-transition:enter-start="transform opacity-0 scale-95"
Expand Down
16 changes: 10 additions & 6 deletions src/Concerns/Listeners.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Livewire\Attributes\On;

/** @codeCoverageIgnore */
/** @codeCoverageIgnore */
trait Listeners
{
#[On('pg:editable-{tableName}')]
Expand All @@ -26,13 +26,17 @@ public function toggleableChanged(string $id, string $field, string $value): voi
#[On('pg:toggleColumn-{tableName}')]
public function toggleColumn(string $field): void
{
foreach ($this->visibleColumns as &$column) {
if (data_get($column, 'field') === $field) {
data_set($column, 'hidden', !data_get($column, 'hidden'));
$this->visibleColumns = $this->visibleColumns->map(function (\stdClass | array $column) use ($field) {
if (is_object($column) && $column->field === $field) {
$column->hidden = !$column->hidden;
}

break;
if (is_array($column) && $column['field'] === $field) {
$column['hidden'] = !$column['hidden'];
}
}

return $column;
});

$this->persistState('columns');
}
Expand Down
2 changes: 1 addition & 1 deletion src/PowerGridComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* @property-read mixed $getCachedData
* @property-read bool $hasColumnFilters
* @property-read array|BaseCollection $visibleColumns
* @property array|BaseCollection $visibleColumns
*/
class PowerGridComponent extends Component
{
Expand Down

0 comments on commit 0036907

Please sign in to comment.