jQuery UI Widgets Forums Navigation Tree Tree – Allow one checkbox for each node and disable other elements in same level

This topic contains 3 replies, has 3 voices, and was last updated by  Dimitar 10 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author

  • raghu_muni
    Participant

    Root

    —–Node 1

    ————- Data a

    ————- Data b
    ————- Node11
    —————— Data b1
    —————— Data b2
    ————- Data c

    —–Node 2

    ————- Data d

    ————- Data e

    ————- Data f

    —–Node 3

    ————- Data g

    Note : I Need to select only one element at each node.
    Node 1 : I need to select only one checkbox for Data a, Data b,Data b1 and Data b2.
    Node 2 : I can select only one checkbox for Data d, Data e,Data f


    Dimitar
    Participant

    Hello raghu_muni,

    Here is an example. We hope it is helpful to you:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script>
        <script type="text/javascript" src="../../scripts/demos.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>
        <script type="text/javascript">
            $(document).ready(function () {
                // create jqxTree
                $('#jqxTree').jqxTree({ height: '400px', checkboxes: true, width: '330px' });
                $('#jqxTree').css('visibility', 'visible');
                var checkedItem = null;
                var selectedItem = null;
                $('#jqxTree').on('select', function (event) {
                    var args = event.args;
                    var item = $('#jqxTree').jqxTree('getItem', args.element);
                    var label = item.label;
                    if (item.level == 0) {
                        selectedItem = item;
                    } else {
                        $("#jqxTree").jqxTree('selectItem', selectedItem);
                    }
                });
                $('#jqxTree').on('checkChange', function (event) {
                    var item = $('#jqxTree').jqxTree('getItem', event.args.element);
                    if (event.args.checked == true) {
                        if (checkedItem == null && item.hasItems == false) {
                            checkedItem = item;
                        } else {
                            $('#jqxTree').jqxTree('uncheckItem', event.args.element);
                        }
                    } else {
                        if (checkedItem && item.label == checkedItem.label) {
                            checkedItem = null;
                        }
                    }
                });
            });
        </script>
    </head>
    <body class='default'>
        <div id='jqxTree' style='visibility: hidden; float: left; margin-left: 20px;'>
            <ul>
                <li id='home'>Home</li>
                <li item-expanded='true'>Solutions
                            <ul>
                                <li>Education</li>
                                <li>Financial services</li>
                                <li>Government</li>
                                <li item-checked='false'>Manufacturing</li>
                                <li>Solutions
                                    <ul>
                                        <li>Consumer photo and video</li>
                                        <li>Mobile</li>
                                        <li>Rich Internet applications</li>
                                        <li>Technical communication</li>
                                        <li>Training and eLearning</li>
                                        <li>Web conferencing</li>
                                    </ul>
                                </li>
                                <li>All industries and solutions</li>
                            </ul>
                </li>
                <li>Products
                            <ul>
                                <li>PC products</li>
                                <li>Mobile products</li>
                                <li>All products</li>
                            </ul>
                </li>
                <li>Support
                            <ul>
                                <li>Support home</li>
                                <li>Customer Service</li>
                                <li>Knowledge base</li>
                                <li>Books</li>
                                <li>Training and certification</li>
                                <li>Support programs</li>
                                <li>Forums</li>
                                <li>Documentation</li>
                                <li>Updates</li>
                            </ul>
                </li>
                <li>Communities
                            <ul>
                                <li>Designers</li>
                                <li>Developers</li>
                                <li>Educators and students</li>
                                <li>Partners</li>
                                <li>By resource
                                    <ul>
                                        <li>Labs</li>
                                        <li>TV</li>
                                        <li>Forums</li>
                                        <li>Exchange</li>
                                        <li>Blogs</li>
                                        <li>Experience Design</li>
                                    </ul>
                                </li>
                            </ul>
                </li>
                <li>Company
                            <ul>
                                <li>About Us</li>
                                <li>Press</li>
                                <li>Investor Relations</li>
                                <li>Corporate Affairs</li>
                                <li>Careers</li>
                                <li>Showcase</li>
                                <li>Events</li>
                                <li>Contact Us</li>
                                <li>Become an affiliate</li>
                            </ul>
                </li>
            </ul>
        </div>
    </body>
    </html>

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/


    ashish_iitr
    Participant

    Hello sir,
    Above code is not working perfectly. I have a list of node directory, each directory have a number of directories with their corresponding checkboxes and i want to select only one checkbox for a specific parent directory can you help me please as soon as possible its urgent.


    Dimitar
    Participant

    Hi ashish_iitr,

    The solution above allows only one checked item of a second or lower level. Unfortunately, we cannot provide you with an example which allows one checked descendant per top-level element. This is a custom scenario which may or may not be supported by jqxTree. As some help, we can provide you with a function which determines the top-level ancestor of a tree item:

    function getParent(item) {
        if (item.level == 0) {
            return null;
        } else if (item.level == 1) {
            return $('#jqxTree').jqxTree('getItem', item.parentElement).label;
        } else {
            return getParent($('#jqxTree').jqxTree('getItem', item.parentElement));
        }
    }

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.