diff --git a/main/plugin-cms/resources/js/Ametys/plugins/cms/search/SearchTool.js b/main/plugin-cms/resources/js/Ametys/plugins/cms/search/SearchTool.js index ac81e54..69e4aa2 100644 --- a/main/plugin-cms/resources/js/Ametys/plugins/cms/search/SearchTool.js +++ b/main/plugin-cms/resources/js/Ametys/plugins/cms/search/SearchTool.js @@ -1069,7 +1069,8 @@ { var params = { id: this._modelId, - values: this.getSearchValues() + values: this.getSearchValues(), + sort: this.getCurrentSorters() }; if (this.isAdvancedMode()) @@ -1234,9 +1235,11 @@ this._showHideSwitchModeButtons (false); } + var toolParams = params.toolParams; + var fields = Ametys.plugins.cms.content.tool.ContentGridHelper.getFieldsFromJson(result.columns, true); var columns = Ametys.plugins.cms.content.tool.ContentGridHelper.getColumnsFromJson(result.columns, this.grid); - var sorters = Ametys.plugins.cms.content.tool.ContentGridHelper.getSortersFromJson(columns, this.grid); + var sorters = toolParams.sort || Ametys.plugins.cms.content.tool.ContentGridHelper.getSortersFromJson(columns, this.grid); this.store.setProxy({ type: 'ametys', @@ -1256,7 +1259,7 @@ this.store.setSorters(sorters); // TODO Init search form from the default values. - this._initSearchForm (params.toolParams); + this._initSearchForm (toolParams); if (this.facetPanel) { @@ -1926,7 +1929,7 @@ { var params = {} params.values = this.getSearchValues(); - params.sort = this.getEncodedSortersForExport() || undefined; + params.sort = this.getEncodedSortersForExport(); params.model = this._modelId; if (this.isAdvancedMode()) @@ -1951,11 +1954,24 @@ }, /** + * Get the array of current active sorters. + * @return {String} The list of sorters. Entry of the list are object with keys 'property' and 'direction' (optionnal) + */ + getCurrentSorters: function() + { + var sorters = []; + this.store.getSorters().each (function (sorter) { + sorters.push({property: sorter.getProperty(), direction: sorter.getDirection()}) + }); + return sorters; + }, + + /** * Get the JSON encoded array of sorters. * @return {String} A JSON String representing the list of sorters. Entry of the list are object with keys 'property' and 'direction' (optionnal) */ getEncodedSortersForExport: function() { - return Ext.encode([{property: 'creationDate', direction: 'ASC'}]); + return Ext.encode(this.getCurrentSorters() || [{property: 'creationDate', direction: 'ASC'}]); } });