forked from syncfusion/blazor-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalData.razor
322 lines (287 loc) · 8.87 KB
/
LocalData.razor
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
@page "/treeview/local-data"
@using Syncfusion.Blazor.Navigations
@inherits SampleBaseComponent;
<SampleDescription>
<p> The <a href='https://www.syncfusion.com/blazor-components/blazor-treeview' target='_blank'>Blazor TreeView</a> sample demonstrates the binding of local data to the TreeView. Click on node to select it, and click on icon or double click on node to expand/collapse it.</p>
</SampleDescription>
<ActionDescription>
<p>The TreeView component loads the data through the dataSource property, where the data can be either local data or remote data. In case of local data, the data structure can be hierarchical data or list data (with self-referential format i.e., mapped with the Id and ParentID fields). In this demo, the first TreeView is bound with the hierarchical data that contains array of nested objects. And the second TreeView is bound with the list type data where the parent-child relation is referred by the Id and ParentID mapping fields. More information about Treeview can be found in this <a target='blank' href='https://ej2.syncfusion.com/aspnet-core-blazor/documentation/treeview/data-binding/'>documentation</a> section .</p>
</ActionDescription>
<div class="col-lg-12 control-section">
<div class="col-lg-6 nested-data">
<div class="content">
<h4>Hierarchical Data</h4>
<SfTreeView TValue="TreeData">
<TreeViewFieldsSettings DataSource="@TreeDataSource" Id="Code" Text="Name" Selected="Selected" Expanded="Expanded" Child="@("Child")"></TreeViewFieldsSettings>
</SfTreeView>
</div>
</div>
<div class="col-lg-6 list-data">
<div class="content">
<h4>List Data</h4>
<SfTreeView TValue="Listdata">
<TreeViewFieldsSettings DataSource="@ListDataSource" Id="Id" ParentID="Pid" Text="Name" HasChildren="HasChild" Expanded="Expanded"></TreeViewFieldsSettings>
</SfTreeView>
</div>
</div>
</div>
@code{
List<Listdata> ListDataSource = new List<Listdata>();
List<TreeData> TreeDataSource = new List<TreeData>();
protected override void OnInitialized()
{
base.OnInitialized();
ListDataSource.Add(new Listdata
{
Id = "1",
Name = "Australia",
HasChild = true,
Expanded = true
});
ListDataSource.Add(new Listdata
{
Id = "2",
Pid = "1",
Name = "New South Wales",
});
ListDataSource.Add(new Listdata
{
Id = "3",
Pid = "1",
Name = "Victoria"
});
ListDataSource.Add(new Listdata
{
Id = "4",
Pid = "1",
Name = "South Australia"
});
ListDataSource.Add(new Listdata
{
Id = "6",
Pid = "1",
Name = "Western Australia",
});
ListDataSource.Add(new Listdata
{
Id = "7",
Name = "Brazil",
HasChild = true
});
ListDataSource.Add(new Listdata
{
Id = "8",
Pid = "7",
Name = "Paraná"
});
ListDataSource.Add(new Listdata
{
Id = "9",
Pid = "7",
Name = "Ceará"
});
ListDataSource.Add(new Listdata
{
Id = "10",
Pid = "7",
Name = "Acre"
});
ListDataSource.Add(new Listdata
{
Id = "11",
Name = "China",
HasChild = true
});
ListDataSource.Add(new Listdata
{
Id = "12",
Pid = "11",
Name = "Guangzhou"
});
ListDataSource.Add(new Listdata
{
Id = "13",
Pid = "11",
Name = "Shanghai"
});
ListDataSource.Add(new Listdata
{
Id = "14",
Pid = "11",
Name = "Beijing"
});
ListDataSource.Add(new Listdata
{
Id = "15",
Pid = "11",
Name = "Shantou"
});
ListDataSource.Add(new Listdata
{
Id = "16",
Name = "France",
HasChild = true
});
ListDataSource.Add(new Listdata
{
Id = "17",
Pid = "16",
Name = "Pays de la Loire"
});
ListDataSource.Add(new Listdata
{
Id = "18",
Pid = "16",
Name = "Aquitaine"
});
ListDataSource.Add(new Listdata
{
Id = "19",
Pid = "16",
Name = "Brittany"
});
ListDataSource.Add(new Listdata
{
Id = "20",
Pid = "16",
Name = "Lorraine"
});
ListDataSource.Add(new Listdata
{
Id = "21",
Name = "India",
HasChild = true
});
ListDataSource.Add(new Listdata
{
Id = "22",
Pid = "21",
Name = "Assam"
});
ListDataSource.Add(new Listdata
{
Id = "23",
Pid = "21",
Name = "Bihar"
});
ListDataSource.Add(new Listdata
{
Id = "24",
Pid = "21",
Name = "Tamil Nadu"
});
TreeDataSource.Add(new TreeData
{
Code = "NA",
Name = "North America",
Expanded = true,
Child = new List<TreeData>()
{
new TreeData { Code = "USA", Name = "United States of America", Selected = true },
new TreeData { Code = "CUB", Name = "Cuba" },
new TreeData { Code = "MEX", Name = "Mexico" },
},
});
TreeDataSource.Add(new TreeData
{
Code = "AF",
Name = "Africa",
Child = new List<TreeData>()
{
new TreeData { Code = "NGA", Name = "Nygeria" },
new TreeData { Code = "EGY", Name = "Egypt" },
new TreeData { Code = "ZAF", Name = "South Africa" },
},
});
TreeDataSource.Add(new TreeData
{
Code = "AS",
Name = "Asia",
Child = new List<TreeData>()
{
new TreeData { Code = "CHN", Name = "China" },
new TreeData { Code = "IND", Name = "India" },
new TreeData { Code = "JPN", Name = "Japan" },
},
});
TreeDataSource.Add(new TreeData
{
Code = "EU",
Name = "Europe",
Child = new List<TreeData>()
{
new TreeData { Code = "DNK", Name = "Denmark" },
new TreeData { Code = "AUT", Name = "Austria" },
new TreeData { Code = "FIN", Name = "Finland" },
},
});
TreeDataSource.Add(new TreeData
{
Code = "SA",
Name = "South America",
Child = new List<TreeData>()
{
new TreeData { Code = "BRA", Name = "Brazil" },
new TreeData { Code = "COL", Name = "Colombia" },
new TreeData { Code = "ARG", Name = "Argentina" },
},
});
TreeDataSource.Add(new TreeData
{
Code = "OC",
Name = "Oceania",
Child = new List<TreeData>()
{
new TreeData { Code = "AUS", Name = "Australia" },
new TreeData { Code = "NZL", Name = "Newzealand" },
new TreeData { Code = "WSM", Name = "Samoa" },
},
});
TreeDataSource.Add(new TreeData
{
Code = "AN",
Name = "Antartica",
Child = new List<TreeData>()
{
new TreeData { Code = "BVT", Name = "Bouvet Island" },
new TreeData { Code = "ATF", Name = "French Southern Lands" },
},
});
}
public class Listdata
{
public string Id { get; set; }
public string Pid { get; set; }
public string Name { get; set; }
public bool HasChild { get; set; }
public bool Expanded { get; set; }
}
public class TreeData
{
public string Code { get; set; }
public string Name { get; set; }
public bool Expanded { get; set; }
public bool Selected { get; set; }
public List<TreeData> Child;
}
}
<style>
.control_wrapper {
max-width: 500px;
margin: auto;
border: 1px solid #dddddd;
border-radius: 3px;
}
.nested-data, .list-data {
padding: 15px;
margin-bottom: 25px;
}
.content {
margin: 0 auto;
border: 1px solid #dddddd;
border-radius: 3px;
}
.content h4 {
padding: 0 10px;
}
</style>