diff --git a/public/js/pimcore/element/helpers/gridColumnConfig.js b/public/js/pimcore/element/helpers/gridColumnConfig.js index 8b6d5c022..fa72b2179 100644 --- a/public/js/pimcore/element/helpers/gridColumnConfig.js +++ b/public/js/pimcore/element/helpers/gridColumnConfig.js @@ -420,6 +420,20 @@ pimcore.element.helpers.gridColumnConfig = { editor.fieldConfig.width = 300; + const activeFilter = this.grid.getStore().getFilters().items; + + for (let filter of activeFilter) { + if (filter.dataIndex !== fieldInfo.dataIndex) { + continue; + } + editor.data = filter.getValue() + .split(",") + .map(v => ({ id: Number.parseInt(v.trim()) })) + .filter(v => !Number.isNaN(v.id)); + editor.store.loadData(items, false); + break; + } + const formPanel = Ext.create('Ext.form.Panel', { xtype: "form", border: false, @@ -439,10 +453,25 @@ pimcore.element.helpers.gridColumnConfig = { iconCls: "pimcore_icon_filter pimcore_icon_overlay_add", handler: function () { if (formPanel.isValid() && typeof fieldInfo.getRelationFilter === "function") { - this.grid.filters.getStore().addFilter( - fieldInfo.getRelationFilter(fieldInfo.dataIndex, editor) - ); - this.filterByRelationWindow.close(); + try { + // Sync editor store with its current value (if applicable) + const value = editor.getValue(); + let items = []; + if (Array.isArray(value)) { + items = value; + } else if (value) { + items = [value]; + } + editor.store.loadData(items, false); + + this.grid.filters.getStore().addFilter( + fieldInfo.getRelationFilter(fieldInfo.dataIndex, editor) + ); + this.filterByRelationWindow.close(); + } catch (e) { + console.error("Error applying relation filter:", e); + pimcore.helpers.showNotification(t("error"), e.message || e, "error"); + } } }.bind(this) }