Skip to content

Commit 0829c28

Browse files
committed
minRow tweaks
* code and doc tweaks for #1172
1 parent c5df96f commit 0829c28

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

doc/CHANGES.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ Change log
3333

3434
## 1.0.0-dev (upcoming)
3535

36-
- fix [(1166)](https://github.com/gridstack/gridstack.js/issues/1166) resize not taking margin height into account
37-
- fix [(1155)](https://github.com/gridstack/gridstack.js/issues/1155) `maxRow` now limit initial item placement if out of bound, preventing broken drag behavior
38-
- fix [(1171)](https://github.com/gridstack/gridstack.js/issues/1171) added event support to call `grid.on('added removed change', callback)` again even with native events.
36+
- add `minRow` and `row` grid options (which set minRow=maxRow=N) [1172](https://github.com/gridstack/gridstack.js/issues/1172) - thanks [@RadoiAndrei](https://github.com/RadoiAndrei)
37+
- fix [1166](https://github.com/gridstack/gridstack.js/issues/1166) resize not taking margin height into account - thanks [@awjae](https://github.com/awjae)
38+
- fix [1155](https://github.com/gridstack/gridstack.js/issues/1155) `maxRow` now limit initial item placement if out of bound, preventing broken drag behavior
39+
- fix [1171](https://github.com/gridstack/gridstack.js/issues/1171) added event support to call `grid.on('added removed change', callback)` again even with native events.
3940

4041
## v1.0.0 (2020-02-23)
4142

doc/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ 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`.
7978
- `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)
8079
- `ddPlugin` - class that implement drag'n'drop functionallity for gridstack. If `false` grid will be static. (default: `null` - first available plugin will be used)
8180
- `disableDrag` - disallows dragging of widgets (default: `false`).
@@ -87,15 +86,16 @@ gridstack.js API
8786
- `handle` - draggable handle selector (default: `'.grid-stack-item-content'`)
8887
- `handleClass` - draggable handle class (e.g. `'grid-stack-item-content'`). If set `handle` is ignored (default: `null`)
8988
- `itemClass` - widget class (default: `'grid-stack-item'`)
90-
- `minRow` - minimum rows amount. Default is `0`
91-
- `maxRow` - maximum rows amount. Default is `0` which means no maximum rows
89+
- `maxRow` - maximum rows amount. Default is `0` which means no max.
90+
- `minRow` - minimum rows amount. Default is `0`. You can also do this with `min-height` CSS attribute on the grid div in pixels, which will round to the closest row.
9291
- `minWidth` - minimal width. If window width is less than or equal to, grid will be shown in one-column mode (default: `768`)
9392
- `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`)
9493
- `placeholderClass` - class for placeholder (default: `'grid-stack-placeholder'`)
9594
- `placeholderText` - placeholder default content (default: `''`)
9695
- `resizable` - allows to override jQuery UI resizable options. (default: `{autoHide: true, handles: 'se'}`)
9796
- `removable` - if `true` widgets could be removed by dragging outside of the grid. It could also be a jQuery selector string, in this case widgets will be removed by dropping them there (default: `false`) See [example](http://gridstackjs.com/demo/two.html)
9897
- `removeTimeout` - time in milliseconds before widget is being removed while dragging outside of the grid. (default: `2000`)
98+
- `row` - fix grid number of rows. This is a shortcut of writing `minRow:N, maxRow:N`. (default `0` no constrain)
9999
- `rtl` - if `true` turns grid to RTL. Possible values are `true`, `false`, `'auto'` (default: `'auto'`) See [example](http://gridstackjs.com/demo/rtl.html)
100100
- `staticGrid` - makes grid static (default `false`). If true widgets are not movable/resizable. You don't even need jQueryUI draggable/resizable. A CSS class `grid-stack-static` is also added to the container.
101101
- `verticalMargin` - vertical gap size (default: `20`). Can be:
@@ -105,11 +105,11 @@ gridstack.js API
105105
## Grid attributes
106106

107107
- `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"` .
109108
- `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`.
111-
- `data-gs-max-row` - maximum rows amount. Default is `0` which means no maximum rows.
112-
- `data-gs-current-row` - current rows amount. Set by the library only. Can be used by the CSS rules.
109+
- `data-gs-current-row` - (internal) current rows amount. Set by the library only. Can be used by the CSS rules.
110+
- `data-gs-max-row` - maximum rows amount. Default is `0` which means no max.
111+
- `data-gs-min-row` - minimum rows amount. Default is `0`. You can also do this with `min-height` CSS attribute on the grid div in pixels, which will round to the closest row.
112+
- `data-gs-row` - fix grid number of rows. This is a shortcut of writing `data-gs-min-row="N" data-gs-max-row="N"`. (default `0` no constrain)
113113

114114
## Item attributes
115115

src/gridstack.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,6 @@
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-
702696
this.$el = $(el); // TODO: legacy code
703697
this.el = this.$el.get(0); // exposed HTML element to the user
704698

@@ -714,11 +708,18 @@
714708
opts.itemClass = opts.itemClass || 'grid-stack-item';
715709
var isNested = this.$el.closest('.' + opts.itemClass).length > 0;
716710

711+
// if row property exists, replace minRow and maxRow instead
712+
if (opts.row) {
713+
opts.minRow = opts.maxRow = opts.row;
714+
delete opts.row;
715+
}
716+
var rowAttr = parseInt(this.$el.attr('data-gs-row'));
717+
718+
// elements attributes override any passed options (like CSS style) - merge the two together
717719
this.opts = Utils.defaults(opts, {
718-
row: parseInt(this.$el.attr('data-gs-row')) || 0,
719720
column: parseInt(this.$el.attr('data-gs-column')) || 12,
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,
721+
minRow: rowAttr ? rowAttr : parseInt(this.$el.attr('data-gs-min-row')) || 0,
722+
maxRow: rowAttr ? rowAttr : parseInt(this.$el.attr('data-gs-max-row')) || 0,
722723
itemClass: 'grid-stack-item',
723724
placeholderClass: 'grid-stack-placeholder',
724725
placeholderText: '',

0 commit comments

Comments
 (0)