Skip to content

Commit 82c4c1c

Browse files
authored
[Bug, EC] PEES-818: Bug: Relation Filter Using Tags (#1041)
* fix * fix * sonar fix * Change grid column width to 300 * Update gridColumnConfig.js
1 parent 7efbc60 commit 82c4c1c

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

public/js/pimcore/element/helpers/gridColumnConfig.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,20 @@ pimcore.element.helpers.gridColumnConfig = {
420420

421421
editor.fieldConfig.width = 300;
422422

423+
const activeFilter = this.grid.getStore().getFilters().items;
424+
425+
for (let filter of activeFilter) {
426+
if (filter.dataIndex !== fieldInfo.dataIndex) {
427+
continue;
428+
}
429+
editor.data = filter.getValue()
430+
.split(",")
431+
.map(v => ({ id: Number.parseInt(v.trim()) }))
432+
.filter(v => !Number.isNaN(v.id));
433+
editor.store.loadData(items, false);
434+
break;
435+
}
436+
423437
const formPanel = Ext.create('Ext.form.Panel', {
424438
xtype: "form",
425439
border: false,
@@ -439,10 +453,25 @@ pimcore.element.helpers.gridColumnConfig = {
439453
iconCls: "pimcore_icon_filter pimcore_icon_overlay_add",
440454
handler: function () {
441455
if (formPanel.isValid() && typeof fieldInfo.getRelationFilter === "function") {
442-
this.grid.filters.getStore().addFilter(
443-
fieldInfo.getRelationFilter(fieldInfo.dataIndex, editor)
444-
);
445-
this.filterByRelationWindow.close();
456+
try {
457+
// Sync editor store with its current value (if applicable)
458+
const value = editor.getValue();
459+
let items = [];
460+
if (Array.isArray(value)) {
461+
items = value;
462+
} else if (value) {
463+
items = [value];
464+
}
465+
editor.store.loadData(items, false);
466+
467+
this.grid.filters.getStore().addFilter(
468+
fieldInfo.getRelationFilter(fieldInfo.dataIndex, editor)
469+
);
470+
this.filterByRelationWindow.close();
471+
} catch (e) {
472+
console.error("Error applying relation filter:", e);
473+
pimcore.helpers.showNotification(t("error"), e.message || e, "error");
474+
}
446475
}
447476
}.bind(this)
448477
}

0 commit comments

Comments
 (0)