Détail du package

fcadgridstack

Clint6521see GridStack root license5.0.15-dev

TypeScript/JS lib for dashboard layout and creation, no external dependencies, with many wrappers (React, Angular, Vue, Ember, knockout...)

Typescript, gridstack.js, grid, gridster

readme

gridstack.js

NPM version Dependency Status devDependency Status Coverage Status downloads

Mobile-friendly modern Typescript library for dashboard layout and creation. Making a drag-and-drop, multi-column responsive dashboard has never been easier. Has multiple bindings and works great with React, Vue, Angular, Knockout.js, Ember and others (see frameworks section).

Inspired by no-longer maintained gridster, built with love.

Check http://gridstackjs.com and these demos.

If you find this lib useful, please donate PayPal (use “send to a friend” to avoid 3% fee) or Venmo (adumesny) and help support it!

Donate Donate

Join us on Slack: https://gridstackjs.troolee.com

Slack Status

Table of Contents generated with DocToc

Demo and examples

Please visit http://gridstackjs.com and these demos

Usage

Install

NPM version

yarn add gridstack
// or
npm install --save gridstack

Include

ES6 or Typescript

import 'gridstack/dist/gridstack.min.css';
import { GridStack } from 'gridstack';
// THEN to get HTML5 drag&drop
import 'gridstack/dist/h5/gridstack-dd-native';
// OR to get legacy jquery-ui drag&drop (support Mobile touch devices, h5 does not yet)
import 'gridstack/dist/jq/gridstack-dd-jqueryui';
// OR nothing to get static grids (API driven, no user drag&drop)

Note: jquery & jquery-ui are imported by name, so you will have to specify their location in your webpack (or equivalent) config file, which means you can possibly bring your own version

  alias: {
    'jquery': 'gridstack/dist/jq/jquery.js',
    'jquery-ui': 'gridstack/dist/jq/jquery-ui.js',
    'jquery.ui': 'gridstack/dist/jq/jquery-ui.js',
    'jquery.ui.touch-punch': 'gridstack/dist/jq/jquery.ui.touch-punch.js',
  },

Alternatively (single combined file) in html

<link href="node_modules/gridstack/dist/gridstack.min.css" rel="stylesheet"/>
<!-- HTML5 drag&drop (70k) -->
<script src="node_modules/gridstack/dist/gridstack-h5.js"></script>
<!-- OR jquery-ui drag&drop (195k) -->
<script src="node_modules/gridstack/dist/gridstack-jq.js"></script>
<!-- OR static grid (40k) -->
<script src="node_modules/gridstack/dist/gridstack-static.js"></script>

Note: the API is the same, regardless of the plugin (or lack thereof) so you can switch at any time. The Jquery version will export $ that it bundles and currently the only one to support mobile/touch devices through jquery.ui.touch-punch (h5 version is planned). Read more at migrating to v3

Note2: IE support was dropped in v2, but restored in v4.4 by an external contributor (I have no interest in testing+supporting obsolete browser so this might break in the future). You can use the es5 files and polyfill (larger) for older browser instead. For example:

<link href="node_modules/gridstack/dist/gridstack.min.css" rel="stylesheet"/>
<script src="node_modules/gridstack/dist/es5/gridstack-poly.js"></script>
<script src="node_modules/gridstack/dist/es5/gridstack-jq.js"></script>

Basic usage

creating items dynamically...

// ...in your HTML
<div class="grid-stack"></div>

// ...in your script
var grid = GridStack.init();
grid.addWidget({w: 2, content: 'item 1'});

... or creating from list

// using serialize data instead of .addWidget()
const serializedData = [
  {x: 0, y: 0, w: 2, h: 2},
  {x: 2, y: 3, w: 3, content: 'item 2'},
  {x: 1, y: 3}
];

grid.load(serializedData);

... or DOM created items

// ...in your HTML
<div class="grid-stack">
  <div class="grid-stack-item">
    <div class="grid-stack-item-content">Item 1</div>
  </div>
  <div class="grid-stack-item" gs-w="2">
    <div class="grid-stack-item-content">Item 2 wider</div>
  </div>
</div>

// ...in your script
GridStack.init();

see jsfiddle sample as running example too.

Requirements

GridStack no longer requires external dependencies as of v1.0.0 (lodash was removed in v0.5.0 and jquery API in v1.0.0). v3.0.0 is a complete HTML5 re-write which removes all jquery dependency (still available for legacy apps). All you need to include now is gridstack-h5.js and gridstack.min.css (layouts are done using CSS column based %).

API Documentation

Documentation can be found here.

Extend Library

You can easily extend or patch gridstack with code like this:

// extend gridstack with our own custom method
GridStack.prototype.printCount = function() {
  console.log('grid has ' + this.engine.nodes.length + ' items');
};

let grid = GridStack.init();

// you can now call
grid.printCount();

Change grid columns

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:

1) Change the column grid option when creating a grid to your number N

GridStack.init( {column: N} );

2) include gridstack-extra.css if N < 12 (else custom CSS - see next). Without these, things will not render/work correctly.

<link href="node_modules/gridstack/dist/gridstack-extra.css" rel="stylesheet"/>

<div class="grid-stack">...</div>

