diff --git a/etemplate/js/et2_extension_nextmatch.js b/etemplate/js/et2_extension_nextmatch.js index ac669b2d2f..9bb5e84513 100644 --- a/etemplate/js/et2_extension_nextmatch.js +++ b/etemplate/js/et2_extension_nextmatch.js @@ -385,6 +385,12 @@ var et2_nextmatch = et2_DOMWidget.extend([et2_IResizeable, et2_IInput], this.egw().debug("info", "Changing nextmatch filters to ", this.activeFilters); + // Keep the selection after applying filters, but only if unchanged + if(JSON.stringify(this.controller._filters) == JSON.stringify(this.activeFilters)) + { + this.controller.keepSelection(); + } + // Update the filters in the grid controller this.controller.setFilters(this.activeFilters); diff --git a/etemplate/js/et2_extension_nextmatch_controller.js b/etemplate/js/et2_extension_nextmatch_controller.js index 65052ca790..2f3b001102 100644 --- a/etemplate/js/et2_extension_nextmatch_controller.js +++ b/etemplate/js/et2_extension_nextmatch_controller.js @@ -83,6 +83,10 @@ var et2_nextmatch_controller = et2_dataview_controller.extend(et2_IDataProvider, // We start with no filters this._filters = {}; + // Keep selection across filter changes + this.kept_selection = null; + this.kept_focus = null; + // Directly use the API-Implementation of dataRegisterUID and // dataUnregisterUID this.dataUnregisterUID = _egw.dataUnregisterUID; @@ -110,6 +114,15 @@ var et2_nextmatch_controller = et2_dataview_controller.extend(et2_IDataProvider, this._lastModification = null; }, + /** + * Keep the selection, if possible, across a data fetch and restore it + * after + */ + keepSelection: function() { + this.kept_selection = this._selectionMgr ? this._selectionMgr.getSelected() : null; + this.kept_focus = this._selectionMgr ? this._selectionMgr._focusedEntry.uid || null : null; + }, + getObjectManager: function () { return this._objectManager; }, @@ -315,6 +328,25 @@ var et2_nextmatch_controller = et2_dataview_controller.extend(et2_IDataProvider, // Call the inherited function this._super.apply(this, arguments); + + // Restore selection, if passed + if(this.self && this.self.kept_selection && this.self._selectionMgr) + { + if(this.self.kept_selection.all) + { + this.self._selectionMgr.selectAll(); + } + for(var i = 0; i < this.self.kept_selection.ids.length || 0; i++) + { + this.self._selectionMgr.setSelected(this.self.kept_selection.ids[i],true); + } + if(this.self.kept_focus) + { + this.self._selectionMgr.setFocused(this.self.kept_focus,true); + } + this.self.kept_selection = null; + this.self.kept_focus = null; + } }, /**