Skip to content

Commit c5df96f

Browse files
authored
Merge pull request #1173 from RadoiAndrei/develop
Added minRow and row
2 parents dda8de1 + 597d484 commit c5df96f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

doc/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ gridstack.js API
7575
* a string (ex: '100px', '10em', '10rem', '10%')
7676
* 0 or null, in which case the library will not generate styles for rows. Everything must be defined in CSS files.
7777
* `'auto'` - height will be calculated to match cell width (initial square grid).
78+
- `row` - number of rows. This is a shortcut of writting `minRow: sameValue, maxRow: sameValue`.
7879
- `column` - number of columns (default: `12`) which can change on the fly with `column(N)` as well. See [example](http://gridstackjs.com/demo/column.html)
7980
- `ddPlugin` - class that implement drag'n'drop functionallity for gridstack. If `false` grid will be static. (default: `null` - first available plugin will be used)
8081
- `disableDrag` - disallows dragging of widgets (default: `false`).
@@ -86,6 +87,7 @@ gridstack.js API
8687
- `handle` - draggable handle selector (default: `'.grid-stack-item-content'`)
8788
- `handleClass` - draggable handle class (e.g. `'grid-stack-item-content'`). If set `handle` is ignored (default: `null`)
8889
- `itemClass` - widget class (default: `'grid-stack-item'`)
90+
- `minRow` - minimum rows amount. Default is `0`
8991
- `maxRow` - maximum rows amount. Default is `0` which means no maximum rows
9092
- `minWidth` - minimal width. If window width is less than or equal to, grid will be shown in one-column mode (default: `768`)
9193
- `oneColumnModeDomSort` - set to `true` if you want oneColumnMode to use the DOM order and ignore x,y from normal multi column layouts during sorting. This enables you to have custom 1 column layout that differ from the rest. (default?: `false`)
@@ -103,7 +105,9 @@ gridstack.js API
103105
## Grid attributes
104106

105107
- `data-gs-animate` - turns animation on
108+
- `data-gs-row` - number of rows. This is a shortcut of writting `data-gs-min-row="sameValue" data-gs-max-row="sameValue"` .
106109
- `data-gs-column` - amount of columns. Setting non-default value must be supported by equivalent change in CSS, [see docs here](https://github.com/gridstack/gridstack.js#change-grid-columns).
110+
- `data-gs-min-row` - minimum rows amount. Default is `0`.
107111
- `data-gs-max-row` - maximum rows amount. Default is `0` which means no maximum rows.
108112
- `data-gs-current-row` - current rows amount. Set by the library only. Can be used by the CSS rules.
109113

src/gridstack.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,12 @@
693693

694694
opts = opts || {};
695695

696+
// if row property exists, replace minRow and maxRow
697+
if (opts.row) {
698+
opts.minRow = opts.row;
699+
opts.maxRow = opts.row;
700+
}
701+
696702
this.$el = $(el); // TODO: legacy code
697703
this.el = this.$el.get(0); // exposed HTML element to the user
698704

@@ -709,8 +715,10 @@
709715
var isNested = this.$el.closest('.' + opts.itemClass).length > 0;
710716

711717
this.opts = Utils.defaults(opts, {
718+
row: parseInt(this.$el.attr('data-gs-row')) || 0,
712719
column: parseInt(this.$el.attr('data-gs-column')) || 12,
713-
maxRow: parseInt(this.$el.attr('data-gs-max-row')) || 0,
720+
minRow: parseInt(this.$el.attr('data-gs-row')) ? parseInt(this.$el.attr('data-gs-row')) : parseInt(this.$el.attr('data-gs-min-row')) || 0,
721+
maxRow: parseInt(this.$el.attr('data-gs-row')) ? parseInt(this.$el.attr('data-gs-row')) : parseInt(this.$el.attr('data-gs-max-row')) || 0,
714722
itemClass: 'grid-stack-item',
715723
placeholderClass: 'grid-stack-placeholder',
716724
placeholderText: '',
@@ -1156,6 +1164,9 @@
11561164
GridStack.prototype._updateContainerHeight = function() {
11571165
if (this.engine._batchMode) { return; }
11581166
var row = this.engine.getRow();
1167+
if (row < this.opts.minRow) {
1168+
row = this.opts.minRow;
1169+
}
11591170
// check for css min height. Each row is cellHeight + verticalMargin, until last one which has no margin below
11601171
var cssMinHeight = parseInt(this.$el.css('min-height'));
11611172
if (cssMinHeight > 0) {

0 commit comments

Comments
 (0)