Manual Treeview
User Manual:
Open the PDF directly: View PDF
.
Page Count: 13

TreeViewforTwitterBootstraphttp://jonmiles.github.io/bootstraptreeview
dist RemovednodeIconbydefault#3 ayearago
public Versionupdatedtov1.2.0 ayearago
screenshot Initialcommit 3yearsago
src Versionupdatedtov1.2.0 ayearago
tests Versionupdatedtov1.2.0 ayearago
.bowerrc Initialcommit 3yearsago
.gitattributes Initialcommit 3yearsago
.gitignore Initialcommit 3yearsago
.jshintrc Initialcommit 3yearsago
.travis.yml Travissetup ayearago
CHANGELOG.md Releasenotesupdated ayearago
Gruntfile.js Travissetup ayearago
LICENSE Initialcommit 3yearsago
README.md Versionupdatedtov1.2.0 ayearago
app.js Initialcommit 3yearsago
bower.json Versionupdatedtov1.2.0 ayearago
package.json Versionupdatedtov1.2.0 ayearago
142 1,234 474Watch Star Fork
jonmiles /bootstraptreeview
Code Issues 38 Pullrequests 27 Pulse Graphs
137commits 4branches 5releases 4contributors
CloneordownloadFindfilemasterBranch: Newpullrequest
Latestcommit542f57eon9May2015jonmilesMergebranch'release/1.2.0' …
README.md
BootstrapTreeView
bower
bower v1.2.0
v1.2.0
npm
npm v1.2.0
v1.2.0
build
build passing
passing
Asimpleandelegantsolutiontodisplayinghierarchicaltreestructures(i.e.aTreeView)whileleveragingthebestthatTwitter
Bootstraphastooffer.
Personal Open source Business Explore Pricing Blog Support This repository
Search
Sign upSign in

Dependencies
Whereprovidedthesearetheactualversionsbootstraptreeviewhasbeentestedagainst.
Bootstrapv3.3.4(>=3.0.0)
jQueryv2.1.3(>=1.9.0)
GettingStarted
Install
Youcaninstallusingbower(recommended):
$bowerinstallbootstrap‐treeview
orusingnpm:
$npminstallbootstrap‐treeview
ordownloadmanually.
Usage
Addthefollowingresourcesforthebootstraptreeviewtofunctioncorrectly.
<!‐‐RequiredStylesheets‐‐>
<linkhref="bootstrap.css"rel="stylesheet">
<!‐‐RequiredJavascript‐‐>
<scriptsrc="jquery.js"></script>
<scriptsrc="bootstrap‐treeview.js"></script>
ThecomponentwillbindtoanyexistingDOMelement.
<divid="tree"></div>
Basicusagemaylooksomethinglikethis.
functiongetTree(){
//Somelogictoretrieve,orgeneratetreestructure
returndata;
}
$('#tree').treeview({data:getTree()});

DataStructure
Inordertodefinethehierarchicalstructureneededforthetreeit'snecessarytoprovideanestedarrayofJavaScriptobjects.
Example
vartree=[
{
text:"Parent1",
nodes:[
{
text:"Child1",
nodes:[
{
text:"Grandchild1"
},
{
text:"Grandchild2"
}
]
},
{
text:"Child2"
}
]
},
{
text:"Parent2"
},
{
text:"Parent3"
},
{
text:"Parent4"
},
{
text:"Parent5"
}
];
AtthelowestlevelatreenodeisarepresentedasasimpleJavaScriptobject.Thisonerequiredpropertytextwillbuildyou
atree.
{
text:"Node1"
}
Ifyouwanttodomore,here'sthefullnodespecification
{
text:"Node1",
icon:"glyphiconglyphicon‐stop",
selectedIcon:"glyphiconglyphicon‐stop",
color:"#000000",
backColor:"#FFFFFF",
href:"#node‐1",
selectable:true,
state:{
checked:true,
disabled:true,
expanded:true,
selected:true
},
tags:['available'],
nodes:[
{},
...
]
}

