Skip to content

Commit ce1386c

Browse files
author
Alain Dumesny
committed
demo showing adding item to nested grid
* #95 works in the current node * nested.html now has add widget buttons.
1 parent 12552fb commit ce1386c

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

demo/float.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ <h1>Float grid demo</h1>
4444

4545
this.addNewWidget = function() {
4646
var node = this.items[count] || {
47-
x: Math.round(12 * Math.random()),
48-
y: Math.round(5 * Math.random()),
49-
width: Math.round(1 + 3 * Math.random()),
50-
height: Math.round(1 + 3 * Math.random())
51-
};
47+
x: Math.round(12 * Math.random()),
48+
y: Math.round(5 * Math.random()),
49+
width: Math.round(1 + 3 * Math.random()),
50+
height: Math.round(1 + 3 * Math.random())
51+
};
5252
this.grid.addWidget($('<div><div class="grid-stack-item-content">' + count++ + '</div></div>'), node);
5353
return false;
5454
}.bind(this);

demo/nested.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<body>
2727
<div class="container-fluid">
2828
<h1>Nested grids demo</h1>
29+
<a class="btn btn-primary" id="add-widget1" href="#">Add Widget Grid1</a>
30+
<a class="btn btn-primary" id="add-widget2" href="#">Add Widget Grid2</a>
31+
<br><br>
2932

3033
<div class="grid-stack top">
3134
<div class="grid-stack-item" data-gs-x="0" data-gs-y="0" data-gs-width="1" data-gs-height="1">
@@ -62,9 +65,23 @@ <h1>Nested grids demo</h1>
6265
dragOut: true // let us drag them out!
6366
};
6467
$('.grid-stack.top').gridstack();
65-
$('.grid-stack.nested1').gridstack(nestOptions);
68+
var grid1 = $('.grid-stack.nested1').gridstack(nestOptions).data('gridstack');
6669
nestOptions.dragOut = false;
67-
$('.grid-stack.nested2').gridstack(nestOptions);
70+
var grid2 = $('.grid-stack.nested2').gridstack(nestOptions).data('gridstack');
71+
72+
var count = 9;
73+
addNewWidget = function(grid) {
74+
var node = {
75+
x: Math.round(12 * Math.random()),
76+
y: Math.round(5 * Math.random()),
77+
width: Math.round(1 + 3 * Math.random()),
78+
height: Math.round(1 + 3 * Math.random())
79+
};
80+
grid.addWidget($('<div class="grid-stack-item sub"><div class="grid-stack-item-content">' + count++ + '</div></div>'), node);
81+
return false;
82+
};
83+
$('#add-widget1').click(function () { addNewWidget(grid1)});
84+
$('#add-widget2').click(function () { addNewWidget(grid2)});
6885
});
6986
</script>
7087
</body>

src/gridstack.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,15 @@ interface GridstackOptions {
444444
disableResize ? : boolean;
445445

446446
/**
447-
* allows to override jQuery UI draggable options. (default?: { handle?: '.grid-stack-item-content', scroll?: true, appendTo?: 'body' })
447+
* allows to override jQuery UI draggable options. (default?: { handle?: '.grid-stack-item-content', scroll?: true, appendTo?: 'body', containment: null })
448448
*/
449449
draggable ? : {};
450450

451+
/**
452+
* let user drag nested grid items out of a parent or not (default false)
453+
*/
454+
dragOut ? : boolean;
455+
451456
/**
452457
* draggable handle selector (default?: '.grid-stack-item-content')
453458
*/

0 commit comments

Comments
 (0)