From 97e0ffa5005960bf0e1f5e933e028f0e93b78d23 Mon Sep 17 00:00:00 2001 From: classix-od Date: Mon, 13 Nov 2017 20:30:39 +0100 Subject: [PATCH] fix(sorting): fixed the priority computing when unsorting using column menu action (#6427) * fix(sorting): fixed the priority computing when unsorting using column menu action * reafactor(code style): Add spaces to organize it. --- src/js/core/factories/GridColumn.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/js/core/factories/GridColumn.js b/src/js/core/factories/GridColumn.js index 418b088449..86994fd3d3 100644 --- a/src/js/core/factories/GridColumn.js +++ b/src/js/core/factories/GridColumn.js @@ -869,6 +869,15 @@ angular.module('ui.grid') * @description Removes column from the grid sorting */ GridColumn.prototype.unsort = function () { + //Decrease priority for every col where priority is higher than the removed sort's priority. + var thisPriority = this.sort.priority; + + this.grid.columns.forEach(function (col) { + if (col.sort && col.sort.priority !== undefined && col.sort.priority > thisPriority) { + col.sort.priority -= 1; + } + }); + this.sort = {}; this.grid.api.core.raise.sortChanged( this.grid, this.grid.getColumnSorting() ); };