Skip to content

Commit 2299d03

Browse files
author
Alain Dumesny
committed
options rename to columns & maxRows
* 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) * updated test (required), samples (optional), readme * re-wrote entire custom column section. Hopefully much easier to find/use now.
1 parent cb76958 commit 2299d03

File tree

9 files changed

+97
-92
lines changed

9 files changed

+97
-92
lines changed

README.md

Lines changed: 27 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), in addition to setting the `width` grid 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,7 +225,7 @@ 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)) and use a site like [sassmeister.com](https://www.sassmeister.com/) to generate CSS if you need to:
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 {
@@ -223,25 +243,6 @@ Here is a SASS code snippet which can make life easier (Thanks to @ascendantofra
223243
}
224244
```
225245

226-
Or you can include `gridstack-extra.css` which include [1-12] column sizes. See below for more details.
227-
228-
## Extra CSS
229-
230-
There are few extra CSS batteries in `gridstack-extra.css` (`gridstack-extra.min.css`) that defines CSS for grids with [1-12] columns. Anything more and you'll need to generate the above SASS/CSS yourself.
231-
232-
### Different grid widths
233-
234-
You can use other than 12 grid width:
235-
236-
```html
237-
<div class="grid-stack grid-stack-N">...</div>
238-
```
239-
```javascript
240-
$('.grid-stack').gridstack({width: N});
241-
```
242-
243-
See example: [2 grids demo](http://gridstack.github.io/gridstack.js/demo/two.html)
244-
245246
## Override resizable/draggable options
246247

247248
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ 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)).
3031
- null values to addWidget() exception fix ([#1042](https://github.com/gridstack/gridstack.js/issues/1042)).
31-
- various fixes for custom # of columns (readme, safer code) ([#1053](https://github.com/gridstack/gridstack.js/issues/1053)).
3232

3333
## v0.5.2 (2019-11-13)
3434

doc/README.md

Lines changed: 4 additions & 4 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,13 +94,12 @@ 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

spec/e2e/html/810-many-columns.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ <h1>Many Columns demo</h1>
4949
const COLUMNS = 30; // # of columns, also need to update CSS
5050
var count = 0;
5151
var options = {
52-
width: COLUMNS,
52+
columns: COLUMNS,
5353
cellHeight: 'auto',
5454
float: false
5555
};

spec/gridstack-engine-spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ describe('gridstack engine', function() {
1717
});
1818

1919
it('should be setup properly', function() {
20-
expect(engine.width).toEqual(12);
20+
expect(engine.columns).toEqual(12);
2121
expect(engine.float).toEqual(false);
22-
expect(engine.height).toEqual(0);
22+
expect(engine.maxRows).toEqual(0);
2323
expect(engine.nodes).toEqual([]);
2424
});
2525
});

spec/gridstack-spec.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@ describe('gridstack', function() {
77
var gridstackHTML =
88
'<div style="width: 992px; height: 800px" id="gs-cont">' +
99
' <div class="grid-stack">' +
10-
' <div class="grid-stack-item"' +
11-
' data-gs-x="0" data-gs-y="0"' +
12-
' data-gs-width="4" data-gs-height="2">' +
10+
' <div class="grid-stack-item" data-gs-x="0" data-gs-y="0" data-gs-width="4" data-gs-height="2">' +
1311
' <div class="grid-stack-item-content"></div>' +
1412
' </div>' +
15-
' <div class="grid-stack-item"' +
16-
' data-gs-x="4" data-gs-y="0"' +
17-
' data-gs-width="4" data-gs-height="4">' +
13+
' <div class="grid-stack-item" data-gs-x="4" data-gs-y="0" data-gs-width="4" data-gs-height="4">' +
1814
' <div class="grid-stack-item-content"></div>' +
1915
' </div>' +
2016
' </div>' +
@@ -35,9 +31,9 @@ describe('gridstack', function() {
3531

3632
it('should set default params correctly.', function() {
3733
e.call(w);
38-
expect(w.width).toBeUndefined();
34+
expect(w.columns).toBeUndefined();
3935
expect(w.float).toBe(false);
40-
expect(w.height).toEqual(0);
36+
expect(w.maxRows).toEqual(0);
4137
expect(w.nodes).toEqual([]);
4238
expect(typeof w.onchange).toBe('function');
4339
expect(w._updateCounter).toEqual(0);
@@ -49,9 +45,9 @@ describe('gridstack', function() {
4945
var arr = [1,2,3];
5046

5147
e.call(w, 1, fkt, true, 2, arr);
52-
expect(w.width).toEqual(1);
48+
expect(w.columns).toEqual(1);
5349
expect(w.float).toBe(true);
54-
expect(w.height).toEqual(2);
50+
expect(w.maxRows).toEqual(2);
5551
expect(w.nodes).toEqual(arr);
5652
expect(w.onchange).toEqual(fkt);
5753
expect(w._updateCounter).toEqual(0);
@@ -75,27 +71,27 @@ describe('gridstack', function() {
7571

7672
describe('sorting of nodes', function() {
7773

78-
it('should sort ascending with width.', function() {
74+
it('should sort ascending with columns.', function() {
7975
w.nodes = [{x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}, {x: 0, y: 1}];
8076
e.prototype._sortNodes.call(w, 1);
8177
expect(w.nodes).toEqual([{x: 0, y: 1}, {x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}]);
8278
});
8379

84-
it('should sort descending with width.', function() {
80+
it('should sort descending with columns.', function() {
8581
w.nodes = [{x: 7, y: 0}, {x: 4, y: 4}, {x: 9, y: 0}, {x: 0, y: 1}];
8682
e.prototype._sortNodes.call(w, -1);
8783
expect(w.nodes).toEqual([{x: 9, y: 0}, {x: 4, y: 4}, {x: 7, y: 0}, {x: 0, y: 1}]);
8884
});
8985

90-
it('should sort ascending without width.', function() {
91-
w.width = false;
86+
it('should sort ascending without columns.', function() {
87+
w.columns = undefined;
9288
w.nodes = [{x: 7, y: 0, width: 1}, {x: 4, y: 4, width: 1}, {x: 9, y: 0, width: 1}, {x: 0, y: 1, width: 1}];
9389
e.prototype._sortNodes.call(w, 1);
9490
expect(w.nodes).toEqual([{x: 7, y: 0, width: 1}, {x: 9, y: 0, width: 1}, {x: 0, y: 1, width: 1}, {x: 4, y: 4, width: 1}]);
9591
});
9692

97-
it('should sort descending without width.', function() {
98-
w.width = false;
93+
it('should sort descending without columns.', function() {
94+
w.columns = undefined;
9995
w.nodes = [{x: 7, y: 0, width: 1}, {x: 4, y: 4, width: 1}, {x: 9, y: 0, width: 1}, {x: 0, y: 1, width: 1}];
10096
e.prototype._sortNodes.call(w, -1);
10197
expect(w.nodes).toEqual([{x: 4, y: 4, width: 1}, {x: 0, y: 1, width: 1}, {x: 9, y: 0, width: 1}, {x: 7, y: 0, width: 1}]);
@@ -224,7 +220,7 @@ describe('gridstack', function() {
224220
var options = {
225221
cellHeight: 80,
226222
verticalMargin: 10,
227-
width: 12
223+
columns: 12
228224
};
229225
$('.grid-stack').gridstack(options);
230226
var grid = $('.grid-stack').data('gridstack');
@@ -235,7 +231,7 @@ describe('gridstack', function() {
235231
var options = {
236232
cellHeight: 80,
237233
verticalMargin: 10,
238-
width: 10
234+
columns: 10
239235
};
240236
$('.grid-stack').gridstack(options);
241237
var grid = $('.grid-stack').data('gridstack');
@@ -255,7 +251,7 @@ describe('gridstack', function() {
255251
var options = {
256252
cellHeight: 80,
257253
verticalMargin: 10,
258-
width: 12
254+
columns: 12
259255
};
260256
$('.grid-stack').gridstack(options);
261257
var grid = $('.grid-stack').data('gridstack');
@@ -266,7 +262,7 @@ describe('gridstack', function() {
266262
var options = {
267263
cellHeight: 80,
268264
verticalMargin: 10,
269-
width: 10
265+
columns: 10
270266
};
271267
$('.grid-stack').gridstack(options);
272268
var grid = $('.grid-stack').data('gridstack');

src/gridstack.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,15 @@ interface GridstackOptions {
436436
/** draggable handle class (e.g. 'grid-stack-item-content'). If set 'handle' is ignored (default?: null) */
437437
handleClass?: string;
438438

439+
/**
440+
* number of columns (default?: 12). Note: IF you change this, CSS also have to change. See https://github.com/gridstack/gridstack.js#change-grid-columns
441+
*/
442+
columns?: number;
443+
439444
/**
440445
* maximum rows amount. Default? is 0 which means no maximum rows
441446
*/
442-
height?: number;
447+
maxRows?: number;
443448

444449
/**
445450
* enable floating widgets (default?: false) See example (http://gridstack.github.io/gridstack.js/demo/float.html)
@@ -513,10 +518,5 @@ interface GridstackOptions {
513518
* (internal?) unit for verticalMargin (default? 'px')
514519
*/
515520
verticalMarginUnit?: string;
516-
517-
/**
518-
* number of columns (default?: 12)
519-
*/
520-
width?: number;
521521
}
522522

0 commit comments

Comments
 (0)