gridstack - v12.3.3
    Preparing search index...

    Class GridStack

    Main gridstack class - you will need to call GridStack.init() first to initialize your grid. Note: your grid elements MUST have the following classes for the CSS layout to work:

    <div class="grid-stack">
    <div class="grid-stack-item">
    <div class="grid-stack-item-content">Item 1</div>
    </div>
    </div>
    Index

    Constructors

    Methods

    • add or remove the grid element size event handler

      Parameters

      • forceRemove: boolean = false

      Returns GridStack

    • return our expected width (or parent) , and optionally of window for dynamic column check

      Parameters

      • forBreakpoint: boolean = false

      Returns number

    • call to create a grid with the given options, including loading any children from JSON structure. This will call GridStack.init(), then grid.load() on any passed children (recursively). Great alternative to calling init() if you want entire grid to come from JSON serialized data, including options.

      Parameters

      • parent: HTMLElement

        HTML element parent to the grid

      • opt: GridStackOptions = {}

        grids options used to initialize the grid, and list of children

      Returns GridStack

    • add a new widget and returns it.

      Widget will be always placed even if result height is more than actual grid height. You need to use willItFit() before calling addWidget for additional check. See also makeWidget(el) for DOM element.

      Parameters

      • w: GridStackWidget

        GridStackWidget definition. used MakeWidget(el) if you have dom element instead.

      Returns GridItemHTMLElement

      const grid = GridStack.init();
      grid.addWidget({w: 3, content: 'hello'});
    • use before calling a bunch of addWidget() to prevent un-necessary relayouts in between (more efficient) and get a single event callback. You will see no changes until batchUpdate(false) is called.

      Parameters

      • flag: boolean = true

      Returns GridStack

    • Update current cell height - see GridStackOptions.cellHeight for format by updating eh Browser CSS variable.

      Parameters

      • Optionalval: numberOrString

        the cell height. Options:

        • undefined: cells content will be made square (match width minus margin)
        • 0: the CSS will be generated by the application instead
        • number: height in pixels
        • string: height with units (e.g., '70px', '5rem', '2em')

      Returns GridStack

      the grid instance for chaining

      grid.cellHeight(100);     // 100px height
      grid.cellHeight('70px'); // explicit pixel height
      grid.cellHeight('5rem'); // relative to root font size
      grid.cellHeight(grid.cellWidth() * 1.2); // aspect ratio
      grid.cellHeight('auto'); // auto-size based on content
    • Gets the current cell width in pixels. This is calculated based on the grid container width divided by the number of columns.

      Returns number

      the cell width in pixels

      const width = grid.cellWidth();
      console.log('Cell width:', width, 'px');

      // Use cell width to calculate widget dimensions
      const widgetWidth = width * 3; // For a 3-column wide widget
    • checks for dynamic column count for our current size, returning true if changed

      Returns boolean

    • Set the number of columns in the grid. Will update existing widgets to conform to new number of columns, as well as cache the original layout so you can revert back to previous positions without loss.

      Requires gridstack-extra.css or gridstack-extra.min.css for [2-11] columns, else you will need to generate correct CSS. See: https://github.com/gridstack/gridstack.js#change-grid-columns

      Parameters

      • column: number

        Integer > 0 (default 12)

      • layout: ColumnOptions = 'moveScale'

        specify the type of re-layout that will happen. Options:

        • 'moveScale' (default): scale widget positions and sizes
        • 'move': keep widget sizes, only move positions
        • 'scale': keep widget positions, only scale sizes
        • 'none': don't change widget positions or sizes Note: items will never be outside of the current column boundaries. Ignored for column=1 as we always want to vertically stack.

      Returns GridStack

      the grid instance for chaining

      // Change to 6 columns with default scaling
      grid.column(6);

      // Change to 4 columns, only move positions
      grid.column(4, 'move');

      // Single column layout (vertical stack)
      grid.column(1);
    • Re-layout grid items to reclaim any empty space. This is useful after removing widgets or when you want to optimize the layout.

      Parameters

      • layout: CompactOptions = 'compact'

        layout type. Options:

        • 'compact' (default): might re-order items to fill any empty space
        • 'list': keep the widget left->right order the same, even if that means leaving an empty slot if things don't fit
      • doSort: boolean = true

        re-sort items first based on x,y position. Set to false to do your own sorting ahead (default: true)

      Returns GridStack

      the grid instance for chaining

      // Compact layout after removing widgets
      grid.removeWidget('.widget-to-remove');
      grid.compact();

      // Use list layout (preserve order)
      grid.compact('list');

      // Compact without sorting first
      grid.compact('compact', false);
    • Create the default grid item divs and content (possibly lazy loaded) by using GridStack.renderCB().

      Parameters

      • n: GridStackNode

        GridStackNode definition containing widget configuration

      Returns HTMLElement

      the created HTML element with proper grid item structure

      const element = grid.createWidgetDivs({ w: 2, h: 1, content: 'Hello World' });
      
    • Destroys a grid instance. DO NOT CALL any methods or access any vars after this as it will free up members.

      Parameters

      • removeDOM: boolean = true

        if false grid and items HTML elements will not be removed from the DOM (Optional. Default true).

      Returns GridStack

    • Temporarily disables widgets moving/resizing. If you want a more permanent way (which freezes up resources) use setStatic(true) instead.

      Note: This is a no-op for static grids.

      This is a shortcut for:

      grid.enableMove(false);
      grid.enableResize(false);

      Parameters

      • recurse: boolean = true

        if true (default), sub-grids also get updated

      Returns GridStack

      the grid instance for chaining

      // Disable all interactions
      grid.disable();

      // Disable only this grid, not sub-grids
      grid.disable(false);
    • Re-enables widgets moving/resizing - see disable(). Note: This is a no-op for static grids.

      This is a shortcut for:

      grid.enableMove(true);
      grid.enableResize(true);

      Parameters

      • recurse: boolean = true

        if true (default), sub-grids also get updated

      Returns GridStack

      the grid instance for chaining

      // Re-enable all interactions
      grid.enable();

      // Enable only this grid, not sub-grids
      grid.enable(false);
    • Enables/disables widget moving for all widgets. No-op for static grids. Note: locally defined items (with noMove property) still override this setting.

      Parameters

      • doEnable: boolean

        if true widgets will be movable, if false moving is disabled

      • recurse: boolean = true

        if true (default), sub-grids also get updated

      Returns GridStack

      the grid instance for chaining

      // Enable moving for all widgets
      grid.enableMove(true);

      // Disable moving for all widgets
      grid.enableMove(false);

      // Enable only this grid, not sub-grids
      grid.enableMove(true, false);
    • Enables/disables widget resizing for all widgets. No-op for static grids. Note: locally defined items (with noResize property) still override this setting.

      Parameters

      • doEnable: boolean

        if true widgets will be resizable, if false resizing is disabled

      • recurse: boolean = true

        if true (default), sub-grids also get updated

      Returns GridStack

      the grid instance for chaining

      // Enable resizing for all widgets
      grid.enableResize(true);

      // Disable resizing for all widgets
      grid.enableResize(false);

      // Enable only this grid, not sub-grids
      grid.enableResize(true, false);
    • Enable/disable floating widgets (default: false). When enabled, widgets can float up to fill empty spaces. See example

      Parameters

      • val: boolean

        true to enable floating, false to disable

      Returns GridStack

      the grid instance for chaining

      grid.float(true);  // Enable floating
      grid.float(false); // Disable floating (default)
    • Get the position of the cell under a pixel on screen.

      Parameters

      • position: MousePosition

        the position of the pixel to resolve in absolute coordinates, as an object with top and left properties

      • useDocRelative: boolean = false

        if true, value will be based on document position vs parent position (Optional. Default false). Useful when grid is within position: relative element

        Returns an object with properties x and y i.e. the column and row in the grid.

      Returns CellPosition

    • Gets the current cell height in pixels. This takes into account the unit type and converts to pixels if necessary.

      Parameters

      • forcePixel: boolean = false

        if true, forces conversion to pixels even when cellHeight is specified in other units

      Returns number

      the cell height in pixels

      const height = grid.getCellHeight();
      console.log('Cell height:', height, 'px');

      // Force pixel conversion
      const pixelHeight = grid.getCellHeight(true);
    • Get the number of columns in the grid (default 12).

      Returns number

      the current number of columns in the grid

      const columnCount = grid.getColumn(); // returns 12 by default
      
    • Get the global drag & drop implementation instance. This provides access to the underlying drag & drop functionality.

      Returns DDGridStack

      the DDGridStack instance used for drag & drop operations

      const dd = GridStack.getDD();
      // Access drag & drop functionality
    • Get the current float mode setting.

      Returns boolean

      true if floating is enabled, false otherwise

      const isFloating = grid.getFloat();
      console.log('Floating enabled:', isFloating);
    • Returns an array of grid HTML elements (no placeholder) - used to iterate through our children in DOM order. This method excludes placeholder elements and returns only actual grid items.

      Returns GridItemHTMLElement[]

      array of GridItemHTMLElement instances representing all grid items

      const items = grid.getGridItems();
      items.forEach(item => {
      console.log('Item ID:', item.gridstackNode.id);
      });
    • Returns the current margin value as a number (undefined if the 4 sides don't match). This only returns a number if all sides have the same margin value.

      Returns number

      the margin value in pixels, or undefined if sides have different values

      const margin = grid.getMargin();
      if (margin !== undefined) {
      console.log('Uniform margin:', margin, 'px');
      } else {
      console.log('Margins are different on different sides');
      }
    • Returns the current number of rows, which will be at least minRow if set. The row count is based on the highest positioned widget in the grid.

      Returns number

      the current number of rows in the grid

      const rowCount = grid.getRow();
      console.log('Grid has', rowCount, 'rows');
    • initializing the HTML element, or selector string, into a grid will return the grid. Calling it again will simply return the existing instance (ignore any passed options). There is also an initAll() version that support multiple grids initialization at once. Or you can use addGrid() to create the entire grid from JSON.

      Parameters

      • options: GridStackOptions = {}

        grid options (optional)

      • elOrString: GridStackElement = '.grid-stack'

        element or CSS selector (first one used) to convert to a grid (default to '.grid-stack' class selector)

      Returns GridStack

      const grid = GridStack.init();

      Note: the HTMLElement (of type GridHTMLElement) will store a `gridstack: GridStack` value that can be retrieve later
      const grid = document.querySelector('.grid-stack').gridstack;
    • Will initialize a list of elements (given a selector) and return an array of grids.

      Parameters

      • options: GridStackOptions = {}

        grid options (optional)

      • selector: string = '.grid-stack'

        elements selector to convert to grids (default to '.grid-stack' class selector)

      Returns GridStack[]

      const grids = GridStack.initAll();
      grids.forEach(...)
    • Checks if the specified rectangular area is empty (no widgets occupy any part of it).

      Parameters

      • x: number

        the x coordinate (column) of the area to check

      • y: number

        the y coordinate (row) of the area to check

      • w: number

        the width in columns of the area to check

      • h: number

        the height in rows of the area to check

      Returns boolean

      true if the area is completely empty, false if any widget overlaps

      // Check if a 2x2 area at position (1,1) is empty
      if (grid.isAreaEmpty(1, 1, 2, 2)) {
      console.log('Area is available for placement');
      }
    • Returns true if change callbacks should be ignored due to column change, sizeToContent, loading, etc. This is useful for callers who want to implement dirty flag functionality.

      Returns boolean

      true if change callbacks are currently being ignored

      if (!grid.isIgnoreChangeCB()) {
      // Process the change event
      console.log('Grid layout changed');
      }
    • Load widgets from a list. This will call update() on each (matching by id) or add/remove widgets that are not there. Used to restore a grid layout for a saved layout list (see save()).

      Parameters

      • items: GridStackWidget[]

        list of widgets definition to update/create

      • addRemove: boolean | AddRemoveFcn = ...

        boolean (default true) or callback method can be passed to control if and how missing widgets can be added/removed, giving the user control of insertion.

      Returns GridStack

      the grid instance for chaining

      // Basic usage with saved layout
      const savedLayout = grid.save(); // Save current layout
      // ... later restore it
      grid.load(savedLayout);

      // Load with custom add/remove callback
      grid.load(layout, (items, grid, add) => {
      if (add) {
      // Custom logic for adding new widgets
      items.forEach(item => {
      const el = document.createElement('div');
      el.innerHTML = item.content || '';
      grid.addWidget(el, item);
      });
      } else {
      // Custom logic for removing widgets
      items.forEach(item => grid.removeWidget(item.el));
      }
      });

      // Load without adding/removing missing widgets
      grid.load(layout, false);
    • Convert an existing gridItem element into a sub-grid with the given (optional) options, else inherit them from the parent's subGrid options.

      Parameters

      • el: GridItemHTMLElement

        gridItem element to convert

      • Optionalops: GridStackOptions

        (optional) sub-grid options, else default to node, then parent settings, else defaults

      • OptionalnodeToAdd: GridStackNode

        (optional) node to add to the newly created sub grid (used when dragging over existing regular item)

      • saveContent: boolean = true

        if true (default) the html inside .grid-stack-content will be saved to child widget

      Returns GridStack

      newly created grid

    • If you add elements to your grid by hand (or have some framework creating DOM), you have to tell gridstack afterwards to make them widgets. If you want gridstack to add the elements for you, use addWidget() instead. Makes the given element a widget and returns it.

      Parameters

      • els: GridStackElement

        widget or single selector to convert.

      • Optionaloptions: GridStackWidget

        widget definition to use instead of reading attributes or using default sizing values

      Returns GridItemHTMLElement

      the converted GridItemHTMLElement

      const grid = GridStack.init();

      // Create HTML content manually, possibly looking like:
      // <div id="item-1" gs-x="0" gs-y="0" gs-w="3" gs-h="2"></div>
      grid.el.innerHTML = '<div id="item-1" gs-w="3"></div><div id="item-2"></div>';

      // Convert existing elements to widgets
      grid.makeWidget('#item-1'); // Uses gs-* attributes from DOM
      grid.makeWidget('#item-2', {w: 2, h: 1, content: 'Hello World'});

      // Or pass DOM element directly
      const element = document.getElementById('item-3');
      grid.makeWidget(element, {x: 0, y: 1, w: 4, h: 2});
    • Updates the margins which will set all 4 sides at once - see GridStackOptions.margin for format options. Supports CSS string format of 1, 2, or 4 values or a single number.

      Parameters

      • value: numberOrString

        margin value - can be:

        • Single number: 10 (applies to all sides)
        • Two values: '10px 20px' (top/bottom, left/right)
        • Four values: '10px 20px 5px 15px' (top, right, bottom, left)

      Returns GridStack

      the grid instance for chaining

      grid.margin(10);           // 10px all sides
      grid.margin('10px 20px'); // 10px top/bottom, 20px left/right
      grid.margin('5px 10px 15px 20px'); // Different for each side
    • Enables/Disables dragging by the user for specific grid elements. For all items and future items, use enableMove() instead. No-op for static grids.

      Note: If you want to prevent an item from moving due to being pushed around by another during collision, use the 'locked' property instead.

      Parameters

      • els: GridStackElement

        widget element(s) or selector to modify

      • val: boolean

        if true widget will be draggable, assuming the parent grid isn't noMove or static

      Returns GridStack

      the grid instance for chaining

      // Make specific widgets draggable
      grid.movable('.my-widget', true);

      // Disable dragging for specific widgets
      grid.movable('#fixed-widget', false);
    • unsubscribe from the 'on' event GridStackEvent

      Parameters

      • name: string

        of the event (see possible values) or list of names space separated

      Returns GridStack

    • Remove all event handlers from the grid. This is useful for cleanup when destroying a grid.

      Returns GridStack

      the grid instance for chaining

      grid.offAll(); // Remove all event listeners
      
    • Register event handler for grid events. You can call this on a single event name, or space separated list.

      Supported events:

      • added: Called when widgets are being added to a grid
      • change: Occurs when widgets change their position/size due to constraints or direct changes
      • disable: Called when grid becomes disabled
      • dragstart: Called when grid item starts being dragged
      • drag: Called while grid item is being dragged (for each new row/column value)
      • dragstop: Called after user is done moving the item, with updated DOM attributes
      • dropped: Called when an item has been dropped and accepted over a grid
      • enable: Called when grid becomes enabled
      • removed: Called when items are being removed from the grid
      • resizestart: Called before user starts resizing an item
      • resize: Called while grid item is being resized (for each new row/column value)
      • resizestop: Called after user is done resizing the item, with updated DOM attributes

      Parameters

      • name: "dropped"

        event name(s) to listen for (space separated for multiple)

      • callback: GridStackDroppedHandler

        function to call when event occurs

      Returns GridStack

      the grid instance for chaining

      // Listen to multiple events at once
      grid.on('added removed change', (event, items) => {
      items.forEach(item => console.log('Item changed:', item));
      });

      // Listen to individual events
      grid.on('added', (event, items) => {
      items.forEach(item => console.log('Added item:', item));
      });
    • Register event handler for grid events. You can call this on a single event name, or space separated list.

      Supported events:

      • added: Called when widgets are being added to a grid
      • change: Occurs when widgets change their position/size due to constraints or direct changes
      • disable: Called when grid becomes disabled
      • dragstart: Called when grid item starts being dragged
      • drag: Called while grid item is being dragged (for each new row/column value)
      • dragstop: Called after user is done moving the item, with updated DOM attributes
      • dropped: Called when an item has been dropped and accepted over a grid
      • enable: Called when grid becomes enabled
      • removed: Called when items are being removed from the grid
      • resizestart: Called before user starts resizing an item
      • resize: Called while grid item is being resized (for each new row/column value)
      • resizestop: Called after user is done resizing the item, with updated DOM attributes

      Parameters

      • name: "enable" | "disable"

        event name(s) to listen for (space separated for multiple)

      • callback: GridStackEventHandler

        function to call when event occurs

      Returns GridStack

      the grid instance for chaining

      // Listen to multiple events at once
      grid.on('added removed change', (event, items) => {
      items.forEach(item => console.log('Item changed:', item));
      });

      // Listen to individual events
      grid.on('added', (event, items) => {
      items.forEach(item => console.log('Added item:', item));
      });
    • Register event handler for grid events. You can call this on a single event name, or space separated list.

      Supported events:

      • added: Called when widgets are being added to a grid
      • change: Occurs when widgets change their position/size due to constraints or direct changes
      • disable: Called when grid becomes disabled
      • dragstart: Called when grid item starts being dragged
      • drag: Called while grid item is being dragged (for each new row/column value)
      • dragstop: Called after user is done moving the item, with updated DOM attributes
      • dropped: Called when an item has been dropped and accepted over a grid
      • enable: Called when grid becomes enabled
      • removed: Called when items are being removed from the grid
      • resizestart: Called before user starts resizing an item
      • resize: Called while grid item is being resized (for each new row/column value)
      • resizestop: Called after user is done resizing the item, with updated DOM attributes

      Parameters

      • name: "change" | "added" | "removed" | "resizecontent"

        event name(s) to listen for (space separated for multiple)

      • callback: GridStackNodesHandler

        function to call when event occurs

      Returns GridStack

      the grid instance for chaining

      // Listen to multiple events at once
      grid.on('added removed change', (event, items) => {
      items.forEach(item => console.log('Item changed:', item));
      });

      // Listen to individual events
      grid.on('added', (event, items) => {
      items.forEach(item => console.log('Added item:', item));
      });
    • Register event handler for grid events. You can call this on a single event name, or space separated list.

      Supported events:

      • added: Called when widgets are being added to a grid
      • change: Occurs when widgets change their position/size due to constraints or direct changes
      • disable: Called when grid becomes disabled
      • dragstart: Called when grid item starts being dragged
      • drag: Called while grid item is being dragged (for each new row/column value)
      • dragstop: Called after user is done moving the item, with updated DOM attributes
      • dropped: Called when an item has been dropped and accepted over a grid
      • enable: Called when grid becomes enabled
      • removed: Called when items are being removed from the grid
      • resizestart: Called before user starts resizing an item
      • resize: Called while grid item is being resized (for each new row/column value)
      • resizestop: Called after user is done resizing the item, with updated DOM attributes

      Parameters

      • name: "drag" | "dragstart" | "resize" | "resizestart" | "resizestop" | "dragstop"

        event name(s) to listen for (space separated for multiple)

      • callback: GridStackElementHandler

        function to call when event occurs

      Returns GridStack

      the grid instance for chaining

      // Listen to multiple events at once
      grid.on('added removed change', (event, items) => {
      items.forEach(item => console.log('Item changed:', item));
      });

      // Listen to individual events
      grid.on('added', (event, items) => {
      items.forEach(item => console.log('Added item:', item));
      });
    • Register event handler for grid events. You can call this on a single event name, or space separated list.

      Supported events:

      • added: Called when widgets are being added to a grid
      • change: Occurs when widgets change their position/size due to constraints or direct changes
      • disable: Called when grid becomes disabled
      • dragstart: Called when grid item starts being dragged
      • drag: Called while grid item is being dragged (for each new row/column value)
      • dragstop: Called after user is done moving the item, with updated DOM attributes
      • dropped: Called when an item has been dropped and accepted over a grid
      • enable: Called when grid becomes enabled
      • removed: Called when items are being removed from the grid
      • resizestart: Called before user starts resizing an item
      • resize: Called while grid item is being resized (for each new row/column value)
      • resizestop: Called after user is done resizing the item, with updated DOM attributes

      Parameters

      • name: string

        event name(s) to listen for (space separated for multiple)

      • callback: GridStackEventHandlerCallback

        function to call when event occurs

      Returns GridStack

      the grid instance for chaining

      // Listen to multiple events at once
      grid.on('added removed change', (event, items) => {
      items.forEach(item => console.log('Item changed:', item));
      });

      // Listen to individual events
      grid.on('added', (event, items) => {
      items.forEach(item => console.log('Added item:', item));
      });
    • called when we are being resized - check if the one Column Mode needs to be turned on/off and remember the prev columns we used, or get our count from parent, as well as check for cellHeight==='auto' (square) or sizeToContent gridItem options.

      Parameters

      • clientWidth: number = ...

      Returns GridStack

    • call this method to register your engine instead of the default one. See instead GridStackOptions.engineClass if you only need to replace just one instance.

      Parameters

      Returns void

    • Removes all widgets from the grid.

      Parameters

      • removeDOM: boolean = true

        if false DOM elements won't be removed from the tree (Default? true).

      • triggerEvent: boolean = true

        if false (quiet mode) element will not be added to removed list and no 'removed' callbacks will be called (Default? true).

      Returns GridStack

    • called when an item was converted into a nested grid to accommodate a dragged over item, but then item leaves - return back to the original grid-item. Also called to remove empty sub-grids when last item is dragged out (since re-creating is simple)

      Parameters

      Returns void

    • Removes widget from the grid.

      Parameters

      • els: GridStackElement
      • removeDOM: boolean = true

        if false DOM element won't be removed from the tree (Default? true).

      • triggerEvent: boolean = true

        if false (quiet mode) element will not be added to removed list and no 'removed' callbacks will be called (Default? true).

      Returns GridStack

    • Enables/Disables user resizing for specific grid elements. For all items and future items, use enableResize() instead. No-op for static grids.

      Parameters

      • els: GridStackElement

        widget element(s) or selector to modify

      • val: boolean

        if true widget will be resizable, assuming the parent grid isn't noResize or static

      Returns GridStack

      the grid instance for chaining

      // Make specific widgets resizable
      grid.resizable('.my-widget', true);

      // Disable resizing for specific widgets
      grid.resizable('#fixed-size-widget', false);
    • Updates widget height to match the content height to avoid vertical scrollbars or dead space. This automatically adjusts the widget height based on its content size.

      Note: This assumes only 1 child under resizeToContentParent='.grid-stack-item-content' (sized to gridItem minus padding) that represents the entire content size.

      Parameters

      Returns void

      // Resize a widget to fit its content
      const widget = document.querySelector('.grid-stack-item');
      grid.resizeToContent(widget);

      // This is commonly used with dynamic content:
      widget.querySelector('.content').innerHTML = 'New longer content...';
      grid.resizeToContent(widget);
    • Rotate widgets by swapping their width and height. This is typically called when the user presses 'r' during dragging. The rotation swaps the w/h dimensions and adjusts min/max constraints accordingly.

      Parameters

      • els: GridStackElement

        widget element(s) or selector to rotate

      • Optionalrelative: Position

        optional pixel coordinate relative to upper/left corner to rotate around (keeps that cell under cursor)

      Returns GridStack

      the grid instance for chaining

      // Rotate a specific widget
      grid.rotate('.my-widget');

      // Rotate with relative positioning during drag
      grid.rotate(widget, { left: 50, top: 30 });
    • saves the current layout returning a list of widgets for serialization which might include any nested grids.

      Parameters

      • saveContent: boolean = true

        if true (default) the latest html inside .grid-stack-content will be saved to GridStackWidget.content field, else it will be removed.

      • saveGridOpt: boolean = false

        if true (default false), save the grid options itself, so you can call the new GridStack.addGrid() to recreate everything from scratch. GridStackOptions.children would then contain the widget list instead.

      • saveCB: SaveFcn = GridStack.saveCB

        callback for each node -> widget, so application can insert additional data to be saved into the widget data structure.

      • Optionalcolumn: number

        if provided, the grid will be saved for the given column size (IFF we have matching internal saved layout, or current layout). Otherwise it will use the largest possible layout (say 12 even if rendering at 1 column) so we can restore to all layouts. NOTE: if you want to save to currently display layout, pass this.getColumn() as column. NOTE2: nested grids will ALWAYS save to the container size to be in sync with parent.

      Returns GridStackOptions | GridStackWidget[]

      list of widgets or full grid option, including .children list of widgets

    • Toggle the grid animation state. Toggles the grid-stack-animate class.

      Parameters

      • doAnimate: boolean = ...

        if true the grid will animate.

      • Optionaldelay: boolean

        if true setting will be set on next event loop.

      Returns GridStack

    • Toggle the grid static state, which permanently removes/add Drag&Drop support, unlike disable()/enable() that just turns it off/on. Also toggle the grid-stack-static class.

      Parameters

      • val: boolean

        if true the grid become static.

      • updateClass: boolean = true

        true (default) if css class gets updated

      • recurse: boolean = true

        true (default) if sub-grids also get updated

      Returns GridStack

    • call to setup dragging in from the outside (say toolbar), by specifying the class selection and options. Called during GridStack.init() as options, but can also be called directly (last param are used) in case the toolbar is dynamically create and needs to be set later.

      Parameters

      • OptionaldragIn: string | HTMLElement[]

        string selector (ex: '.sidebar-item') or list of dom elements

      • OptionaldragInOptions: DDDragOpt

        options - see DDDragOpt. (default: {handle: '.grid-stack-item-content', appendTo: 'body'}

      • Optionalwidgets: GridStackWidget[]

        GridStackWidget def to assign to each element which defines what to create on drop

      • root: HTMLElement | Document = document

        optional root which defaults to document (for shadow dom pass the parent HTMLDocument)

      Returns void

    • Updates widget position/size and other info. This is used to change widget properties after creation. Can update position, size, content, and other widget properties.

      Note: If you need to call this on all nodes, use load() instead which will update what changed. Setting the same x,y for multiple items will be indeterministic and likely unwanted.

      Parameters

      Returns GridStack

      the grid instance for chaining

      // Update widget size and position
      grid.update('.my-widget', { x: 2, y: 1, w: 3, h: 2 });

      // Update widget content
      grid.update(widget, { content: '<p>New content</p>' });

      // Update multiple properties
      grid.update('#my-widget', {
      w: 4,
      h: 3,
      noResize: true,
      locked: true
      });
    • Returns true if the height of the grid will be less than the vertical constraint. Always returns true if grid doesn't have height constraint.

      Parameters

      Returns boolean

      if (grid.willItFit(newWidget)) {
      grid.addWidget(newWidget);
      } else {
      alert('Not enough free space to place the widget');
      }

    Properties

    addRemoveCB?: AddRemoveFcn

    callback method use when new items|grids needs to be created or deleted, instead of the default item:

    w.content
    grid:
    grid content...
    add = true: the returned DOM element will then be converted to a GridItemHTMLElement using makeWidget()|GridStack:init(). add = false: the item will be removed from DOM (if not already done) grid = true|false for grid vs grid-items

    animationDelay: number = ...

    time to wait for animation (if enabled) to be done so content sizing can happen

    the HTML element tied to this grid after it's been initialized

    engine used to implement non DOM grid functionality

    Engine: typeof GridStackEngine = GridStackEngine

    scoping so users can call new GridStack.Engine(12) for example

    engineClass: typeof GridStackEngine
    opts: GridStackOptions = {}

    grid options - public for classes to access, but use methods to modify!

    parentGridNode?: GridStackNode

    point to a parent grid item if we're nested (inside a grid-item in between 2 Grids)

    renderCB?: RenderFcn = ...

    callback to create the content of widgets so the app can control how to store and restore it By default this lib will do 'el.textContent = w.content' forcing text only support for avoiding potential XSS issues.

    resizeObserver: ResizeObserver
    resizeToContentCB?: ResizeToContentFcn

    callback to use for resizeToContent instead of the built in one

    resizeToContentParent: string = '.grid-stack-item-content'

    parent class for sizing content. defaults to '.grid-stack-item-content'

    responseLayout: ColumnOptions
    saveCB?: SaveFcn

    callback during saving to application can inject extra data for each widget, on top of the grid layout properties

    updateCB?: (w: GridStackNode) => void

    called after a widget has been updated (eg: load() into an existing list of children) so application can do extra work

    Utils: typeof Utils = Utils

    scoping so users can call GridStack.Utils.sort() for example