Gridster.js Manual
User Manual:
Open the PDF directly: View PDF
.
Page Count: 7

PlugintothegridPlugintothegrid
Thisisit,themythicaldraganddropmulticolumngridhasarrived.GridsterisaThisisit,themythicaldraganddropmulticolumngridhasarrived.Gridsterisa
jQuerypluginthatallowsbuildingintuitivedraggablelayoutsfromelementsjQuerypluginthatallowsbuildingintuitivedraggablelayoutsfromelements
spanningmultiplecolumns.Youcanevendynamicallyaddandremoveelementsspanningmultiplecolumns.Youcanevendynamicallyaddandremoveelements
fromthegrid.Itisonparwithslicedbread,orpossiblybetter.MITlicensed.fromthegrid.Itisonparwithslicedbread,orpossiblybetter.MITlicensed.
Suitableforchildrenofallages.MadebySuitableforchildrenofallages.MadebyDucksboardDucksboard..
It'ssosweetweliketocallitdraganddrool.It'ssosweetweliketocallitdraganddrool.
Downloadnow
put a grid in your life
What? Usage Documentation Download Issues
UsageUsage
SetupSetup
IncludedependenciesIncludedependencies
GridsteriscurrentlywrittenasajQueryplugin,soyouneedtoincludeitintheheadofthedocument.DownloadthelatestGridsteriscurrentlywrittenasajQueryplugin,soyouneedtoincludeitintheheadofthedocument.Downloadthelatest
releaseatreleaseatjQueryjQuery..
HTMLStructureHTMLStructure
Classnamesandtagsarecustomizable,gridsteronlycaresaboutdataattributes.Useastructurelikethis:Classnamesandtagsarecustomizable,gridsteronlycaresaboutdataattributes.Useastructurelikethis:
HiQPdfEvaluation03/30/2013

viewrawgridster.html
viewrawgridder.js
viewrawgridster.js
viewrawgridster.js
viewrawgridster.js
viewrawgridster.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<divclass="gridster">
<ul>
<lidata‐row="1"data‐col="1"data‐sizex="1"data‐sizey="1"></li>
<lidata‐row="2"data‐col="1"data‐sizex="1"data‐sizey="1"></li>
<lidata‐row="3"data‐col="1"data‐sizex="1"data‐sizey="1"></li>
<lidata‐row="1"data‐col="2"data‐sizex="2"data‐sizey="1"></li>
<lidata‐row="2"data‐col="2"data‐sizex="2"data‐sizey="2"></li>
<lidata‐row="1"data‐col="4"data‐sizex="1"data‐sizey="1"></li>
<lidata‐row="2"data‐col="4"data‐sizex="2"data‐sizey="1"></li>
<lidata‐row="3"data‐col="4"data‐sizex="1"data‐sizey="1"></li>
<lidata‐row="1"data‐col="5"data‐sizex="1"data‐sizey="1"></li>
<lidata‐row="3"data‐col="5"data‐sizex="1"data‐sizey="1"></li>
<lidata‐row="1"data‐col="6"data‐sizex="1"data‐sizey="1"></li>
<lidata‐row="2"data‐col="6"data‐sizex="1"data‐sizey="2"></li>
</ul>
</div>
ThisGistbroughttoyoubyGitHub.
Griditup!Griditup!
Gridsteracceptsoneargument,ahashofwithconfigurationoptions.SeetheGridsteracceptsoneargument,ahashofwithconfigurationoptions.Seethedocumentationdocumentationfordetails.fordetails.
1
2
3
4
5
6
7
8
$(function(){//DOMReady
$(".gridsterul").gridster({
widget_margins:[10,10],
widget_base_dimensions:[140,140]
});
});
ThisGistbroughttoyoubyGitHub.
UsingtheAPIUsingtheAPI
TogetholdoftheAPIobject,usethejQuerydatamethodlikeso:TogetholdoftheAPIobject,usethejQuerydatamethodlikeso:
1
2
3
4
5
$(function(){//DOMReady
vargridster=$(".gridsterul").gridster().data('gridster');
});
ThisGistbroughttoyoubyGitHub.
AddanewwidgettothegridAddanewwidgettothegrid
1gridster.add_widget('<liclass="new">TheHTMLofthewidget...</li>',2,1);
ThisGistbroughttoyoubyGitHub.
RemoveawidgetfromthegridRemoveawidgetfromthegrid
1gridster.remove_widget($('.gridsterli').eq(3));
ThisGistbroughttoyoubyGitHub.
GetaserializedarraywiththeelementspositionsGetaserializedarraywiththeelementspositions
CreatesaJavaScriptarrayofobjectswithpositionsofallwidgets,readytobeencodedasaJSONstring.CreatesaJavaScriptarrayofobjectswithpositionsofallwidgets,readytobeencodedasaJSONstring.
1gridster.serialize();
ThisGistbroughttoyoubyGitHub.
HiQPdfEvaluation03/30/2013