NodeProperties
Thefollowingpropertiesaredefinedtoallownodeleveloverrides,suchasnodespecificicons,coloursandtags.
text
StringMandatory
Thetextvaluedisplayedforagiventreenode,typicallytotherightofthenodesicon.
icon
StringOptional
Theicondisplayedonagivennode,typicallytotheleftofthetext.
ForsimplicitywedirectlyleverageBootstrapsGlyphiconssupportandassuchyoushouldprovideboththebaseclassand
individualiconclassseparatedbyaspace.
Byprovidingthebaseclassyouretainfullcontrolovertheiconsused.Ifyouwanttouseyourownthenjustaddyourclassto
thisiconfield.
selectedIcon
StringOptional
Theicondisplayedonagivennodewhenselected,typicallytotheleftofthetext.
color
StringOptional
Theforegroundcolorusedonagivennode,overridesglobalcoloroption.
backColor
StringOptional
Thebackgroundcolorusedonagivennode,overridesglobalcoloroption.
href
StringOptional
UsedinconjunctionwithglobalenableLinksoptiontospecifyanchortagURLonagivennode.
selectable
BooleanDefault:true
Whetherornotanodeisselectableinthetree.Falseindicatesthenodeshouldactasanexpansionheadingandwillnotfire
selectionevents.
state
ObjectOptionalDescribesanode'sinitialstate.
state.checked
BooleanDefault:false
Whetherornotanodeischecked,representedbyacheckboxstyleglyphicon.
state.disabled
BooleanDefault:false

Whetherornotanodeisdisabled(notselectable,expandableorcheckable).
state.expanded
BooleanDefault:false
Whetherornotanodeisexpandedi.e.open.Takesprecedenceoverglobaloptionlevels.
state.selected
BooleanDefault:false
Whetherornotanodeisselected.
tags
ArrayofStringsOptional
UsedinconjunctionwithglobalshowTagsoptiontoaddadditionalinformationtotherightofeachnode;usingBootstrap
Badges
Extendible
Youcanextendthenodeobjectbyaddinganynumberofadditionalkeyvaluepairsthatyourequireforyourapplication.
Rememberthisistheobjectwhichwillbepassedaroundduringselectionevents.
Options
Optionsallowyoutocustomisethetreeview'sdefaultappearanceandbehaviour.Theyarepassedtothepluginon
initialization,asanobject.
//Example:initializingthetreeview
//expandedto5levels
//withabackgroundcolorofgreen
$('#tree').treeview({
data:data,//dataisnotoptional
levels:5,
backColor:'green'
});
Youcanpassanewoptionsobjecttothetreeviewatanytimebutthiswillhavetheeffectofreinitializingthetreeview.
ListofOptions
Thefollowingisalistofallavailableoptions.
data
ArrayofObjects.Nodefault,expectsdata
Thisisthecoredatatobedisplayedbythetreeview.
backColor
String,anylegalcolorvalue.Default:inheritsfromBootstrap.css.
Setsthedefaultbackgroundcolorusedbyallnodes,exceptwhenoverriddenonapernodebasisindata.
borderColor
String,anylegalcolorvalue.Default:inheritsfromBootstrap.css.
Setsthebordercolorforthecomponent;setshowBordertofalseifyoudon'twantavisibleborder.
checkedIcon

String,classnames(s).Default:"glyphiconglyphiconcheck"asdefinedbyBootstrapGlyphicons
Setstheicontobeasacheckedcheckbox,usedinconjunctionwithshowCheckbox.
collapseIcon
String,classname(s).Default:"glyphiconglyphiconminus"asdefinedbyBootstrapGlyphicons
Setstheicontobeusedonacollapsibletreenode.
color
String,anylegalcolorvalue.Default:inheritsfromBootstrap.css.
Setsthedefaultforegroundcolorusedbyallnodes,exceptwhenoverriddenonapernodebasisindata.
emptyIcon
String,classname(s).Default:"glyphicon"asdefinedbyBootstrapGlyphicons
Setstheicontobeusedonatreenodewithnochildnodes.
enableLinks
Boolean.Default:false
Whetherornottopresentnodetextasahyperlink.Thehrefvalueofwhichmustbeprovidedinthedatastructureonaper
nodebasis.
expandIcon
String,classname(s).Default:"glyphiconglyphiconplus"asdefinedbyBootstrapGlyphicons
Setstheicontobeusedonanexpandabletreenode.
highlightSearchResults
Boolean.Default:true
Whetherornottohighlightsearchresults.
highlightSelected
Boolean.Default:true
Whetherornottohighlighttheselectednode.
levels
Integer.Default:2
Setsthenumberofhierarchicallevelsdeepthetreewillbeexpandedtobydefault.
multiSelect
Boolean.Default:false
Whetherornotmultiplenodescanbeselectedatthesametime.
nodeIcon
String,classname(s).Default:"glyphiconglyphiconstop"asdefinedbyBootstrapGlyphicons
Setsthedefaulticontobeusedonallnodes,exceptwhenoverriddenonapernodebasisindata.
onhoverColor
String,anylegalcolorvalue.Default:'#F5F5F5'.

