From fa6e01bbe7b793d8e5c32a0c9521304187a78216 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 11 Jan 2018 11:22:50 +0300 Subject: [PATCH] TreeView: insert element by index. --- apps/common/main/lib/component/TreeView.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/common/main/lib/component/TreeView.js b/apps/common/main/lib/component/TreeView.js index 84ffd6ffc..12d383107 100644 --- a/apps/common/main/lib/component/TreeView.js +++ b/apps/common/main/lib/component/TreeView.js @@ -181,7 +181,7 @@ define([ Common.UI.DataView.prototype.initialize.call(this, options); }, - onAddItem: function(record, index, opts) { + onAddItem: function(record, store, opts) { var view = new Common.UI.DataViewItem({ template: this.itemTemplate, model: record @@ -190,12 +190,21 @@ define([ if (view) { var innerEl = $(this.el).find('.inner').addBack().filter('.inner'); if (innerEl) { - if (opts && opts.at == 0) - innerEl.prepend(view.render().el); else - innerEl.append(view.render().el); - innerEl.find('.empty-text').remove(); - this.dataViewItems.push(view); + + if (opts && opts.at!==undefined) { + var idx = opts.at; + var innerDivs = innerEl.find('> div'); + if (idx > 0) + $(innerDivs.get(idx - 1)).after(view.render().el); + else { + (innerDivs.length > 0) ? $(innerDivs[idx]).before(view.render().el) : innerEl.append(view.render().el); + } + this.dataViewItems = this.dataViewItems.slice(0, idx).concat(view).concat(this.dataViewItems.slice(idx)); + } else { + innerEl.append(view.render().el); + this.dataViewItems.push(view); + } var name = record.get('name'); if (name.length > 37 - record.get('level')*2)