Gridster.js – saving the state and dynamic loading of the elements
This is it, the mythical drag-and-drop multi-column grid has arrived. Gridster is a jQuery plugin that allows building intuitive draggable layouts from elements spanning multiple columns. You can even dynamically add and remove elements from the grid. It is on par with sliced bread, or possibly better. MIT licensed. Suitable for children of all ages. Made by Ducksboard. It’s so sweet we like to call it drag-and-drool.
Demos
- Adding widgets dynamically
- Custom drag handle
- Expandable widgets
- Build grid from serialize
- Multiple gridster instances on the same page
- Resizable widgets
- Resizable widgets with constraints
- Serialize widgets positions
- Using drag callbacks
- Using resize callbacks
- Dynamic grid width
Usage
Setup
Include dependencies
Gridster is currently written as a jQuery plugin, so you need to include it in the head of the document. Download the latest release at jQuery.
HTML Structure
Class names and tags are customizable, gridster only cares about data attributes. Use a structure like this:
<div class="gridster"> <ul> <li data-row="1" data-col="1" data-sizex="1" data-sizey="1"></li> <li data-row="2" data-col="1" data-sizex="1" data-sizey="1"></li> <li data-row="3" data-col="1" data-sizex="1" data-sizey="1"></li> <li data-row="1" data-col="2" data-sizex="2" data-sizey="1"></li> <li data-row="2" data-col="2" data-sizex="2" data-sizey="2"></li> <li data-row="1" data-col="4" data-sizex="1" data-sizey="1"></li> <li data-row="2" data-col="4" data-sizex="2" data-sizey="1"></li> <li data-row="3" data-col="4" data-sizex="1" data-sizey="1"></li> <li data-row="1" data-col="5" data-sizex="1" data-sizey="1"></li> <li data-row="3" data-col="5" data-sizex="1" data-sizey="1"></li> <li data-row="1" data-col="6" data-sizex="1" data-sizey="1"></li> <li data-row="2" data-col="6" data-sizex="1" data-sizey="2"></li> </ul> </div>
Grid it up!
Gridster accepts one argument, a hash of with configuration options. See the documentation for details.
$(function(){ //DOM Ready $(".gridster ul").gridster({ widget_margins: [10, 10], widget_base_dimensions: [140, 140] }); });
Source : gridster