From a9546af3dc5dbe2e81e9c6f2fca3276f4304ed7c Mon Sep 17 00:00:00 2001 From: Glen Javier Date: Tue, 14 Feb 2017 22:08:53 +1000 Subject: [PATCH] modifying batchUpdate to work with addWidget --- src/gridstack.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/gridstack.js b/src/gridstack.js index 39d250a..bd987ee 100644 --- a/src/gridstack.js +++ b/src/gridstack.js @@ -169,6 +169,7 @@ this._addedNodes = []; this._removedNodes = []; + this._batchQueue = []; }; GridStackEngine.prototype.batchUpdate = function() { @@ -176,9 +177,19 @@ this.float = true; }; - GridStackEngine.prototype.commit = function() { + GridStackEngine.prototype.commit = function(grid) { if (this._updateCounter !== 0) { this._updateCounter = 0; + + _.each(this._batchQueue, function(el) { + grid.container.append(el); + grid._prepareElement(el, true); + grid._triggerAddEvent(); + grid._updateContainerHeight(); + grid._triggerChangeEvent(true); + }); + this._batchQueue = []; + this.float = this._float; this._packNodes(); this._notify(); @@ -1264,11 +1275,16 @@ if (typeof minHeight != 'undefined') { el.attr('data-gs-min-height', minHeight); } if (typeof maxHeight != 'undefined') { el.attr('data-gs-max-height', maxHeight); } if (typeof id != 'undefined') { el.attr('data-gs-id', id); } - this.container.append(el); - this._prepareElement(el, true); - this._triggerAddEvent(); - this._updateContainerHeight(); - this._triggerChangeEvent(true); + + if (this.grid._updateCounter) { + this.grid._batchQueue.push(el); + } else { + this.container.append(el); + this._prepareElement(el, true); + this._triggerAddEvent(); + this._updateContainerHeight(); + this._triggerChangeEvent(true); + } return el; }; @@ -1592,7 +1608,7 @@ }; GridStack.prototype.commit = function() { - this.grid.commit(); + this.grid.commit(this); this._updateContainerHeight(); };