DocumentationDocumentation
OptionsOptions
widget_class widget_margins widget_base_dimensions min_cols min_rows max_size_x
max_size_y extra_cols extra_rows autogenerate_stylesheet avoid_overlapped_widgets
draggable.start draggable.drag draggable.stop collision.on_overlap_start collision.on_overlap
collision.on_overlap_stop
MethodsMethods
Thesearethemostcommonlyusedmethods.Ifyouwantmoredetails,checkouttheThesearethemostcommonlyusedmethods.Ifyouwantmoredetails,checkoutthedocumentationgeneratedfromdocumentationgeneratedfrom
sourcesource..
add_widget resize_widget remove_widget serialize serialize_changed enable disable
OptionsOptions
Agridsterconfigurationobject.Agridsterconfigurationobject.
widget_selector:widget_selector:
">li"">li"
Definewhichelementsarethewidgets.CanbeaCSSSelectorstringorajQuerycollectionofHTMLElements.Definewhichelementsarethewidgets.CanbeaCSSSelectorstringorajQuerycollectionofHTMLElements.
widget_margins:widget_margins:
[10,10][10,10]
Horizontalandverticalmarginsrespectivelyforwidgets.Horizontalandverticalmarginsrespectivelyforwidgets.
widget_base_dimensions:widget_base_dimensions:
[140,140][140,140]
Basewidgetdimensionsinpixels.Thefirstindexisthewidth,thesecondistheheight.Basewidgetdimensionsinpixels.Thefirstindexisthewidth,thesecondistheheight.
extra_rows:extra_rows:
00
Addmorerowstothegridinadditiontothosethathavebeencalculated.Addmorerowstothegridinadditiontothosethathavebeencalculated.
extra_cols:extra_cols:
00
Addmorerowstothegridinadditiontothosethathavebeencalculated.Addmorerowstothegridinadditiontothosethathavebeencalculated.
min_cols:min_cols:
11
Theminimumnumbercolumnstocreate.Theminimumnumbercolumnstocreate.
min_rows:min_rows:
1515
Theminimumnumberofrowstocreate.Theminimumnumberofrowstocreate.
max_size_x:max_size_x:
66
Themaximumnumberofcolumnsthatawidgetcanspan.Themaximumnumberofcolumnsthatawidgetcanspan.
max_size_y:max_size_y:
66
Themaximumnumberofrowsthatawidgetcanspan.Themaximumnumberofrowsthatawidgetcanspan.
autogenerate_stylesheet:autogenerate_stylesheet:
truetrue
Iftrue,alltheCSSrequiredtopositionallwidgetsintheirrespectivecolumnsandrowswillbegeneratedautomaticallyandIftrue,alltheCSSrequiredtopositionallwidgetsintheirrespectivecolumnsandrowswillbegeneratedautomaticallyand
injectedtotheinjectedtothe<head><head>ofthedocument.YoucansetthistofalseandwriteyourownCSStargetingrowsandcolsviadataofthedocument.YoucansetthistofalseandwriteyourownCSStargetingrowsandcolsviadata
attributeslikeso:attributeslikeso:[datacol="1"]{left:10px;}[datacol="1"]{left:10px;}..
avoid_overlapped_widgets:avoid_overlapped_widgets:
truetrue
Don'tallowwidgetsloadedfromtheDOMtooverlap.Thisishelpfulifyou'reloadingwidgetpositionsformthedatabaseandDon'tallowwidgetsloadedfromtheDOMtooverlap.Thisishelpfulifyou'reloadingwidgetpositionsformthedatabaseand
theymightbeinconsistent.theymightbeinconsistent.
serialize_params:serialize_params:
function($w,wgd){return{col:wgd.col,row:wgd.row}}function($w,wgd){return{col:wgd.col,row:wgd.row}}
Afunctiontoreturnserializeddataforeacheachwidget,usedwhencallingtheAfunctiontoreturnserializeddataforeacheachwidget,usedwhencallingtheserializemethodserializemethod.Twoargumentsare.Twoargumentsare
HiQPdfEvaluation03/30/2013

