Skip to content

Commit de26b00

Browse files
committed
#216 Add detachGrid parameter to destroy. Updated docs for remove and removeAll param.
1 parent d1c90cf commit de26b00

File tree

6 files changed

+30
-13
lines changed

6 files changed

+30
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ Changes
452452
- add `setAnimation` method to API
453453
- add `setGridWidth` method ([#227](https://github.com/troolee/gridstack.js/issues/227))
454454
- add `removable`/`removeTimeout`
455+
- add `detachGrid` parameter to `destroy` method ([#216](https://github.com/troolee/gridstack.js/issues/216))
455456

456457
#### v0.2.4 (2016-02-15)
457458

dist/gridstack.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,14 @@
10411041
this._updateContainerHeight();
10421042
};
10431043

1044-
GridStack.prototype.destroy = function() {
1044+
GridStack.prototype.destroy = function(detachGrid) {
10451045
$(window).off('resize', this.onResizeHandler);
10461046
this.disable();
1047-
this.container.remove();
1047+
if (typeof detachGrid != 'undefined' && !detachGrid) {
1048+
this.removeAll(true);
1049+
} else {
1050+
this.container.remove();
1051+
}
10481052
Utils.removeStylesheet(this._stylesId);
10491053
if (this.grid) {
10501054
this.grid = null;

dist/gridstack.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gridstack.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ gridstack.js API
2323
- [cellHeight(val)](#cellheightval)
2424
- [cellWidth()](#cellwidth)
2525
- [commit()](#commit)
26-
- [destroy()](#destroy)
26+
- [destroy([detachGrid])](#destroydetachgrid)
2727
- [disable()](#disable)
2828
- [enable()](#enable)
2929
- [enableMove(doEnable, includeNewWidgets)](#enablemovedoenable-includenewwidgets)
@@ -38,8 +38,8 @@ gridstack.js API
3838
- [minWidth(el, val)](#minwidthel-val)
3939
- [movable(el, val)](#movableel-val)
4040
- [move(el, x, y)](#moveel-x-y)
41-
- [removeWidget(el, detachNode)](#removewidgetel-detachnode)
42-
- [removeAll()](#removeall)
41+
- [removeWidget(el[, detachNode])](#removewidgetel-detachnode)
42+
- [removeAll([detachNode])](#removealldetachnode)
4343
- [resize(el, width, height)](#resizeel-width-height)
4444
- [resizable(el, val)](#resizableel-val)
4545
- [setAnimation(doAnimate)](#setanimationdoanimate)
@@ -220,10 +220,14 @@ Gets current cell width.
220220

221221
Finishes batch updates. Updates DOM nodes. You must call it after `batchUpdate`.
222222

223-
### destroy()
223+
### destroy([detachGrid])
224224

225225
Destroys a grid instance.
226226

227+
Parameters:
228+
229+
- `detachGrid` - if `false` nodes and grid will not be removed from the DOM (Optional. Default `true`).
230+
227231
### disable()
228232

229233
Disables widgets moving/resizing. This is a shortcut for:
@@ -340,19 +344,23 @@ Parameters:
340344
- `el` - widget to move
341345
- `x`, `y` - new position. If value is `null` or `undefined` it will be ignored.
342346

343-
### removeWidget(el, detachNode)
347+
### removeWidget(el[, detachNode])
344348

345349
Removes widget from the grid.
346350

347351
Parameters:
348352

349353
- `el` - widget to remove.
350-
- `detachNode` - if `false` DOM node won't be removed from the tree (Optional. Default `true`).
354+
- `detachNode` - if `false` node won't be removed from the DOM (Optional. Default `true`).
351355

352-
### removeAll()
356+
### removeAll([detachNode])
353357

354358
Removes all widgets from the grid.
355359

360+
Parameters:
361+
362+
- `detachNode` - if `false` nodes won't be removed from the DOM (Optional. Default `true`).
363+
356364
### resize(el, width, height)
357365

358366
Changes widget size

src/gridstack.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,10 +1041,14 @@
10411041
this._updateContainerHeight();
10421042
};
10431043

1044-
GridStack.prototype.destroy = function() {
1044+
GridStack.prototype.destroy = function(detachGrid) {
10451045
$(window).off('resize', this.onResizeHandler);
10461046
this.disable();
1047-
this.container.remove();
1047+
if (typeof detachGrid != 'undefined' && !detachGrid) {
1048+
this.removeAll(true);
1049+
} else {
1050+
this.container.remove();
1051+
}
10481052
Utils.removeStylesheet(this._stylesId);
10491053
if (this.grid) {
10501054
this.grid = null;

0 commit comments

Comments
 (0)