Skip to content

Commit

Permalink
refix toogle column weird bug, change to columns property as visibleC…
Browse files Browse the repository at this point in the history
…olumns is computed property (#1439)
  • Loading branch information
jhonoryza authored Mar 1, 2024
1 parent 0036907 commit 8d01f53
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/Concerns/Listeners.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@ public function toggleableChanged(string $id, string $field, string $value): voi
#[On('pg:toggleColumn-{tableName}')]
public function toggleColumn(string $field): void
{
$this->visibleColumns = $this->visibleColumns->map(function (\stdClass | array $column) use ($field) {
if (is_object($column) && $column->field === $field) {
$column->hidden = !$column->hidden;
}
foreach ($this->columns as &$column) {
if (data_get($column, 'field') === $field) {
data_set($column, 'hidden', !data_get($column, 'hidden'));

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

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 array|BaseCollection $visibleColumns
* @property-read array|BaseCollection $visibleColumns
*/
class PowerGridComponent extends Component
{
Expand Down

0 comments on commit 8d01f53

Please sign in to comment.