Setsthedefaultbackgroundcoloractivatedwhentheuserscursorhoversoveranode.
selectedIcon
String,classname(s).Default:"glyphiconglyphiconstop"asdefinedbyBootstrapGlyphicons
Setsthedefaulticontobeusedonallselectednodes,exceptwhenoverriddenonapernodebasisindata.
searchResultBackColor
String,anylegalcolorvalue.Default:undefined,inherits.
Setsthebackgroundcoloroftheselectednode.
searchResultColor
String,anylegalcolorvalue.Default:'#D9534F'.
Setstheforegroundcoloroftheselectednode.
selectedBackColor
String,anylegalcolorvalue.Default:'#428bca'.
Setsthebackgroundcoloroftheselectednode.
selectedColor
String,anylegalcolorvalue.Default:'#FFFFFF'.
Setstheforegroundcoloroftheselectednode.
showBorder
Boolean.Default:true
Whetherornottodisplayaborderaroundnodes.
showCheckbox
Boolean.Default:false
Whetherornottodisplaycheckboxesonnodes.
showIcon
Boolean.Default:true
Whetherornottodisplayanodesicon.
showTags
Boolean.Default:false
Whetherornottodisplaytagstotherightofeachnode.Thevaluesofwhichmustbeprovidedinthedatastructureonaper
nodebasis.
uncheckedIcon
String,classnames(s).Default:"glyphiconglyphiconunchecked"asdefinedbyBootstrapGlyphicons
Setstheicontobeasanuncheckedcheckbox,usedinconjunctionwithshowCheckbox.
Methods
Methodsprovideawayofinteractingwiththepluginprogrammatically.Forexample,expandinganodeispossibleviathe

expandNodemethod.
Youcaninvokemethodsinoneoftwoways,usingeither:
1.Theplugin'swrapper
Theplugin'swrapperworksasaproxyforaccessingtheunderlyingmethods.
$('#tree').treeview('methodName',args)
Limitation,multipleargumentsmustbepassedasanarrayofarguments.
2.Thetreeviewdirectly
Youcangetaninstanceofthetreeviewusingoneofthetwofollowingmethods.
//Thisspecialmethodreturnsaninstanceofthetreeview.
$('#tree').treeview(true)
.methodName(args);
//TheinstanceisalsosavedintheDOMelementsdata,
//andaccessibleusingtheplugin'sid'treeview'.
$('#tree').data('treeview')
.methodName(args);
Abetterapproach,ifyouplanalotofinteraction.
ListofMethods
Thefollowingisalistofallavailablemethods.
checkAll(options)
Checksalltreenodes
$('#tree').treeview('checkAll',{silent:true});
TriggersnodeCheckedevent;passsilenttosuppressevents.
checkNode(node|nodeId,options)
Checksagiventreenode,acceptsnodeornodeId.
$('#tree').treeview('checkNode',[nodeId,{silent:true}]);
TriggersnodeCheckedevent;passsilenttosuppressevents.
clearSearch()
Clearthetreeviewofanyprevioussearchresultse.g.removetheirhighlightedstate.
$('#tree').treeview('clearSearch');
TriggerssearchClearedevent
collapseAll(options)
Collapsealltreenodes,collapsingtheentiretree.
$('#tree').treeview('collapseAll',{silent:true});
TriggersnodeCollapsedevent;passsilenttosuppressevents.

