Skip to content

Commit 4e1804a

Browse files
author
Alain Dumesny
authored
Merge pull request #1105 from adumesny/develop
drag&drop between nested grids, set Containment
2 parents 9ac95ce + 12552fb commit 4e1804a

File tree

4 files changed

+49
-27
lines changed

4 files changed

+49
-27
lines changed

demo/nested.html

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,44 @@
2727
<div class="container-fluid">
2828
<h1>Nested grids demo</h1>
2929

30-
<div class="grid-stack">
31-
<div class="grid-stack-item" data-gs-x="0" data-gs-y="0" data-gs-width="4" data-gs-height="3">
32-
<div class="grid-stack-item-content">
33-
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eaque eius eligendi eos fuga magnam numquam perferendis provident quos rem. Asperiores assumenda dolor error eveniet impedit nihil numquam provident repellat ullam.
34-
</div>
30+
<div class="grid-stack top">
31+
<div class="grid-stack-item" data-gs-x="0" data-gs-y="0" data-gs-width="1" data-gs-height="1">
32+
<div class="grid-stack-item-content">regular item</div>
3533
</div>
36-
<div class="grid-stack-item" data-gs-x="4" data-gs-y="0" data-gs-width="4" data-gs-height="4">
34+
<div class="grid-stack-item" data-gs-x="1" data-gs-y="0" data-gs-width="4" data-gs-height="4">
3735
<div class="grid-stack-item-content">
38-
39-
<div class="grid-stack">
40-
<div class="grid-stack-item" data-gs-x="0" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">1</div></div>
41-
<div class="grid-stack-item" data-gs-x="3" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">2</div></div>
42-
<div class="grid-stack-item" data-gs-x="6" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">3</div></div>
43-
<div class="grid-stack-item" data-gs-x="9" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">4</div></div>
44-
45-
<div class="grid-stack-item" data-gs-x="0" data-gs-y="1" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">5</div></div>
46-
<div class="grid-stack-item" data-gs-x="3" data-gs-y="1" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">6</div></div>
47-
</div>
48-
36+
nested 1 - can drag items out
37+
<div class="grid-stack nested1">
38+
<div class="grid-stack-item sub" data-gs-x="0" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">1</div></div>
39+
<div class="grid-stack-item sub" data-gs-x="3" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">2</div></div>
40+
<div class="grid-stack-item sub" data-gs-x="6" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">3</div></div>
41+
<div class="grid-stack-item sub" data-gs-x="9" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">4</div></div>
42+
<div class="grid-stack-item sub" data-gs-x="0" data-gs-y="1" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">5</div></div>
43+
<div class="grid-stack-item sub" data-gs-x="3" data-gs-y="1" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">6</div></div>
44+
</div>
45+
</div>
46+
</div>
47+
<div class="grid-stack-item" data-gs-x="5" data-gs-y="0" data-gs-width="3" data-gs-height="4">
48+
<div class="grid-stack-item-content">
49+
nested 2 - constrained to parent (default)
50+
<div class="grid-stack nested2">
51+
<div class="grid-stack-item sub" data-gs-x="0" data-gs-y="0" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">7</div></div>
52+
<div class="grid-stack-item sub" data-gs-x="0" data-gs-y="3" data-gs-width="3" data-gs-height="1"><div class="grid-stack-item-content">8</div></div>
4953
</div>
5054
</div>
5155
</div>
5256
</div>
5357

