Heterogeneous Data

In most TreeView applications, the displayMemberPath and childItemsPath properties are set to strings that define the name of the property that should be displayed on the nodes and the name of the property that contains child items (the default values for these properties are 'header' and 'items').

In some applications, however, the names of these binding properties depends on the hierarchical level of the data. In these cases, you can use an array of names for either property.

The tree below is bound to a list of 'continent' items, each with a 'countries' member that contains a list of 'country' items with a 'cities' member:

Africa
Algeria
Algiers
Oran
Constantine
Luanda
Ambriz
Bailundo
Porto Novo
Cotonou
Parakou
Gaborone
Francistown
Molepolole
Kabul
Kandahar
Herat
Yerevan
Gyumri
Vanadzor
Baku
Agjabadi
Astara
Manama
Riffa
Sitra
Tirana
Elbasan
Fier
Andorra la Vieja
Canillo
Encamp
Vienna
Salzburg
Graz
Minsk
Barysaw
Slutsk
Ottawa
Toronto
Vancouver
Washington
New York
Pittsburgh
Mexico City
Acapulco
San Jose
Belmopan
Dangriga
Belize City
Canberra
Sydney
Melbourne
Wellington
Christchurch
Auckland
Suva
Labasa
Nasinu
Port Vila
Forari
Etate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// This file locates: "Scripts/Lesson/C1Nav/HeterogeneousData.js".
c1.documentReady(function () {
    var tree = wijmo.Control.getControl('#theTree');
 
    tree.itemsSource = getData();
    tree.displayMemberPath = 'continent,country,city'.split(',');
    tree.childItemsPath = 'countries,cities'.split(',');
 
    // get the data
    function getData() {
        return [
            {
                continent: 'Africa', countries: [
                  {
                      country: 'Algeria', cities: [
                        { city: 'Algiers' },
                        { city: 'Oran' },
                        { city: 'Constantine' }
                      ]
                  },
                  {
                      country: 'Angola', cities: [
                        { city: 'Luanda' },
                        { city: 'Ambriz' },
                        { city: 'Bailundo' }
                      ]
                  },
                  {
                      country: 'Benin', cities: [
                        { city: 'Porto Novo' },
                        { city: 'Cotonou' },
                        { city: 'Parakou' }
                      ]
                  },
                  {
                      country: 'Botswana', cities: [
                        { city: 'Gaborone' },
                        { city: 'Francistown' },
                        { city: 'Molepolole' }
                      ]
                  },
                ]
            },
            {
                continent: 'Asia', countries: [
                  {
                      country: 'Afghanistan', cities: [
                        { city: 'Kabul' },
                        { city: 'Kandahar' },
                        { city: 'Herat' }
                      ]
                  },
                  {
                      country: 'Armenia', cities: [
                        { city: 'Yerevan' },
                        { city: 'Gyumri' },
                        { city: 'Vanadzor' }
                      ]
                  },
                  {
                      country: 'Azerbaijan', cities: [
                        { city: 'Baku' },
                        { city: 'Agjabadi' },
                        { city: 'Astara' }
                      ]
                  },
                  {
                      country: 'Bahrain', cities: [
                        { city: 'Manama' },
                        { city: 'Riffa' },
                        { city: 'Sitra' }
                      ]
                  },
                ]
            },
            {
                continent: 'Europe', countries: [
                  {
                      country: 'Albania', cities: [
                        { city: 'Tirana' },
                        { city: 'Elbasan' },
                        { city: 'Fier' }
                      ]
                  },
                  {
                      country: 'Andorra', cities: [
                        { city: 'Andorra la Vieja' },
                        { city: 'Canillo' },
                        { city: 'Encamp' }
                      ]
                  },
                  {
                      country: 'Austria', cities: [
                        { city: 'Vienna' },
                        { city: 'Salzburg' },
                        { city: 'Graz' }
                      ]
                  },
                  {
                      country: 'Belarus', cities: [
                        { city: 'Minsk' },
                        { city: 'Barysaw' },
                        { city: 'Slutsk' }
                      ]
                  },
                ]
            },
            {
                continent: 'America', countries: [
                  {
                      country: 'Canada', cities: [
                        { city: 'Ottawa' },
                        { city: 'Toronto' },
                        { city: 'Vancouver' }
                      ]
                  },
                  {
                      country: 'United States', cities: [
                        { city: 'Washington' },
                        { city: 'New York' },
                        { city: 'Pittsburgh' }
                      ]
                  },
                  {
                      country: 'Mexico', cities: [
                        { city: 'Mexico City' },
                        { city: 'Acapulco' },
                        { city: 'San Jose' }
                      ]
                  },
                  {
                      country: 'Belize', cities: [
                        { city: 'Belmopan' },
                        { city: 'Dangriga' },
                        { city: 'Belize City' }
                      ]
                  },
                ]
            },
            {
                continent: 'Ocenania', countries: [
                  {
                      country: 'Australia', cities: [
                        { city: 'Canberra' },
                        { city: 'Sydney' },
                        { city: 'Melbourne' }
                      ]
                  },
                  {
                      country: 'New Zealand', cities: [
                        { city: 'Wellington' },
                        { city: 'Christchurch' },
                        { city: 'Auckland' }
                      ]
                  },
                  {
                      country: 'Fiji', cities: [
                        { city: 'Suva' },
                        { city: 'Labasa' },
                        { city: 'Nasinu' }
                      ]
                  },
                  {
                      country: 'Vanuatu', cities: [
                        { city: 'Port Vila' },
                        { city: 'Forari' },
                        { city: 'Etate' }
                      ]
                  },
                ]
            },
        ];
    }
});
1
2
3
4
5
6
7
8
9
10
11
// This file locates: "Content/css/Lesson/C1Nav/HeterogeneousData.css".
/* default trees on this sample */
.demo-control .wj-treeview {
    display:block;
    //height: 350px;
    font-size: 120%;
    margin-bottom: 8px;
    padding: 6px;
    background: #f0f0f0;
    box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
using System.Web.Mvc;
 
namespace LearnMvcClient.Controllers
{
    public partial class C1NavController : Controller
    {
        // GET: HeterogeneousData
        public ActionResult HeterogeneousData()
        {
            return View();
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<h1>
    @Html.Raw(Resources.C1Nav.HeterogeneousData_Title)
</h1>
<p>
    @Html.Raw(Resources.C1Nav.HeterogeneousData_Text1)
</p>
<p>
    @Html.Raw(Resources.C1Nav.HeterogeneousData_Text2)
</p>
<p>
    @Html.Raw(Resources.C1Nav.HeterogeneousData_Text3)
</p>
 
@Html.C1().TreeView().Id("theTree")