passed:passed:$w$w:thejQuerywrappedHTMLElement,and:thejQuerywrappedHTMLElement,andwgdwgd:thegridcoordsobjectwithkeys:thegridcoordsobjectwithkeyscolcol,,rowrow,,size_xsize_xandandsize_ysize_y..
draggable.start:draggable.start:
function(event,ui){}function(event,ui){}
Acallbackforwhendraggingstarts.Acallbackforwhendraggingstarts.
draggable.drag:draggable.drag:
function(event,ui){}function(event,ui){}
Acallbackforwhenthemouseismovedduringthedragging.Acallbackforwhenthemouseismovedduringthedragging.
draggable.stop:draggable.stop:
function(event,ui){}function(event,ui){}
Acallbackforwhendraggingstops.Acallbackforwhendraggingstops.
collision.on_overlap_start:collision.on_overlap_start:
function(collider_data){}function(collider_data){}
Acallbackforthefirsttimewhenawidgetentersanewgridcell.Acallbackforthefirsttimewhenawidgetentersanewgridcell.
collision.on_overlap:collision.on_overlap:
function(collider_data){}function(collider_data){}
Acallbackforeachtimeawidgetmovesinsideagridcell.Acallbackforeachtimeawidgetmovesinsideagridcell.
collision.on_overlap_stop:collision.on_overlap_stop:
function(collider_data){}function(collider_data){}
Acallbackforthefirsttimewhenawidgetleavesitsoldgridcell.Acallbackforthefirsttimewhenawidgetleavesitsoldgridcell.
.add_widget(html,[size_x],[size_y],[col],[row])
Createanewwidgetwiththegivenhtmlandaddittothegrid.Createanewwidgetwiththegivenhtmlandaddittothegrid.
ParametersParameters
htmlhtml
String|HTMLElementString|HTMLElement
ThestringofHTMLElementthatrepresentsthewidgetisgoingtobeadded.ThestringofHTMLElementthatrepresentsthewidgetisgoingtobeadded.
size_xsize_x
NumberNumber
Thenumberofrowsthatthewidgetoccupies.DefaultstoThenumberofrowsthatthewidgetoccupies.Defaultsto
11
..
size_ysize_y
NumberNumber
Thenumberofcolumnsthatthewidgetoccupies.DefaultstoThenumberofcolumnsthatthewidgetoccupies.Defaultsto
11
..
colcol
NumberNumber
Thecolumnthewidgetshouldstartin.Thecolumnthewidgetshouldstartin.
rowrow
NumberNumber
Therowthewidgetshouldstartin.Therowthewidgetshouldstartin.
ReturnsReturns
ReturnsthejQuerywrappedHTMLElementrepresentingthewidgetthat'sbeencreated.ReturnsthejQuerywrappedHTMLElementrepresentingthewidgetthat'sbeencreated.
.resize_widget($widget,[size_x],[size_y])
Changethesizeofawidget.Changethesizeofawidget.
ParametersParameters
$widget$widget
HTMLElementHTMLElement
ThejQuerywrappedHTMLElementthatrepresentsthewidgetisgoingtoberesized.ThejQuerywrappedHTMLElementthatrepresentsthewidgetisgoingtoberesized.
size_xsize_x
NumberNumber
Thenumberofrowsthatthewidgetisgoingtospan.Defaultstocurrentsize_x.Thenumberofrowsthatthewidgetisgoingtospan.Defaultstocurrentsize_x.
HiQPdfEvaluation03/30/2013

