From 358ef3086c0b20c6154ca2a7de4474da08cff1ea Mon Sep 17 00:00:00 2001 From: jos Date: Thu, 3 May 2018 11:22:58 +0200 Subject: [PATCH] Fixed index of Array items not being updated after sorting --- HISTORY.md | 5 +++++ package.json | 2 +- src/js/Node.js | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 64eb7a9..97e3c05 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,11 @@ https://github.com/josdejong/jsoneditor +## not yet released, version 5.15.1 + +- Fixed index numbers of Array itesm not being updated after sorting. + + ## 2018-05-02, version 5.15.0 - Implemented selection API: `onSelectionChanged`, `onTextSelectionChanged`, diff --git a/package.json b/package.json index 9ad48ba..6bd9f65 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "bugs": "https://github.com/josdejong/jsoneditor/issues", "scripts": { "build": "gulp", - "watch": "gulp watch", + "start": "gulp watch", "test": "mocha test" }, "dependencies": { diff --git a/src/js/Node.js b/src/js/Node.js index 4252a41..417f7f7 100644 --- a/src/js/Node.js +++ b/src/js/Node.js @@ -3003,6 +3003,14 @@ Node.prototype.sort = function (direction) { }); this.sortOrder = (order == 1) ? 'asc' : 'desc'; + // update the index numbering + if (this.type === 'array') { + this.childs.forEach(function (child, index) { + child.index = index; + child.updateDom(); + }); + } + this.editor._onAction('sort', { node: this, oldChilds: oldChilds,