Skip to content

Commit d52cee2

Browse files
[Grid Options] Fixes for saving grid configuration with "save filters" (#963)
* saved grid column config with "save filters": - restore filters after loading - store "save filters" in database - add translation for "save filters" * make it not requiring a migration in the core, revert part that display the clear filter button * "critical" sonarcloud fix --------- Co-authored-by: Ji Jia Jia <[email protected]> (cherry picked from commit 23a65cc)
1 parent 897cd06 commit d52cee2

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

public/js/pimcore/element/helpers/gridConfigDialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ pimcore.element.helpers.gridConfigDialog = Class.create({
285285

286286
this.saveFilters = new Ext.form.field.Checkbox(
287287
{
288-
fieldLabel: "Save filters",
288+
fieldLabel: t("save_filters"),
289289
inputValue: true,
290290
name: "saveFilters",
291291
value: this.settings.saveFilters

public/js/pimcore/object/folder/search.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,19 @@ pimcore.object.search = Class.create(pimcore.object.helpers.gridTabAbstract, {
283283
let col = gridColumns[i];
284284
if (col.filter) {
285285
needGridFilter = true;
286-
break;
286+
287+
if (this.filter) {
288+
const filterValue = this.filter.find(filter => filter.property === col.dataIndex)?.value || null;
289+
if (filterValue) {
290+
if (typeof col.filter !== "object") {
291+
col.filter = { type: col.filter };
292+
}
293+
294+
col.filter.value = filterValue;
295+
}
296+
} else {
297+
break;
298+
}
287299
}
288300
}
289301
}
@@ -340,11 +352,11 @@ pimcore.object.search = Class.create(pimcore.object.helpers.gridTabAbstract, {
340352

341353
if (this.filter) {
342354
this.filter.forEach(filt => {
343-
this.store.setFilters(new Ext.util.Filter(filt))
344355
this.filterUpdateFunction(this.grid, this.toolbarFilterInfo, this.clearFilterButton);
345356
});
346357
}
347358

359+
348360
this.grid.on("columnmove", function () {
349361
this.saveColumnConfigButton.show()
350362
}.bind(this));

src/Model/GridConfig.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class GridConfig extends AbstractModel
4545

4646
protected bool $setAsFavourite = false;
4747

48-
protected bool $saveFilters = false;
48+
protected ?bool $saveFilters = null;
4949

5050
protected string $type = 'object';
5151

@@ -199,6 +199,16 @@ public function setSetAsFavourite(bool $setAsFavourite): void
199199

200200
public function isSaveFilters(): bool
201201
{
202+
if ($this->saveFilters === null) {
203+
$config = json_decode($this->getConfig());
204+
205+
if (isset($config->filter)) {
206+
$this->saveFilters = (bool) $config->filter;
207+
} else {
208+
$this->saveFilters = false;
209+
}
210+
}
211+
202212
return $this->saveFilters;
203213
}
204214

src/Model/GridConfig/Dao.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public function save(): int
5757
}
5858
}
5959

60+
if (!$gridconfigs['saveFilters']) {
61+
$configData = json_decode($data['config'], true);
62+
unset($configData['filter']);
63+
$data['config'] = json_encode($configData);
64+
}
65+
6066
$lastInsertId = Helper::upsert($this->db, 'gridconfigs', $data, $this->getPrimaryKey('gridconfigs'));
6167
if ($lastInsertId !== null && !$this->model->getId()) {
6268
$this->model->setId((int) $lastInsertId);

translations/admin.en.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ restrict_to_locales: 'Restrict to locales'
581581
predefined: Predefined
582582
save_as_copy: 'Save as copy'
583583
set_as_favourite: 'Set as favourite'
584+
save_filters: Save filters
584585
grid_configuration: 'Grid Configuration'
585586
shared_users: 'Shared Users'
586587
shared_roles: 'Shared Roles'

0 commit comments

Comments
 (0)