Click here to Skip to main content
13,089,400 members (63,015 online)
Click here to Skip to main content
Add your own
alternative version

Stats

42.9K views
19 bookmarked
Posted 5 Jan 2012

jQuery Tree with Checkboxes

, 5 Jan 2012
Rate this:
Please Sign up or sign in to vote.
How to add a jQuery Tree with Checkboxes to your web page

Today, we will show you how to add a jQuery Tree with Checkboxes to your web page.

The first step is to include the JavaScript files. The jQuery framework and jqxcore.js should always be included when you want to use our jQuery widgets. The logic of the jQuery Tree is implemented in jqxtree.js. The Tree plug-in uses several other plug-ins like scrollbar, button, and panel and they should be included, too. In order to show a checkbox in each tree item, you need to include jqxcheckbox.js.

<script type="text/javascript" src="../../scripts/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxscrollbar.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxpanel.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxtree.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcheckbox.js"></script>

The next step is to include the CSS stylesheet(s).

<link rel="stylesheet" 

href="../../jqwidgets/styles/jqx.base.css" type="text/css" />

Add the HTML markup. The tree can be created from a DIV tag with UL inside the DIV.

<div id='jqxTree'>
    <ul>
        <li item-selected='true'>Home</li>
        <li item-checked='true' 

        item-expanded='true'><a href="#">Solutions</a>
            <ul>
                <li><a href="#">Government</a></li>
                <li item-checked='false'><a href="#">Manufacturing</a></li>
                <li><a href="#">Solutions</a>
                    <ul>
                        <li><a href="#">Consumer photo and video</a></li>
                        <li><a href="#">Mobile</a></li>
                        <li><a href="#">Rich Internet applications</a></li>
                        <li><a href="#">Technical communication</a></li>
                        <li><a href="#">Training and eLearning</a></li>
                        <li><a href="#">Web conferencing</a></li>
                    </ul>
                </li>
                <li><a href="#">All industries and solutions</a></li>
            </ul>
        </li>
    </ul>
</div>

Create the Tree by using the jqxTree constructor.

$('#jqxTree').jqxTree({ height: '400px', 
width: '330px', hasThreeStates: true, checkboxes: true});

To enable the checkboxes, you need to set the ‘checkboxes’ property to true. You can also enable three-state checkboxes. In this mode, when the user checks an item, its sub items also become checked. When there is an unchecked item, the parent item is in indeterminate state. To enable the three-state checkboxes, set the ‘hasThreeStates’ property to true.

jquery tree with checkboxes

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

jqwidgets
jQWidgets
United States United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.
Group type: Organisation

13 members


You may also be interested in...

Comments and Discussions

 
QuestionjQuery Tree with Checkboxes Pin
Member 117360602-Jun-15 4:55
memberMember 117360602-Jun-15 4:55 
Questionwhere will I download those plugins. Give me link Pin
anurag1928913-Mar-14 2:21
memberanurag1928913-Mar-14 2:21 
Questionplease put a pic from tree Pin
leylaazari18-Nov-13 20:26
memberleylaazari18-Nov-13 20:26 
AnswerRe: please put a pic from tree Pin
jqwidgets18-Nov-13 20:30
groupjqwidgets18-Nov-13 20:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 5 Jan 2012
Article Copyright 2012 by jqwidgets
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid