Skip to content

Commit

Permalink
Merge pull request #1503 from moonshine-software/column-selection-hid…
Browse files Browse the repository at this point in the history
…e-on-init

feat: ColumnSelection with hideOnInit argument
  • Loading branch information
lee-to authored Jan 26, 2025
2 parents 97e5c23 + 72620c7 commit a0139ed
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Contracts/src/UI/FieldContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public function changePreview(Closure $callback): static;

public function isPreviewChanged(): bool;

public function columnSelection(bool $active = true): static;
public function columnSelection(bool $active = true, bool $hideOnInit = false): static;

public function isColumnSelection(): bool;

public function isColumnHideOnInit(): bool;

public function sticky(): static;

public function isStickyColumn(): bool;
Expand Down
2 changes: 1 addition & 1 deletion src/UI/dist/assets/app.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/UI/resources/js/Components/TableBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ export default (

this.block.querySelectorAll('[data-column-selection-checker]').forEach(el => {
let stored = localStorage.getItem(this.getColumnSelectionStoreKey(el))
let hideOnInit = this.table?.querySelector(`[data-column-selection="${el.dataset?.column}"]`)
?.dataset.columnSelectionHideOnInit

if (stored === null && hideOnInit) {
stored = 'false'
}

el.checked = stored === null || stored === 'true'
this.columnSelection(el)
Expand Down
1 change: 1 addition & 0 deletions src/UI/src/Components/Table/TableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ private function resolveHeadRow(): TableRowContract
$cells->push(
TableTh::make($thContent, $index)
->customAttributes(['data-column-selection' => $field->getIdentity()])
->customAttributes(['data-column-selection-hide-on-init' => $field->isColumnHideOnInit()])
->customAttributes(['class' => $field->isStickyColumn() ? $this->getStickyClass() : ''])
->customAttributes($tdAttributes($index)),
);
Expand Down
10 changes: 9 additions & 1 deletion src/UI/src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ abstract class Field extends FormElement implements FieldContract

protected bool $columnSelection = true;

protected bool $columnHideOnInit = false;

protected bool $stickyColumn = false;

protected bool $nullable = false;
Expand Down Expand Up @@ -117,9 +119,10 @@ public function isPreviewChanged(): bool
}


public function columnSelection(bool $active = true): static
public function columnSelection(bool $active = true, bool $hideOnInit = false): static
{
$this->columnSelection = $active;
$this->columnHideOnInit = $hideOnInit;

return $this;
}
Expand All @@ -129,6 +132,11 @@ public function isColumnSelection(): bool
return $this->columnSelection;
}

public function isColumnHideOnInit(): bool
{
return $this->columnHideOnInit;
}

public function sticky(): static
{
$this->stickyColumn = true;
Expand Down

0 comments on commit a0139ed

Please sign in to comment.