From 73e2ba991c0e74654f3c2e2ae02485196d25fe1e Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 6 Dec 2017 13:51:42 +0100 Subject: [FIX] web: add a stableSort method for sorting x2m Issue: create 60 lines in ordered x2many with the same value (0) for the order field and make a change ; the displayed records will be switched. The problem appears because the sorting function is not stable and the records with the same values can change place (hence change page), which is quite disturbing for the user. --- addons/web/static/src/js/views/basic/basic_model.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index 8a9fd496b39..78e9216be62 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -89,6 +89,7 @@ var Context = require('web.Context'); var core = require('web.core'); var Domain = require('web.Domain'); var session = require('web.session'); +var utils = require('web.utils'); var _t = core._t; @@ -3833,7 +3834,7 @@ var BasicModel = AbstractModel.extend({ for (var k = 0; k < list.orderedResIDs.length; k++) { orderedResIDs[list.orderedResIDs[k]] = k; } - list.res_ids.sort(function compareResIdIndexes (resId1, resId2) { + utils.stableSort(list.res_ids, function compareResIdIndexes (resId1, resId2) { if (!(resId1 in orderedResIDs) && !(resId2 in orderedResIDs)) { return 0; } @@ -3878,7 +3879,7 @@ var BasicModel = AbstractModel.extend({ } return compareRecords(record1ID, record2ID, level + 1); }; - list.res_ids.sort(compareRecords); + utils.stableSort(list.res_ids, compareRecords); } this._setDataInRange(list); }, -- cgit v1.2.3