Available in the OSS Version

Tree - XML Binding

This sample demonstrates how to data bind the igTree to an XML data.

This sample is designed for a larger screen size.

On mobile, try rotating your screen, view full size, or email to another device.

Code View

Copy to Clipboard
<!DOCTYPE html>
<html>
<head>
    <title></title>

    <!-- Ignite UI for jQuery Required Combined CSS Files -->
    <link href="http://cdn-na.infragistics.com/igniteui/2024.2/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet" />
    <link href="http://cdn-na.infragistics.com/igniteui/2024.2/latest/css/structure/infragistics.css" rel="stylesheet" />

    <script src="http://ajax.aspnetcdn.com/ajax/modernizr/modernizr-2.8.3.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>

    <!-- Ignite UI for jQuery Required Combined JavaScript Files -->
    <script src="http://cdn-na.infragistics.com/igniteui/2024.2/latest/js/infragistics.core.js"></script>
    <script src="http://cdn-na.infragistics.com/igniteui/2024.2/latest/js/infragistics.lob.js"></script>

</head>
<body>

    <ul id="tree"></ul>

    <script>

        $(function () {

            //Sample XML Data
            var xmlDoc = '<OrgChart Name="All Employees">' +
                '<Employee Name="Gustavo Achong" Age="42" Email="gachong@adventureworks.com">' +
                    '<Employee Name="Kim Abercrombie" Age="33" Email="kabercrombie@adventureworks.com" />' +
                    '<Employee Name="Lawrence Tapley" Age="52" Email="ltapley@adventureworks.com" />' +
                '</Employee>' +
                '<Employee Name="Catherine Abel" Age="27" Email="cabel@adventureworks.com">' +
                    '<Employee Name="Kristen Anderson" Age="30" Email="kanderson@adventureworks.com" />' +
                    '<Employee Name="Richard Lee" Age="25" Email="rlee@adventureworks.com" />' +
                    '<Employee Name="Victoria Gramley" Age="23" Email="vgramley@adventureworks.com" />' +
                '</Employee>' +
                '<Employee Name="Adrienne Mauro" Age="27" Email="amauro@adventureworks.com">' +
                    '<Employee Name="Christopher Chadwick" Age="37" Email="cchadwick@adventureworks.com" />' +
                '</Employee>' +
            '</OrgChart>';

            //Binding to XML requires a schema to define data fields
            var xmlSchema = new $.ig.DataSchema("xml",
                {
                    //searchField serves as the base node(s) for the XPaths
                    searchField: "OrgChart",
                    childDataProperty: "Employee",
                    fields: [
                        { name: "Name", xpath: "@Name" },
                        { name: "Age", xpath: "@Age" },
                        { name: "Email", xpath: "@Email" },
                        { name: "Employee", xpath: "Employee" }
                    ]
                }
            );

            //This creates an Infragistics datasource from the XML 
            //and the Schema which can be consumed by the grid.
            var ds = new $.ig.DataSource({
                type: "xml",
                dataSource: xmlDoc,
                schema: xmlSchema
            });

            $("#tree").igTree({
                dataSource: ds, //$.ig.DataSource object defined above
                dataSourceType: 'xml',
                bindings: {
                    textKey: "Name",
                    childDataProperty: "Employee"
                }
            });
        });
    </script>

</body>
</html>