Skip to content

Commit

Permalink
Added functionality to clear TomSelect from the PowerGrid end (#1300)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinheij authored Dec 19, 2023
1 parent 12f82ff commit 7173e29
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/powergrid.js": "/powergrid.js?id=d4bd448250d2689635ac29191651dc76",
"/powergrid.js": "/powergrid.js?id=495809d3974beb1d1566c20a3225b674",
"/bootstrap5.css": "/bootstrap5.css?id=03aba1df82c23db07c1d1096efcd42ae",
"/tailwind.css": "/tailwind.css?id=479d85eb8b0b8341542e0b979c84f17d",
"/tom-select.css": "/tom-select.css?id=7af730d2c4bf937316d4002948b1571d",
Expand Down
2 changes: 1 addition & 1 deletion dist/powergrid.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions resources/js/components/select/tomSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ export default (params) => ({
onChange: (value) => {
storeMultiSelect(params, value)
},
onInitialize: () => {
window.addEventListener(`pg:clear_multi_select::${params.tableName}:${params.dataField}`, () => {
if (element) {
element.tomselect.clear(true)
}
})

window.addEventListener(`pg:clear_all_multi_select::${params.tableName}`, () => {
if (element) {
element.tomselect.clear(true)
}
})
},
}

const asyncConfig = {
Expand Down
5 changes: 3 additions & 2 deletions src/Traits/HasFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function clearFilter(string $field = '', bool $emit = true): void
list($table, $column) = explode('.', $field);

if (isset($this->filters['multi_select'][$table][$column])) {
$this->dispatch('pg:clear_multi_select::' . $this->tableName);
$this->dispatch('pg:clear_multi_select::' . $this->tableName . ':' . $field);
}

if (isset($this->filters['datetime'][$table][$column]) || isset($this->filters['date'][$table][$column])) {
Expand Down Expand Up @@ -88,7 +88,7 @@ public function clearFilter(string $field = '', bool $emit = true): void
}
} else {
if (isset($this->filters['multi_select'][$field])) {
$this->dispatch('pg:clear_multi_select::' . $this->tableName);
$this->dispatch('pg:clear_multi_select::' . $this->tableName . ':' . $field);
}

if (isset($this->filters['datetime'][$field]) || isset($this->filters['date'][$field])) {
Expand Down Expand Up @@ -123,6 +123,7 @@ public function clearAllFilters(): void
$this->persistState('filters');

$this->dispatch('pg:clear_all_flatpickr::' . $this->tableName);
$this->dispatch('pg:clear_all_multi_select::' . $this->tableName);
}

private function resolveFilters(): void
Expand Down

0 comments on commit 7173e29

Please sign in to comment.