collapseNode(node|nodeId,options)
Collapseagiventreenodeandit'schildnodes.Ifyoudon'twanttocollapsethechildnodes,passoption{ignoreChildren:
true}.
$('#tree').treeview('collapseNode',[nodeId,{silent:true,ignoreChildren:false}]);
TriggersnodeCollapsedevent;passsilenttosuppressevents.
disableAll(options)
Disablealltreenodes
$('#tree').treeview('disableAll',{silent:true});
TriggersnodeDisabledevent;passsilenttosuppressevents.
disableNode(node|nodeId,options)
Disableagiventreenode,acceptsnodeornodeId.
$('#tree').treeview('disableNode',[nodeId,{silent:true}]);
TriggersnodeDisabledevent;passsilenttosuppressevents.
enableAll(options)
Enablealltreenodes
$('#tree').treeview('enableAll',{silent:true});
TriggersnodeEnabledevent;passsilenttosuppressevents.
enableNode(node|nodeId,options)
Enableagiventreenode,acceptsnodeornodeId.
$('#tree').treeview('enableNode',[nodeId,{silent:true}]);
TriggersnodeEnabledevent;passsilenttosuppressevents.
expandAll(options)
Expandalltreenodes.Optionallycanbeexpandedtoanygivennumberoflevels.
$('#tree').treeview('expandAll',{levels:2,silent:true});
TriggersnodeExpandedevent;passsilenttosuppressevents.
expandNode(node|nodeId,options)
Expandagiventreenode,acceptsnodeornodeId.Optionallycanbeexpandedtoanygivennumberoflevels.
$('#tree').treeview('expandNode',[nodeId,{levels:2,silent:true}]);
TriggersnodeExpandedevent;passsilenttosuppressevents.
getCollapsed()
Returnsanarrayofcollapsednodese.g.state.expanded=false.

$('#tree').treeview('getCollapsed',nodeId);
getDisabled()
Returnsanarrayofdisablednodese.g.state.disabled=true.
$('#tree').treeview('getDisabled',nodeId);
getEnabled()
Returnsanarrayofenablednodese.g.state.disabled=false.
$('#tree').treeview('getEnabled',nodeId);
getExpanded()
Returnsanarrayofexpandednodese.g.state.expanded=true.
$('#tree').treeview('getExpanded',nodeId);
getNode(nodeId)
Returnsasinglenodeobjectthatmatchesthegivennodeid.
$('#tree').treeview('getNode',nodeId);
getParent(node|nodeId)
Returnstheparentnodeofagivennode,ifvalidotherwisereturnsundefined.
$('#tree').treeview('getParent',node);
getSelected()
Returnsanarrayofselectednodese.g.state.selected=true.
$('#tree').treeview('getSelected',nodeId);
getSiblings(node|nodeId)
Returnsanarrayofsiblingnodesforagivennode,ifvalidotherwisereturnsundefined.
$('#tree').treeview('getSiblings',node);
getUnselected()
Returnsanarrayofunselectednodese.g.state.selected=false.
$('#tree').treeview('getUnselected',nodeId);
remove()
Removesthetreeviewcomponent.Removingattachedevents,internalattachedobjects,andaddedHTMLelements.
$('#tree').treeview('remove');

