Skip to content

Commit a4e62e2

Browse files
author
Alain Dumesny
authored
Merge pull request #1053 from adumesny/bugfix/810
grid options renamed to `columns` & `maxRows`
2 parents d86a6e9 + 2f57d59 commit a4e62e2

File tree

10 files changed

+622
-143
lines changed

10 files changed

+622
-143
lines changed

README.md

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ Join gridstack.js on Slack: https://gridstackjs.troolee.com
2626
- [API Documentation](#api-documentation)
2727
- [Touch devices support](#touch-devices-support)
2828
- [gridstack.js for specific frameworks](#gridstackjs-for-specific-frameworks)
29-
- [Change grid width](#change-grid-width)
30-
- [Extra CSS](#extra-css)
31-
- [Different grid widths](#different-grid-widths)
29+
- [Change grid columns](#change-grid-columns)
30+
- [Custom columns CSS](#custom-columns-css)
3231
- [Override resizable/draggable options](#override-resizabledraggable-options)
3332
- [IE8 support](#ie8-support)
3433
- [Changes](#changes)
@@ -174,10 +173,31 @@ If you're still experiencing issues on touch devices please check [#444](https:/
174173
- ember: [gridstack-ember](https://github.com/yahoo/ember-gridstack)
175174

176175

177-
## Change grid width
176+
## Change grid columns
178177

179-
To change grid width (columns count), to addition to `width` option, CSS rules
180-
for `.grid-stack-item[data-gs-width="X"]` and `.grid-stack-item[data-gs-x="X"]` have to be changed accordingly.
178+
GridStack makes it very easy if you need [1-12] columns out of the box (default is 12), but you always need **2 things** if you need to customize this:
179+
180+
1) Change the `columns` grid option when creating a grid to your number N
181+
```js
182+
$('.grid-stack').gridstack( {columns: N} );
183+
```
184+
185+
2) and change your HTML accordingly if **N < 12** (else custom CSS section next). Without this, things will not render/work correctly.
186+
```html
187+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/gridstack-extra.css"/>
188+
189+
<div class="grid-stack grid-stack-N">...</div>
190+
```
191+
192+
Note `grid-stack-N` class was added.
193+
194+
`gridstack-extra.css` (and `gridstack-extra.min.css`) defines CSS for grids with custom [1-12] columns. Anything more and you'll need to generate the SASS/CSS yourself (see next).
195+
196+
See example: [2 grids demo](http://gridstack.github.io/gridstack.js/demo/two.html) with 6 columns
197+
198+
## Custom columns CSS
199+
200+
If you need > 12 columns or want to generate the CSS manually (else see above) you will need to generate CSS rules for `.grid-stack-item[data-gs-width="X"]` and `.grid-stack-item[data-gs-x="X"]`.
181201

182202
For instance for 3-column grid you need to rewrite CSS to be:
183203

@@ -205,13 +225,15 @@ For 4-column grid it should be:
205225

206226
and so on.
207227

208-
Here is a SASS code snippet which can make life easier (Thanks to @ascendantofrain, [#81](https://github.com/gridstack/gridstack.js/issues/81) and @StefanM98, [#868](https://github.com/gridstack/gridstack.js/issues/868)):
228+
Better yet, here is a SASS code snippet which can make life much easier (Thanks to @ascendantofrain, [#81](https://github.com/gridstack/gridstack.js/issues/81) and @StefanM98, [#868](https://github.com/gridstack/gridstack.js/issues/868)) and you can use sites like [sassmeister.com](https://www.sassmeister.com/) to generate the CSS for you instead:
209229

210230
```sass
211231
.grid-stack > .grid-stack-item {
212232
213233
$gridstack-columns: 12;
214234
235+
min-width: (100% / $gridstack-columns);
236+
215237
@for $i from 1 through $gridstack-columns {
216238
&[data-gs-width='#{$i}'] { width: (100% / $gridstack-columns) * $i; }
217239
&[data-gs-x='#{$i}'] { left: (100% / $gridstack-columns) * $i; }
@@ -221,25 +243,6 @@ Here is a SASS code snippet which can make life easier (Thanks to @ascendantofra
221243
}
222244
```
223245

224-
Or you can include `gridstack-extra.css`. See below for more details.
225-
226-
## Extra CSS
227-
228-
There are few extra CSS batteries in `gridstack-extra.css` (`gridstack-extra.min.css`).
229-
230-
### Different grid widths
231-
232-
You can use other than 12 grid width:
233-
234-
```html
235-
<div class="grid-stack grid-stack-N">...</div>
236-
```
237-
```javascript
238-
$('.grid-stack').gridstack({width: N});
239-
```
240-
241-
See example: [2 grids demo](http://gridstack.github.io/gridstack.js/demo/two.html)
242-
243246
## Override resizable/draggable options
244247

245248
You can override default `resizable`/`draggable` options. For instance to enable other then bottom right resizing handle

demo/two.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ <h1>Two grids demo</h1>
106106
<script type="text/javascript">
107107
$(function () {
108108
var options = {
109-
width: 6,
109+
columns: 6,
110110
float: false,
111111
removable: '.trash',
112112
removeTimeout: 100,

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Change log
2424

2525
## v0.5.2-dev (upcoming changes)
2626

27+
- grid options `width` is now `columns`, and `height` is now `maxRows` which match what they are. Old names are still supported for now (with console warnings). Also various fixes for custom # of columns and re-wrote entire doc section ([#1053](https://github.com/gridstack/gridstack.js/issues/1053)).
2728
- fix widgets not animating when animate: true is used. on every move, styles were recreated-fix should slightly improve gridstack.js speed ([#937](https://github.com/gridstack/gridstack.js/issues/937)).
2829
- fix moving widgets when having multiple grids. jquery-ui workaround ([#1043](https://github.com/gridstack/gridstack.js/issues/1043)).
2930
- switch to eslint ([#763](https://github.com/gridstack/gridstack.js/issues/763)).

doc/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ gridstack.js API
7777
- `draggable` - allows to override jQuery UI draggable options. (default: `{handle: '.grid-stack-item-content', scroll: false, appendTo: 'body'}`)
7878
- `handle` - draggable handle selector (default: `'.grid-stack-item-content'`)
7979
- `handleClass` - draggable handle class (e.g. `'grid-stack-item-content'`). If set `handle` is ignored (default: `null`)
80-
- `height` - maximum rows amount. Default is `0` which means no maximum rows
80+
- `columns` - amount of columns (default: `12`)
81+
- `maxRows` - maximum rows amount. Default is `0` which means no maximum rows
8182
- `float` - enable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html)
8283
- `itemClass` - widget class (default: `'grid-stack-item'`)
8384
- `minWidth` - minimal width. If window width is less than or equal to, grid will be shown in one-column mode (default: `768`)
@@ -93,21 +94,20 @@ gridstack.js API
9394
- `verticalMargin` - vertical gap size (default: `20`). Can be:
9495
* an integer (px)
9596
* a string (ex: '2em', '20px', '2rem')
96-
- `width` - amount of columns (default: `12`)
9797

9898
## Grid attributes
9999

100100
- `data-gs-animate` - turns animation on
101-
- `data-gs-width` - 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-width).
102-
- `data-gs-height` - maximum rows amount. Default is `0` which means no maximum rows.
101+
- `data-gs-columns` - 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).
102+
- `data-gs-maxRows` - maximum rows amount. Default is `0` which means no maximum rows.
103103
- `data-gs-current-height` - current rows amount. Set by the library only. Can be used by the CSS rules.
104104

105105
## Item attributes
106106

107-
- `data-gs-x`, `data-gs-y` - element position. Note: if one is missing this will `autoPosition` the item
108-
- `data-gs-width`, `data-gs-height` - element size
109-
- `data-gs-id`- good for quick identification (for example in change event)
110-
- `data-gs-max-width`, `data-gs-min-width`, `data-gs-max-height`, `data-gs-min-height` - element constraints
107+
- `data-gs-x`, `data-gs-y` - (number) element position in row/column. Note: if one is missing this will `autoPosition` the item
108+
- `data-gs-width`, `data-gs-height` - (number) element size in row/column
109+
- `data-gs-id`- (number | string) good for quick identification (for example in change event)
110+
- `data-gs-max-width`, `data-gs-min-width`, `data-gs-max-height`, `data-gs-min-height` - element constraints in row/column
111111
- `data-gs-no-resize` - disable element resizing
112112
- `data-gs-no-move` - disable element moving
113113
- `data-gs-auto-position` - tells to ignore `data-gs-x` and `data-gs-y` attributes and to place element to the first available position. Having either one missing will also do that.

0 commit comments

Comments
 (0)