Note: class .grid-stack-N will automatically be added and we include gridstack-extra.css which defines CSS for grids with custom [2-11] columns. Anything more and you'll need to generate the SASS/CSS yourself (see next).

See example: 2 grids demo with 6 columns

Custom columns CSS

If you need > 12 columns or want to generate the CSS manually you will need to generate CSS rules for .grid-stack-item[gs-w="X"] and .grid-stack-item[gs-x="X"].

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

.grid-stack-item[gs-w="3"]  { width: 100% }
.grid-stack-item[gs-w="2"]  { width: 66.67% }
.grid-stack-item[gs-w="1"]  { width: 33.33% }

.grid-stack-item[gs-x="2"]  { left: 66.67% }
.grid-stack-item[gs-x="1"]  { left: 33.33% }

For 4-column grid it should be:

.grid-stack-item[gs-w="4"]  { width: 100% }
.grid-stack-item[gs-w="3"]  { width: 75% }
.grid-stack-item[gs-w="2"]  { width: 50% }
.grid-stack-item[gs-w="1"]  { width: 25% }

.grid-stack-item[gs-x="3"]  { left: 75% }
.grid-stack-item[gs-x="2"]  { left: 50% }
.grid-stack-item[gs-x="1"]  { left: 25% }

and so on.

Better yet, here is a SASS code snippet which can make life much easier (Thanks to @ascendantofrain, #81 and @StefanM98, #868) and you can use sites like sassmeister.com to generate the CSS for you instead:

@use "sass;math";
.grid-stack > .grid-stack-item {

  $gridstack-columns: 12;

  min-width: math.div(100%, $gridstack-columns);

  @for $i from 0 through $gridstack-columns {
    &[gs-w='#{$i}'] { width: math.div(100%, $gridstack-columns) * $i; }
    &[gs-x='#{$i}'] { left: math.div(100%, $gridstack-columns) * $i; }
    &[gs-min-w='#{$i}'] { min-width: math.div(100%, $gridstack-columns) * $i; }
    &[gs-max-w='#{$i}'] { max-width: math.div(100%, $gridstack-columns) * $i; }
  }
}

you can also use the SASS src/gridstack-extra.scss included in NPM package and modify to add more columns.

Sample gulp command for 30 columns:

gulp.src('node_modules/gridstack/dist/src/gridstack-extra.scss')
        .pipe(replace('$gridstack-columns: 11 !default;','$gridstack-columns: 30;'))
        .pipe(sass({outputStyle: 'compressed'}))
        .pipe(rename({extname: '.min.css'}))
        .pipe(gulp.dest('dist/css'))

Override resizable/draggable options

You can override default resizable/draggable options. For instance to enable other then bottom right resizing handle you can init gridstack like:

GridStack.init({
  resizable: {
    handles: 'e,se,s,sw,w'
  }
});

Touch devices support

gridstack v3.2 jq version compiles touch support (html5 version does not yet support touchmove events. This will be added in a future release), so it works out of the box, no need for anything. You used to need jQuery UI Touch Punch to make jQuery UI Draggable/Resizable work on touch-based devices (now distributed as dist/jq/jquery.ui.touch-punch.js for reference).

This option will be useful:

let options = {
  alwaysShowResizeHandle: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
};
GridStack.init(options);

See example. If you're still experiencing issues on touch devices please check #444

gridstack.js for specific frameworks

search for 'gridstack' under NPM for latest, more to come...

Migrating

Migrating to v0.6

starting in 0.6.x change event are no longer sent (for pretty much most nodes!) when an item is just added/deleted unless it also changes other nodes (was incorrect and causing inefficiencies). You may need to track added|removed events if you didn't and relied on the old broken behavior.

Migrating to v1

v1.0.0 removed Jquery from the API and external dependencies, which will require some code changes. Here is a list of the changes:

  1. see previous step if not on v0.6 already

  2. your code only needs to import GridStack from 'gridstack' or include gridstack.all.js and gristack.css (don't include other JS) and is recommended you do that as internal dependencies will change over time. If you are jquery based, see jquery app section.

  3. code change:

OLD initializing code + adding a widget + adding an event:

// initialization returned Jquery element, requiring second call to get GridStack var
var grid = $('.grid-stack').gridstack(opts?).data('gridstack');

// returned Jquery element
grid.addWidget($('<div><div class="grid-stack-item-content"> test </div></div>'), undefined, undefined, 2, undefined, true);

// jquery event handler
$('.grid-stack').on('added', function(e, items) {/* items contains info */});

// grid access after init
var grid = $('.grid-stack').data('gridstack');

NEW

// element identifier defaults to '.grid-stack', returns the grid
// Note: for Typescript use window.GridStack.init() until next native 2.x TS version
var grid = GridStack.init(opts?, element?);

// returns DOM element
grid.addWidget('<div><div class="grid-stack-item-content"> test </div></div>', {width: 2});
// Note: in 3.x it's ever simpler 
// grid.addWidget({w:2, content: 'test'})

// event handler
grid.on('added', function(e, items) {/* items contains info */});

// grid access after init
var grid = el.gridstack; // where el = document.querySelector('.grid-stack') or other ways...

Other rename changes

`GridStackUI` --> `GridStack`
`GridStackUI.GridStackEngine` --> `GridStack.Engine`
`grid.container` (jquery grid wrapper) --> `grid.el` // (grid DOM element)
`grid.grid` (GridStackEngine) --> `grid.engine`
`grid.setColumn(N)` --> `grid.column(N)` and `grid.column()` // to get value, old API still supported though

Recommend looking at the many samples for more code examples.

Migrating to v2

make sure to read v1 migration first!

v2 is a Typescript rewrite of 1.x, removing all jquery events, using classes and overall code cleanup to support ES6 modules. Your code might need to change from 1.x

  1. In general methods that used no args (getter) vs setter can't be used in TS when the arguments differ (set/get are also not function calls so API would have changed). Instead we decided to have all set methods return GridStack to they can be chain-able (ex: grid.float(true).cellHeight(10).column(6)). Also legacy methods that used to take many parameters will now take a single object (typically GridStackOptions or GridStackWidget).
`addWidget(el, x, y, width, height)` --> `addWidget(el, {with: 2})`
// Note: in 2.1.x you can now just do addWidget({with: 2, content: "text"})
`float()` --> `getFloat()` // to get value
`cellHeight()` --> `getCellHeight()` // to get value
`verticalMargin` --> `margin` // grid options and API that applies to all 4 sides.
`verticalMargin()` --> `getMargin()` // to get value
  1. event signatures are generic and not jquery-ui dependent anymore. gsresizestop has been removed as resizestop|dragstop are now called after the DOM attributes have been updated.

  2. oneColumnMode would trigger when window.width < 768px by default. We now check for grid width instead (more correct and supports nesting). You might need to adjust grid minWidth or disableOneColumnMode.

Note: 2.x no longer support legacy IE11 and older due to using more compact ES6 output and typecsript native code. You will need to stay at 1.x

Migrating to v3

make sure to read v2 migration first!

v3 has a new HTML5 drag&drop plugging (63k total, all native code), while still allowing you to use the legacy jquery-ui version instead (188k), or a new static grid version (34k, no user drag&drop but full API support). You will need to decide which version to use as gridstack.all.js no longer exist (same is now gridstack-jq.js) - see include info.

NOTE: HTML5 version is almost on parity with the old jquery-ui based drag&drop. the containment (prevent a child from being dragged outside it's parent) and revert (not clear what it is for yet) are not yet implemented in initial release of v3.0.0.
Also mobile devices don't support h5 drag events (will need to handle touch) whereas v3.2 jq version now now supports out of the box (see v3.2 release)

Breaking changes:

  1. include (as mentioned) need to change

  2. GridStack.update(el, opt) now takes single GridStackWidget options instead of only supporting (x,y,w,h) BUT legacy call in JS will continue working the same for now. That method is a complete re-write and does the right constrain and updates now for all the available params.

  3. locked(), move(), resize(), minWidth(), minHeight(), maxWidth(), maxHeight() methods are hidden from Typescript (JS can still call for now) as they are just 1 liner wrapper around update(el, opt) anyway and will go away soon. (ex: move(el, x, y) => update(el, {x, y}))

  4. item attribute like data-gs-min-width is now gs-min-w. We removed 'data-' from all attributes, and shorten 'width|height' to just 'w|h' to require less typing and more efficient (2k saved in .js alone!).

  5. GridStackWidget used in most API width|height|minWidth|minHeight|maxWidth|maxHeight are now shorter w|h|minW|minH|maxW|maxH as well

Migrating to v4

make sure to read v3 migration first!

v4 is a complete re-write of the collision and drag in/out heuristics to fix some very long standing request & bugs. It also greatly improved usability. Read the release notes for more detail.

Unlikely Breaking Changes (internal usage):

  1. removeTimeout was removed (feedback over trash will be immediate - actual removal still on mouse up)

  2. the following GridStackEngine methods changed (used internally, doesn't affect GridStack public API)

// moved to 3 methods with new option params to support new code and pixel coverage check
`collision()` -> `collide(), collideAll(), collideCoverage()`
`moveNodeCheck(node, x, y, w, h)` -> `moveNodeCheck(node, opt: GridStackMoveOpts)`
`isNodeChangedPosition(node, x, y, w, h)` -> `changedPosConstrain(node, opt: GridStackMoveOpts)`
`moveNode(node, x, y, w, h, noPack)` -> `moveNode(node, opt: GridStackMoveOpts)`
  1. removed old obsolete (v0.6-v1 methods/attrs) getGridHeight(), verticalMargin, data-gs-current-height, locked(), maxWidth(), minWidth(), maxHeight(), minHeight(), move(), resize()

Migrating to v5

make sure to read v4 migration first!

v5 does not have any breaking changes from v4, but a focus on nested grids in h5 mode: You can now drag in/out of parent into nested child, with new API parameters values. See the release notes.

jQuery Application

We now have a native HTML5 drag'n'drop through the plugin system (default), but the jquery-ui version can be used instead. It will bundle jquery (3.5.1) + jquery-ui (1.12.1 minimal drag|drop|resize) + jquery-ui-touch-punch (1.0.8 for mobile support) in gridstack-jq.js.

NOTE: in v4, v3: we ES6 module import jquery & jquery-ui by name, so you need to specify location of those .js files, which means you might be able to bring your own version as well. See the include instructions.

NOTE: in v1.x IFF you want to use gridstack-jq instead and your app needs to bring your own JQ version, you should instead include gridstack-poly.min.js (optional IE support) + gridstack.min.js + gridstack.jQueryUI.min.js after you import your JQ libs. But note that there are issue with jQuery and ES6 import (see 1306).

As for events, you can still use $(".grid-stack").on(...) for the version that uses jquery-ui for things we don't support.

Changes

View our change log here.

The Team

gridstack.js is currently maintained by Alain Dumesny and Dylan Weiss, originally created by Pavel Reznikov. We appreciate all contributors for help.

changelog

Change log

Table of Contents generated with DocToc

5.0.0-dev (TBD)

5.0.0 (2022-01-10)

  • add #992 support dragging into and out of nested grids from parents! Thank you @arclogos132 for sponsoring it.
  • add #1910 new column:'auto' option to size nested grids to their parent grid item column count, keeping items the same size inside and outside. Thank you @arclogos132 for also sponsoring it.
  • fix #1902 nested.html: dragging between sub-grids show items clipped
  • fix #1558 dragging between vertical grids causes too much growth, not follow mouse.
  • fix #1912 no longer force rows for min-height
  • fix #1888 locks up with nested grid when 'column' is set to 1

4.4.1 (2021-12-24)

  • fix #1901 error introduced for #1785 when re-loading with fewer objects

4.4.0 (2021-12-21)

  • add #1887 support for IE (new es5 folder) by @SmileLifeIven
  • fix #1785 overlapping items when switching column() and making edits. Thank you @radovanobal for sponsoring it.
  • fix #1890 unhandled exception when dragging fast between grids.

4.3.1 (2021-10-18)

  • fix #1868 prevent swap during resize
  • fix #1849 #1816 save highest resolution in 1 column mode
  • fix #1855 resize when padding is large vs cellHeight

4.3.0 (2021-10-15)

  • you can now swap items of different width if they are the same row/height. Thanks to spektrummedia for sponsoring it.
  • fix #1860 nested grid save inf loop fix
  • use latest dart-sass, updated comments

4.2.7 (2021-9-12)

  • fix #1817 Enable passing of DragEvent to gridstack dropped event. Thanks @onepartsam
  • fix #1835 Layout incorrectly restored when node has a minimum width. Thanks @hssm
  • fix #1794 addGrid() does not recognize rem cellHeightUnit

4.2.6 (2021-7-11)

  • fix #1784 removable:true working by itself (without needing acceptWidgets:true)
  • fix #1791 removed drag flicker and scroll issue. Thanks @nelsieborja
  • fix #1795 save(false) will no longer have .content field (removed existing one if present)
  • fix #1782 save(false, false) now correctly saves nested grids
  • fix #1793 save(false, true) followed by enable() throws error. we now have new Utils.cloneDeep()

4.2.5 (2021-5-31)

  • fix for website with JQ droppable('destroy') giving error

4.2.4 (2021-5-29)

  • fix #1760 removable:true working again (broke in 4.x)
  • fix #1761 staticGrid(false) will now enable drag in behavior (if set)
  • fix #1767 locked item can be user moved/resized again, just not pushed by other nodes (broke in 1.1.1)
  • fix #1764 destroy(false) can now re-init properly (doesn't force static grid)

4.2.3 (2021-5-8)

  • Utils.getScrollParent() -> getScrollElement() rename
  • fix #1745 digression on scrolling in v4.2.1. Thanks @Manfred-on-github for fixing your prev change.

4.2.2 (2021-4-23)

4.2.1 (2021-4-18)

  • fix #1700 JQ nested grid drag fix broken in 4.0.3 (but much older underlying issue)
  • fix #1678 item gs-x:0 not animating fix
  • fix #1727 resize-scroll issue when grid is not at top of page. Thanks @Manfred-on-github
  • fix #1728 fix sizing from top/left sides

4.2.0 (2021-4-11)

  • fix #1704 scrollbar fix broken in 4.x
  • fix #1655 addWidget() while in 1 column now remembers original wanted width
  • add #1727 addWidget() now supports nested grids like init/addGrid() does.

4.1.0 (2021-4-7)

  • fix #219 fixing another 6 years old request we now automatically insert extra rows when dragging an item at the bottom below others to make it easier to insert below.
  • fix #1687 more fix for drag between 2 grids with row / maxRow broken in 4.x
  • fix export symbols .d.ts for gridstack-h5.js | gridstack-jq.js | gridstack-static.js
  • fix #1709 correct info for using JQ version and ES6 (tested in Angular app)

4.0.3 (2021-3-28)

  • fix #1693 load after init() broken in 4.x
  • fix #1687 drag between 2 grids with row / maxRow broken in 4.x
  • fix #1676 drag edge case in/out single grid without acceptWidgets fix broken in 4.x

4.0.2 (2021-3-27)

  • fix #1679 Resizable: {handles:'w/sw'} broken in 4.x
  • fix #1658 enableMove(T/F) not working correctly
  • fix helper: myFunction now working for H5 case for dragInOptions & setupDragIn() broken in 3.x
  • fix prevent addGrid() from creating nested div grid if container already is a '.grid-stack' div

4.0.1 (2021-3-20)

  • fix #1669 JQ resize broken in 4.x
  • fix #1661 serialization of nested grid

4.0.0 (2021-3-19)

  • fix #149 #1094 #1605 #1534 re-write of the collision code - fixing 6 years old most requested request
  • you can now swap items of the same size (vertical/horizontal) when grid is full, and is the default in float:false (top gravity) as it feels more natural. Could add Alt key for swap vs push behavior later.
  • Dragging up and down now behave the same (used to require push WAY down past to swap/append). Also much more efficient collision code.
  • handle mid point of dragged over items (>50%) rather than just a new row/column and check for the most covered item when multiple collide.

  • fix #393 #1612 #1578 re-write of the drag in/out code - fixing 5 years old bug

  • we now remove item when cursor leaves (acceptWidgets case using dropout event) or shape is outside (re-using same method) and re-insert on cursor enter (since we only get dropover event). Should not be possible to have 2 placeholders which confuses the grids.
  • major re-write and cleanup of the drag in/out. Vars have been renamed and fully documented as I couldn't understand the legacy buggy code.
  • removed any over trash delay feedback as I don't see the point and could introduce race conditions.

  • fix 1617 FireFox DOM order issue. Thanks @marcel-necker

  • fix changing column # column(n) now resizes cellHeight:'auto' to keep square
  • add 1616 drag | resize events while dragging. Thanks @MrCorba
  • add 1637 GridStack.setupDragIn() so user can update external draggable after the grid has been created

3.3.0 (2021-2-2)

  • big re-write on how cellHeight() works. you can now call it at any time (not just grid init options) including switching to 'auto' or other modes on the fly.
  • fix cellHeight:auto now keeps cell square as window resizes (regressing from 2.x TS conversion). Utils.throttle() works better too (guaranteed to be called last event)
  • new cellHeight:initial which makes the cell squares initially, but doesn't change as windows resizes (better performance)
  • new grid option cellHeightThrottle (100ms) to control throttle of auto sizing triggers
  • fix 1600 height too small with cellHeight:auto loading in 1 column. Now detect we load at 1 column and size accordingly (default 'auto' could make big 700x700 cells, so explicit px might still be wanted)
  • fix 1538 loading nested into small size and sizing back up
  • fix 1604 nested grid resizing fix
  • fix 1599 resize from left side can move item right

3.2.0 (2021-1-25)

  • fix 1413 website & lib works on mobile. We now compile the latest v1.0.8 jquery.ui.touch-punch into the JQ version (only 2k) so mobile devices (android, iphone, ipad, ms surface, etc...) are supported out of the box. HTML5 version will require re-write to plain mousemove & mobile touchmove instead of drag events in a future release.
  • small optimizations (create placeholder content on the fly, moved more DD code into draggable class)

3.1.5 (2021-1-23)

  • fix 1572 column: N option now sets CSS class
  • fix 1571 don't allow drop when grid is full
  • fix 1570 easier to drag out/in from below
  • fix 1579 cellHeight() not updating CSS correctly
  • fix 1581 H5 draggable by actual div handle rather than entire item (let content respond to drag as well)

3.1.4 (2021-1-11)

  • fix 1557 fix no-drop cursor on windows when dragging within a default grid (no external drag in)
  • fix 1541 fix Safari H5 delay when dropping items

3.1.3 (2021-1-2)

  • fix 1540 Safari H5 drag&drop fixed
  • fix 1535 use batchUpdate() around grid init to make sure gs-y attributes are respected.
  • fix 1545 disableMove() correctly prevents drag later (remove events and draggable attribute)
  • fix 1546 resize no longer delayed, which caused race conditions errors
  • fix 1001 resizing near bottom/top needs to auto-scroll/. thanks @hbcarlos!

3.1.2 (2020-12-7)

  • fix 1419 dragging into a fixed row grid works better (check if it will fit, else try to append, else won't insert) -- possible BREAK (unlikely you use engine directly)
  • engine constructor takes Options struct rather than spelling arguments (easier to extend/use)
  • canBePlacedWithRespectToHeight() -> willItFit() like grid method

  • fix 1330 maxW does not work as intended with resizable handle "w"

  • fix 1472 support all options for new dragged in widgets (read all gs-xyz attributes)
  • fix 1511 dragging any grid item content works
  • fix 1438 web-component fixes & grid with 0 size initially.

3.1.0 (2020-12-4)

  • add new addGrid(parent, opts) to create a grid and load children instead of init() + load(), which is used by load() to supports nested grids creation. see nested.html demo.
  • save() will now work on nested grids, recursively saving info. added flag to also allow saving the current grid options + children (needed for nested grids) so you can now call new adddGrid() to re-create everything from JSON.
  • fix 1505 don't call movable()/resizable() on locked items error. thanks @infime
  • fix 1517 force typescript 3.6 as 3.7 has breaking change

3.0.0 (2020-11-29)

  • the big news is we finally have a native HTML5 drag&drop plugin (zero jquery)! Huge thanks to @rhlin for creating this in stealth mode. Read all about it in main doc.
  • we now have a React example, in addition to Vue - Angular is next!. thanks @eloparco
  • fix placeholder not having custom GridStackOptions.itemClass. thanks @pablosichert
  • fix 1484 dragging between 2 grids and back (regression in 2.0.1)
  • fix 1471 load() into 1 column mode doesn't resize back to 12 correctly
  • fix 1235 update(el, opts) re-write to take all GridStackWidget options (not just x,y,width,height) and do everything efficiently. Hiding locked(), move(), resize(), minWidth(), etc... as they just simply call update() which does all the constrain now as well!
  • del ddPlugin grid option as we only have one drag&drop plugin at runtime, which is defined by the include you use (HTML5 vs jquery vs none)
  • change attribute data-gs-min-width is now gs-min-w. We removed 'data-' from all attributes, and shorten 'width|height' to just 'w|h' to require less typing and more efficient (2k saved in .js alone!) 1491 1492
  • also GridStackWidget used in most API width|height|minWidth|minHeight|maxWidth|maxHeight are now shorter w|h|minW|minH|maxW|maxH as well 1493
  • see migrating to v3

2.2.0 (2020-11-7)

  • add margin option now support multi values CSS format '5px 10px 0 20px' or '5em 10em'
  • add data-gs-static-grid attribute
  • fix 1435 class="ui-draggable-disabled ui-resizable-disabled" have been added back to static grid items, so existing CSS rule to style continue working
  • fix 1439 getting DOM element by id with number works (api that uses GridStackElement handle more string formats)
  • fix 1442 setting marginTop (or any 4 sides) to cause resize to break. Thanks @deadivan for suggested fix.

2.1.0 (2020-10-28)

  • fix grid static: true to no longer add any drag&drop (even disabled) which should speed things up, and setStatic(T/F) will now correctly add it back/delete for items that need it only. Also fixed JQ draggable warning if not initialized first 858
  • add addWidget(opt) now handles just passing a GridStackWidget which creates the default divs, simplifying your code. Old API still supported.
  • add save(saveContent = true) now lets you optionally save the HTML content in the node property, with load() restoring it 1418
  • add GridStackWidget.content now lets you add any HTML content when calling load()/save() or addWidget() 1418
  • add ColumnOptions to column(n, options) for multiple re-layout options, including 'none' that will preserve the x and width, until out of bound/overlap 1338 including a custom function for you to create the new layout 1332

2.0.2 (2020-10-05)

  • fix animate to not re-create CSS style each time (should be faster too) and made it default now since so much nicer. pass {animate: false} grid options if you want instant again 937
  • fix resizable: { handles: ...} forcing alwaysShowResizeHandle behavior 1373

2.0.1 (2020-09-26)

  • fix minWidth(), minHeight(), maxHeight() to set node value as well 1359
  • fix GridStackOptions spelling 1359
  • fix remove window resize event when grid.destroy() 1369
  • fix nested grid resize 1361
  • fix resize with cellHeight '6rem' '6em' not working 1356
  • fix preserve attributes (min/max/id/etc...) when dragging between grids 1367
  • fix 2 drop shadows when dragging between grids 393

2.0.0 (2020-09-07)

  • re-write to native Typescript, removing all JQuery from main code and API (drag&drop plugin still using jqueryui for now)
  • add getGridItems() to return list of HTML grid items
  • add {dragIn | dragInOptions} grid attributes to handle external drag&drop items
  • add save() and load() to serialize grids from JSON, saving all attributes (not just w,h,x,y) 1286
  • add margin to replace verticalMargin which affects both dimensions in code, rather than one in code the other in CSS. You can now have perfect square cells (default) 723
  • fix 1299 many columns round-off error
  • fix 1102 loose functionality when they are moved to a new grid
  • add optional params to removeWidget() to have quiet mode (no callbacks)
  • drop support for IE11 due to more compact ES6 output and newer TS code

1.2.1 (2020-09-04)

  • fix 1341 Enable the UMD behavior for bundlers compatibility

1.2.0 (2020-08-01)

  • fix 1311 domAttr is not defined
  • adds styleInHead option to allow for selecting older behavior (adding STYLE element to HEAD element instead of parentNode)
  • update jquery to v3.5.1

1.1.2 (2020-05-17)

  • fix 1229 staticGrid no longer disable oneColumnMode
  • fix 1195 options broken with ember hash helper - thanks @btecu
  • fix 1250 don't remove item from another grid
  • fix 1261 init() clones passed options so second doesn't affect first one
  • fix 1276 addWidget() ignores data attributes

1.1.1 (2020-03-17)

  • fix 1187 IE support for CustomEvent polyfill - thanks @phil-blais
  • fix 1204 destroy drag&drop when removing node(s) instead of just disabling it.
  • fix 1181 Locked widgets are still moveable by other widgets.
  • fix 1217 If I set cellHeight to some vh, only first grid will take vh, rest will use px
  • include SASS source files to npm package again 1193

1.1.0 (2020-02-29)

  • add minRow and row grid options (which set minRow=maxRow=N) 1172 - thanks @RadoiAndrei
  • fix 1166 resize not taking margin height into account - thanks @awjae
  • fix 1155 maxRow now limit initial item placement if out of bound, preventing broken drag behavior
  • fix 1171 added event support to call grid.on('added removed change', callback) again even with native events.

v1.0.0 (2020-02-23)

  • breaking: (1084) jquery was removed from the API and dependencies (initialize differently, and methods take/return GridStack or HTMLElement instead of JQuery), so your code will need to change. See Migrating to v1.0.0
  • setColumn(N) is now column(N) (matches other set/get methods) and getColumn() to get current column number
  • add grid.on(eventName, callback) / grid.off(eventName) to hide native JQ events mix
  • add grid.getRow() to get the current grid row number

v0.6.4 (2020-02-17)

  • fix #540 WebComponent support: CSS file now insert before grid instead of 'head'
  • fix #1143 nested grids with different acceptWidgets class
  • fix #1142 add/remove widget will also trigger change events when it should.
  • optimized change callback to save original x,y,w,h values and only call those that changed 1148
  • delete bower since dead for a while now

v0.6.3 (2020-02-05)

  • fix #1132 oneColumnMode missing CSS to do layout
  • del oneColumnModeClass / .grid-stack-one-column-mode and associated code. If you depended on this, use class .grid-stack-1 instead since it is 1 column layout anyway 1134

v0.6.2 (2020-02-03)

  • add oneColumnModeDomSort true|false to let you specify a custom layout (use dom order instead of x,y) for oneColumnMode column(1) #713
  • fix oneColumnMode to only restore if we auto went to it as window sizes up #1125
  • editing in 1 column (or few columns) does a better job updating higher layout (track before and after and move items accordingly). Tracking item swap would be even better still. #1127

v0.6.1 (2020-02-02)

  • fix #37 oneColumnMode (<768px by default) now simply calls column(1) and remembers prev columns (so we can restore). This gives us full resize/re-order of items capabilities rather than a locked CSS only layout (see prev rev changes). #1120
  • fix responsive.html demo #1121

v0.6.0 (2019-12-24)

  • add float(val) to set/get the grid float mode, which will relayout #1088
  • add compact() to reclaim any empty space and relayout grid items #1101
  • add options.dragOut to let user drag nested grid items out of a parent or not (default false) and jQuery UI draggable.containment can now be specified in options. You can now drag&drop between 2 nested grids #1105
  • add % as a valid unit for height #1093. thank you @trevisanweb @aureality @ZoolWay
  • fix callbacks to get either added, removed, change or combination if adding a node require also to change its (x,y) for example. Also you can now call batchUpdate() before calling a bunch of addWidget() and get a single event callback (more efficient). #1096
  • removeAll() is now much faster (no relayout) and calls removed event just once with a list #1097
  • column() complete re-write and is no longer "Experimental". We now do a reasonable job at sizing/position the widgets (especially 1 column) and also now cache each column layout so you can go back to say 12 column and not loose original layout. #1098
  • fix addWidget(el) (no data) would not render item at correct location, and overlap item at (0,0) #1098
  • you can now pre-define size of dragable elements from a sidebar using standard data-gs-width and data-gs-height - fix #413, #914, #918, #922, #933 thanks @ermcgrat and others for pointing out code issue.

v0.5.5 (2019-11-27)

  • min files include rev number/license #1075
  • npm package fix to exclude more temporary content #1078
  • removed jquery-ui/* requirements from AMD packing in gridstack.jQueryUI.js as it was causing App compile missing errors now that we include a subset of jquery-ui

v0.5.4 (2019-11-26)

  • fix for griditems with x=0 placement wrong order (introduced by #1017) (#1054).
  • fix cellHeight(val) not working due to style change (introduced by #937) (#1068).
  • add gridstack-poly.js for IE and older browsers, removed core-js lib from samples (<1k vs 85k), and all IE8 mentions (#1061).
  • add jquery-ui.js (and min.js) as minimal subset we need (55k vs 248k), which is now part of gridstack-h5.js. Include individual parts if you need your own lib instead of all.js (#1064).
  • changed jquery dependency to lowest we can use (>=1.8) (#629).
  • add advance demo from web site (#1073).

v0.5.3 (2019-11-20)

  • grid options width is now column, height now maxRow, and setGridWidth() now column() to match what they are. Old names are still supported (console warnings). Various fixes for custom # of column and re-wrote entire doc section (#1053).
  • fix widgets not animating when animate: true is used. on every move, styles were recreated-fix should slightly improve gridstack.js speed (#937).
  • fix moving widgets when having multiple grids. jquery-ui workaround (#1043).
  • switch to eslint (#763) thanks @rwstoneback.
  • fix null values addWidget() options (#1042).

v0.5.2 (2019-11-13)

  • fix undefined x,y position messes up grid (#1017).
  • changed code to 2 spaces.
  • fix minHeight during onStartMoving() (#999).
  • add gridstack.d.ts TypeScript definition file now included - no need to include @types/gridstack, easier to update (#1036).
  • add addWidget(el, options) to pass object so you don't have to spell 10 params. (#907).

v0.5.1 (2019-11-07)

  • reduced npm package size from 672k to 324k (drop demo, src and extra files)

v0.5.0 (2019-11-06)

  • emit dropped event when a widget is dropped from one grid into another (#823).
  • don't throw error if no bounding scroll element is found (#891).
  • don't push locked widgets even if they are at the top of the grid (#882).
  • RequireJS and CommonJS now export on the exports module fix (#643).
  • automatically scroll page when widget is moving beyond viewport (#827).
  • removed lodash dependencies (#693).
  • don't overwrite globals jQuery when in a modular environment (#974).
  • removed z-index from .grid-stack-item-content causing child modal dialog clipping (#984).
  • convert project to use yarn (#983).

v0.4.0 (2018-05-11)

  • widgets can have their own resize handles. Use data-gs-resize-handles element attribute to use. For example, data-gs-resize-handles="e,w" will make the particular widget only resize west and east. (#494).
  • enable sidebar items to be duplicated properly. Pass helper: 'clone' in draggable options. (#661, #396, #499).
  • fix staticGrid grid option (#743)
  • preserve inline styles when moving/cloning items (thanks @silverwind)
  • fix bug causing heights not to get set (#744)
  • allow grid to have min-height, fixes (#628) thanks @adumesny
  • widget x and y are now ints (thanks @DonnchaC)
  • allow all droppable options (thanks @vigor-vlad)
  • properly track mouse position in getCellFromPixel (thanks @aletorrado)
  • remove instance of !important (thanks @krilllind)
  • scroll when moving widget up or down out of viewport (#827)

v0.3.0 (2017-04-21)

  • remove placeholder when dragging widget below grid (already worked when dragging left, above, and to the right of grid).
  • prevent extra checks for removing widget when dragging off grid.
  • trigger added when a widget is added via dropping from one grid to another.
  • trigger removed when a widget is removed via dropping from one grid to another.
  • trigger removed when a widget is removed via dropping on a removable zone (#607 and #550).
  • trigger custom event for resizestop called gsresizestop (#577 and #398).
  • prevent dragging/resizing in oneColumnMode (#593).
  • add oneColumnModeClass option to grid.
  • remove 768px CSS styles, moved to grid-stack-one-column-mode class.
  • add max-width override on grid-stck-one-column-mode (#462).
  • add internal functionisNodeChangedPosition, minor optimization to move/drag.
  • drag'n'drop plugin system. Move jQuery UI dependencies to separate plugin file.

v0.2.6 (2016-08-17)

  • update requirements to the latest versions of jQuery (v3.1.0+) and jquery-ui (v1.12.0+).
  • fix jQuery size() (#486).
  • update destroy([removeDOM]) call (#422).
  • don't mutate options when calling draggable and resizable. (#505).
  • update _notify to allow detach (#411).
  • fix code that checks for jquery-ui (#481).
  • fix cellWidth calculation on empty grid

v0.2.5 (2016-03-02)

  • update names to respect js naming convention.
  • cellHeight and margin can now be string (e.g. '3em', '20px') (Thanks to @jlowcs).
  • add maxWidth/maxHeight methods.
  • add enableMove/enableResize methods.
  • fix window resize issue #331).
  • add options disableDrag and disableResize.
  • fix batchUpdate/commit (Thank to @radiolips)
  • remove dependency of FontAwesome
  • RTL support
  • 'auto' value for cellHeight option
  • fix setStatic method
  • add setAnimation method to API
  • add column method (#227)
  • add removable/removeTimeout (experimental)
  • add removeDOM parameter to destroy method (#216) (thanks @jhpedemonte)
  • add useOffset parameter to getCellFromPixel method (#237)
  • add minWidth, maxWidth, minHeight, maxHeight, id parameters to addWidget (#188)
  • add added and removed events for when a widget is added or removed, respectively. (#54)
  • add acceptWidgets parameter. Widgets can now be draggable between grids or from outside (experimental)

v0.2.4 (2016-02-15)

  • fix closure compiler/linter warnings
  • add staticGrid option.
  • add minWidth/minHeight methods (Thanks to @cvillemure)
  • add destroy method (Thanks to @zspitzer)
  • add placeholderText option (Thanks to @slauyama)
  • add handleClass option.
  • add makeWidget method.
  • lodash v 4.x support (Thanks to @andrewr88)

v0.2.3 (2015-06-23)

  • gridstack-extra.css
  • add support of lodash.js
  • add isAreaEmpty method
  • nested grids
  • add batchUpdate/commit methods
  • add update method
  • allow to override resizable/draggable options
  • add disable/enable methods
  • add getCellFromPixel (thanks to @juchi)
  • AMD support
  • fix nodes sorting
  • improved touch devices support
  • add alwaysShowResizeHandle option
  • minor fixes and improvements

v0.2.2 (2014-12-23)

  • fix grid initialization
  • add cellHeight/cellWidth API methods
  • fix boolean attributes (#31)

v0.2.1 (2014-12-09)

  • add widgets locking (#19)
  • add willItFit API method
  • fix auto-positioning (#20)
  • add animation (thanks to @ishields)
  • fix y coordinate calculation when dragging (#18)
  • fix removeWidget (#16)
  • minor fixes

v0.2.0 (2014-11-30)

  • add height option
  • auto-generate css rules (widgets height and top)
  • add GridStack.Utils.sort utility function
  • add removeAll API method
  • add resize and move API methods
  • add resizable and movable API methods
  • add data-gs-no-move attribute
  • add float option
  • fix default css rule for inner content
  • minor fixes

v0.1.0 (2014-11-18)

Very first version.