Skip to content

Commit baa8cde

Browse files
author
Andrei Radoi
committed
Added minRow and row
1 parent 7d362d8 commit baa8cde

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/gridstack.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,12 @@
296296

297297
var idSeq = 0;
298298

299-
var GridStackEngine = function(column, onchange, float, maxRow, items) {
299+
var GridStackEngine = function(row, column, onchange, float, minRow, maxRow, items) {
300+
this.row = row || 0;
300301
this.column = column || 12;
301302
this.float = float || false;
302-
this.maxRow = maxRow || 0;
303+
this.minRow = minRow || 0;
304+
this.maxRow = this.row ? this.row : maxRow || 0;
303305

304306
this.nodes = items || [];
305307
this.onchange = onchange || function() {};
@@ -558,16 +560,18 @@
558560
}
559561
var hasLocked = Boolean(this.nodes.find(function(n) { return n.locked; }));
560562

561-
if (!this.maxRow && !hasLocked) {
563+
if (!this.maxRow && !this.row && !hasLocked) {
562564
return true;
563565
}
564566

565567
var clonedNode;
566568
var clone = new GridStackEngine(
569+
0,
567570
this.column,
568571
null,
569572
this.float,
570573
0,
574+
0,
571575
this.nodes.map(function(n) {
572576
if (n === node) {
573577
clonedNode = $.extend({}, n);
@@ -587,23 +591,24 @@
587591
return n !== clonedNode && Boolean(n.locked) && Boolean(n._dirty);
588592
}));
589593
}
590-
if (this.maxRow) {
594+
if (this.maxRow || this.row) {
591595
res &= clone.getRow() <= this.maxRow;
592596
}
593597

594598
return res;
595599
};
596600

597601
GridStackEngine.prototype.canBePlacedWithRespectToHeight = function(node) {
598-
if (!this.maxRow) {
602+
if (!this.maxRow && !this.row) {
599603
return true;
600604
}
601-
602605
var clone = new GridStackEngine(
606+
0,
603607
this.column,
604608
null,
605609
this.float,
606610
0,
611+
0,
607612
this.nodes.map(function(n) { return $.extend({}, n); }));
608613
clone.addNode(node);
609614
return clone.getRow() <= this.maxRow;
@@ -665,7 +670,7 @@
665670
};
666671

667672
GridStackEngine.prototype.getRow = function() {
668-
return this.nodes.reduce(function(memo, n) { return Math.max(memo, n.y + n.height); }, 0);
673+
return this.row ? this.row : this.nodes.reduce(function(memo, n) { return Math.max(memo, n.y + n.height); }, 0);
669674
};
670675

671676
GridStackEngine.prototype.beginUpdate = function(node) {
@@ -709,8 +714,10 @@
709714
var isNested = this.$el.closest('.' + opts.itemClass).length > 0;
710715

711716
this.opts = Utils.defaults(opts, {
717+
row: parseInt(this.$el.attr('data-gs-row')) || 0,
712718
column: parseInt(this.$el.attr('data-gs-column')) || 12,
713-
maxRow: parseInt(this.$el.attr('data-gs-max-row')) || 0,
719+
maxRow: parseInt(this.$el.attr('data-gs-row')) || 0 ? parseInt(this.$el.attr('data-gs-row')) : parseInt(this.$el.attr('data-gs-max-row')) || 0,
720+
minRow: parseInt(this.$el.attr('data-gs-min-row')) || 0,
714721
itemClass: 'grid-stack-item',
715722
placeholderClass: 'grid-stack-placeholder',
716723
placeholderText: '',
@@ -787,7 +794,7 @@
787794

788795
this._initStyles();
789796

790-
this.engine = new GridStackEngine(this.opts.column, function(nodes, detachNode) {
797+
this.engine = new GridStackEngine(this.opts.row, this.opts.column, function(nodes, detachNode) {
791798
detachNode = (detachNode === undefined ? true : detachNode);
792799
var maxHeight = 0;
793800
this.nodes.forEach(function(n) {
@@ -807,7 +814,7 @@
807814
}
808815
});
809816
self._updateStyles(maxHeight + 10);
810-
}, this.opts.float, this.opts.maxRow);
817+
}, this.opts.float, this.opts.minRow, this.opts.maxRow);
811818

812819
if (this.opts.auto) {
813820
var elements = [];
@@ -1155,12 +1162,12 @@
11551162

11561163
GridStack.prototype._updateContainerHeight = function() {
11571164
if (this.engine._batchMode) { return; }
1158-
var row = this.engine.getRow();
1165+
var row = this.opts.minRow > this.engine.getRow() ? this.opts.minRow : this.engine.getRow();
11591166
// check for css min height. Each row is cellHeight + verticalMargin, until last one which has no margin below
11601167
var cssMinHeight = parseInt(this.$el.css('min-height'));
11611168
if (cssMinHeight > 0) {
11621169
var verticalMargin = this.opts.verticalMargin;
1163-
var minRow = Math.round((cssMinHeight + verticalMargin) / (this.cellHeight() + verticalMargin));
1170+
var minRow = Math.round((cssMinHeight + verticalMargin) / (this.cellHeight() + verticalMargin));
11641171
if (row < minRow) {
11651172
row = minRow;
11661173
}

0 commit comments

Comments
 (0)