revealNode(node|nodeId,options)
Revealsagiventreenode,expandingthetreefromnodetoroot.
$('#tree').treeview('revealNode',[nodeId,{silent:true}]);
TriggersnodeExpandedevent;passsilenttosuppressevents.
search(pattern,options)
Searchesthetreeviewfornodesthatmatchagivenstring,highlightingtheminthetree.
Returnsanarrayofmatchingnodes.
$('#tree').treeview('search',['Parent',{
ignoreCase:true,//caseinsensitive
exactMatch:false,//likeorequals
revealResults:true,//revealmatchingnodes
}]);
TriggerssearchCompleteevent
selectNode(node|nodeId,options)
Selectsagiventreenode,acceptsnodeornodeId.
$('#tree').treeview('selectNode',[nodeId,{silent:true}]);
TriggersnodeSelectedevent;passsilenttosuppressevents.
toggleNodeChecked(node|nodeId,options)
Togglesanodescheckedstate;checkingifunchecked,uncheckingifchecked.
$('#tree').treeview('toggleNodeChecked',[nodeId,{silent:true}]);
TriggerseithernodeCheckedornodeUncheckedevent;passsilenttosuppressevents.
toggleNodeDisabled(node|nodeId,options)
Togglesanodesdisabledstate;disablingifenabled,enablingifdisabled.
$('#tree').treeview('toggleNodeDisabled',[nodeId,{silent:true}]);
TriggerseithernodeDisabledornodeEnabledevent;passsilenttosuppressevents.
toggleNodeExpanded(node|nodeId,options)
Togglesanodesexpandedstate;collapsingifexpanded,expandingifcollapsed.
$('#tree').treeview('toggleNodeExpanded',[nodeId,{silent:true}]);
TriggerseithernodeExpandedornodeCollapsedevent;passsilenttosuppressevents.
toggleNodeSelected(node|nodeId,options)
Togglesanodeselectedstate;selectingifunselected,unselectingifselected.
$('#tree').treeview('toggleNodeSelected',[nodeId,{silent:true}]);
TriggerseithernodeSelectedornodeUnselectedevent;passsilenttosuppressevents.

uncheckAll(options)
Uncheckalltreenodes.
$('#tree').treeview('uncheckAll',{silent:true});
TriggersnodeUncheckedevent;passsilenttosuppressevents.
uncheckNode(node|nodeId,options)
Uncheckagiventreenode,acceptsnodeornodeId.
$('#tree').treeview('uncheckNode',[nodeId,{silent:true}]);
TriggersnodeUncheckedevent;passsilenttosuppressevents.
unselectNode(node|nodeId,options)
Unselectsagiventreenode,acceptsnodeornodeId.
$('#tree').treeview('unselectNode',[nodeId,{silent:true}]);
TriggersnodeUnselectedevent;passsilenttosuppressevents.
Events
Eventsareprovidedsothatyourapplicationcanrespondtochangesinthetreeview'sstate.Forexample,ifyouwantto
updateadisplaywhenanodeisselectedusethenodeSelectedevent.
Youcanbindtoanyeventdefinedbelowbyeitherusinganoptionscallbackhandler,orthestandardjQuery.onmethod.
Exampleusingoptionscallbackhandler:
$('#tree').treeview({
//Thenamingconventionforcallback'sistoprependwith`on`
//andcapitalizethefirstletteroftheeventname
//e.g.nodeSelected‐>onNodeSelected
onNodeSelected:function(event,data){
//Yourlogicgoeshere
});
andusingjQuery.onmethod
$('#tree').on('nodeSelected',function(event,data){
//Yourlogicgoeshere
});
ListofEvents
nodeChecked(event,node)Anodeischecked.
nodeCollapsed(event,node)Anodeiscollapsed.
nodeDisabled(event,node)Anodeisdisabled.
nodeEnabled(event,node)Anodeisenabled.
nodeExpanded(event,node)Anodeisexpanded.
nodeSelected(event,node)Anodeisselected.
nodeUnchecked(event,node)Anodeisunchecked.

nodeUnselected(event,node)Anodeisunselected.
searchComplete(event,results)Afterasearchcompletes
searchCleared(event,results)Aftersearchresultsarecleared
CopyrightandLicensing
Copyright2013JonathanMiles
LicensedundertheApacheLicense,Version2.0(the"License");youmaynotusethisfileexceptincompliancewiththe
License.YoumayobtainacopyoftheLicenseathttp://www.apache.org/licenses/LICENSE2.0
Unlessrequiredbyapplicablelaworagreedtoinwriting,softwaredistributedundertheLicenseisdistributedonan"ASIS"
BASIS,WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.SeetheLicenseforthe
specificlanguagegoverningpermissionsandlimitationsundertheLicense.
StatusAPITrainingShopBlogAbout©2016GitHub,Inc. TermsPrivacySecurityContactHelp