54-
5558
<script type="text/javascript">
5659
$(function () {
57-
var options = {
60+
var nestOptions = {
61+
acceptWidgets: '.grid-stack-item.sub', // only pink sub items can be inserted, otherwise grid-items causes all sort of issues
62+
dragOut: true // let us drag them out!
5863
};
59-
$('.grid-stack').gridstack(options);
64+
$('.grid-stack.top').gridstack();
65+
$('.grid-stack.nested1').gridstack(nestOptions);
66+
nestOptions.dragOut = false;
67+
$('.grid-stack.nested2').gridstack(nestOptions);
6068
});
6169
</script>
6270
</body>

doc/CHANGES.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ Change log
2727

2828
## v0.5.5-dev (upcoming changes)
2929

30-
- add `float(val)` to set/get the grid float mode [#1088](https://github.com/gridstack/gridstack.js/pull/1088)
31-
- add `compact()` relayout grid items to reclaim any empty space [#1101](https://github.com/gridstack/gridstack.js/pull/1101)
32-
- Allow percentage as a valid unit for height [#1093](https://github.com/gridstack/gridstack.js/pull/1093)
30+
- add `float(val)` to set/get the grid float mode, which will relayout [#1088](https://github.com/gridstack/gridstack.js/pull/1088)
31+
- add `compact()` to reclaim any empty space and relayout grid items [#1101](https://github.com/gridstack/gridstack.js/pull/1101)
32+
- add `options.dragOut` to let user drag nested grid items out of a parent or not (default false)
33+
and jQuery UI `draggable.containment` can now be specified in options. You can now drag&drop between 2 nested grids [#1105](https://github.com/gridstack/gridstack.js/pull/1105)
34+
- Allow percentage as a valid unit for height [#1093](https://github.com/gridstack/gridstack.js/pull/1093). thank you @trevisanweb @aureality @ZoolWay
3335
- fixed callbacks to get either `added, removed, change` or combination if adding a node require also to change its (x,y) for example.
3436
Also you can now call `batchUpdate()` before calling a bunch of `addWidget()` and get a single event callback (more efficient).
3537
[#1096](https://github.com/gridstack/gridstack.js/pull/1096)
3638
- `removeAll()` is now much faster (no relayout) and calls `removed` event just once with a list [#1097](https://github.com/gridstack/gridstack.js/pull/1097)
3739
- `setColumn()` complete re-write and is no longer "Experimental". We now do a reasonable job at sizing/position the widgets (especially 1 column) and
3840
also now cache each column layout so you can go back to say 12 column and not loose original layout. [#1098](https://github.com/gridstack/gridstack.js/pull/1098)
39-
- fix bug where `addWidget(el)` (default values) would not render item at correct CSS location, and overlap item at (0,0) [#1098](https://github.com/gridstack/gridstack.js/pull/1098)
41+
- fix bug where `addWidget(el)` (no data) would not render item at correct location, and overlap item at (0,0) [#1098](https://github.com/gridstack/gridstack.js/pull/1098)
4042

4143
## v0.5.5 (2019-11-27)
4244

doc/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ gridstack.js API
7373
* a string (ex: '100px', '10em', '10rem', '10%')
7474
* 0 or null, in which case the library will not generate styles for rows. Everything must be defined in CSS files.
7575
* `'auto'` - height will be calculated to match cell width (initial square grid).
76-
- `column` - amount of columns (default: `12`)
76+
- `column` - number of columns (default: `12`) which can change on the fly with `setColumn()` as well. See [example](http://gridstackjs.com/demo/column.html)
7777
- `ddPlugin` - class that implement drag'n'drop functionallity for gridstack. If `false` grid will be static. (default: `null` - first available plugin will be used)
7878
- `disableDrag` - disallows dragging of widgets (default: `false`).
7979
- `disableOneColumnMode` - disables the onColumnMode when the window width is less than minWidth (default: 'false')
8080
- `disableResize` - disallows resizing of widgets (default: `false`).
81-
- `draggable` - allows to override jQuery UI draggable options. (default: `{handle: '.grid-stack-item-content', scroll: false, appendTo: 'body'}`)
81+
- `draggable` - allows to override jQuery UI draggable options. (default: `{handle: '.grid-stack-item-content', scroll: false, appendTo: 'body', containment: null}`)
82+
- `dragOut` to let user drag nested grid items out of a parent or not (default false) See [example](http://gridstackjs.com/demo/nested.html)
8283
- `float` - enable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html)
8384
- `handle` - draggable handle selector (default: `'.grid-stack-item-content'`)
8485
- `handleClass` - draggable handle class (e.g. `'grid-stack-item-content'`). If set `handle` is ignored (default: `null`)

src/gridstack.jQueryUI.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,22 @@
5656
el.draggable(opts);
5757
} else {
5858
el.draggable($.extend({}, this.grid.opts.draggable, {
59-
containment: this.grid.opts.isNested ? this.grid.container.parent() : null,
59+
containment: (this.grid.opts.isNested && !this.grid.opts.dragOut) ?
60+
this.grid.container.parent() :
61+
(this.grid.opts.draggable.containment || null),
6062
start: opts.start || function() {},
6163
stop: opts.stop || function() {},
6264
drag: opts.drag || function() {}
6365
}));
66+
67+
var handles = el.data('gs-resize-handles') ? el.data('gs-resize-handles') : this.grid.opts.resizable.handles;
68+
el.resizable($.extend({}, this.grid.opts.resizable, {
69+
handles: handles
70+
}, {
71+
start: opts.start || function () { },
72+
stop: opts.stop || function () { },
73+
resize: opts.resize || function () { }
74+
}));
6475
}
6576
return this;
6677
};

0 commit comments

Comments
 (0)