Available in the Full Version

Hierarchical Grid - XML Binding

Name

This sample is designed for a larger screen size.

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

The sample demonstrates how to bind igHierarchicalGrid to XML data source. Note that Binding to XML requires a schema to define data fields.

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>

    <table id="hierarchicalGrid1"></table>

    <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
            });

            $("#hierarchicalGrid1").igHierarchicalGrid({
                dataSource: ds, //$.ig.DataSource object defined above
                autoGenerateColumns: false,
                columns: [
                    { headerText: "Name", key: "Name" }
                ],
                columnLayouts : [{
                    key: "Employee",
                    autoGenerateColumns: false,
                    columns: [
                        { headerText: "Name", key: "Name" },
                        { headerText: "Age", key: "Age" },
                        { headerText: "Email", key: "Email" }
                    ],
                    columnLayouts : [{
                        key: "Employee",
                        autoGenerateColumns: false,
                        columns: [
                            { headerText: "Name", key: "Name" },
                            { headerText: "Age", key: "Age" },
                            { headerText: "Email", key: "Email" }
                        ]
                    }],
                }]
            });
        });

    </script>

</body>
</html>