size_ysize_y
NumberNumber
Thenumberofcolumnsthatthewidgetisgoingtospan.Defaultstocurrentsize_y.Thenumberofcolumnsthatthewidgetisgoingtospan.Defaultstocurrentsize_y.
ReturnsReturns
ReturnsthejQuerywrappedHTMLElementrepresentingthewidgetthat'sbeenresized.ReturnsthejQuerywrappedHTMLElementrepresentingthewidgetthat'sbeenresized.
.remove_widget(el,[callback])
Removeawidgetfromthegrid.Removeawidgetfromthegrid.
ParametersParameters
elel
HTMLElementHTMLElement
ThejQuerywrappedHTMLElementrepresentingthewidgetthatyouwanttoremove.ThejQuerywrappedHTMLElementrepresentingthewidgetthatyouwanttoremove.
callbackcallback
FunctionFunction
Acallbackforwhenthewidgetisremoved.Acallbackforwhenthewidgetisremoved.
ReturnsReturns
ReturnstheinstanceoftheGridsterclass.ReturnstheinstanceoftheGridsterclass.
.serialize([$widgets])
Createsanarrayofobjectsrepresentingthecurrentpositionofallwidgetsinthegrid.Createsanarrayofobjectsrepresentingthecurrentpositionofallwidgetsinthegrid.
ParametersParameters
$widgets$widgets
HTMLElementHTMLElement
ThecollectionofjQuerywrappedHTMLElementsyouwanttoserialize.IfnoargumentispassedallwidgetswillbeThecollectionofjQuerywrappedHTMLElementsyouwanttoserialize.Ifnoargumentispassedallwidgetswillbe
serialized.serialized.
ReturnsReturns
ReturnsanArrayofObjects(readytobeencodedasaJSONstring)withthedataspecifiedbytheReturnsanArrayofObjects(readytobeencodedasaJSONstring)withthedataspecifiedbytheserialize_paramsserialize_params
option.option.
.serialize_changed()
Createsanarrayofobjectsrepresentingthecurrentpositionofthewidgetswhohavechangedposition.Createsanarrayofobjectsrepresentingthecurrentpositionofthewidgetswhohavechangedposition.
ReturnsReturns
ReturnsanArrayofObjects(readytobeencodedasaJSONstring)withthedataspecifiedintheReturnsanArrayofObjects(readytobeencodedasaJSONstring)withthedataspecifiedintheserialize_paramsserialize_params
option.option.
.enable()
Enablesdragging.Enablesdragging.
HiQPdfEvaluation03/30/2013

ReturnsReturns
ReturnstheinstanceoftheGridsterclass.ReturnstheinstanceoftheGridsterclass.
.disable()
Disablesdragging.Disablesdragging.
ReturnsReturns
ReturnstheinstanceoftheGridsterclass.ReturnstheinstanceoftheGridsterclass.
DownloadDownload
RememberthatgridsterdependsonjQuery.DownloadthelatestreleaseatRememberthatgridsterdependsonjQuery.DownloadthelatestreleaseatjQueryjQuery..
gridster.gridster.jsjs
DevelopmentversionDevelopmentversion
jquery.gridster.jsjquery.gridster.js
Productionversion(minified)Productionversion(minified)
jquery.gridster.min.jsjquery.gridster.min.js
gridster.gridster.csscss
DevelopmentversionDevelopmentversion
jquery.gridster.cssjquery.gridster.css
Productionversion(minified)Productionversion(minified)
jquery.gridster.min.cssjquery.gridster.min.css
orclonetherepofromgithuborclonetherepofromgithub
GithubprojectGithubproject
gridster.jsgridster.js
Download.zipDownload.zip
gridster.js.zipgridster.js.zip
BrowsersupportBrowsersupport
GridstersupportsInternetExplorer9+,Firefox,Chrome,SafariandOpera.GridstersupportsInternetExplorer9+,Firefox,Chrome,SafariandOpera.
put a grid in your life
HiQPdfEvaluation03/30/2013
