Skip to content

Commit 4266845

Browse files
ES-975464 - Resolve the ReadMe issue in this sample repository
1 parent 26e9f47 commit 4266845

File tree

1 file changed

+307
-2
lines changed

1 file changed

+307
-2
lines changed

README.md

Lines changed: 307 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,307 @@
1-
# How to load data on demand using events in winui treegrid?
2-
This examples describes how to load data on demand using events in winui treegrid.
1+
# How to load data on demand using events in WinUI TreeGrid
2+
3+
This examples describes how to load data on demand using events in [WinUI TreeGrid](https://www.syncfusion.com/winui-controls/treegrid) (SfTreeGrid).
4+
5+
SfTreeGrid supports to load the data in on-demand through [SfTreeGrid.RequestTreeItems](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.TreeGrid.SfTreeGrid.html#Syncfusion_UI_Xaml_TreeGrid_SfTreeGrid_RequestTreeItems) event. `RequestTreeItems` event is triggered at the time of loading and when user expand any node at runtime. SfTreeGrid gets the root and leaf nodes through this event handler.
6+
7+
`TreeGridRequestTreeItemsEventArgs.ParentItem` denotes the data object looking for its child nodes. If it is null, it denotes SfTreeGrid requesting root nodes.
8+
9+
In the below example SfTreeGrid is populated through `SfTreeGrid.RequestTreeItems` instead of setting [SfTreeGrid.ItemsSource](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.TreeGrid.SfTreeGrid.html#Syncfusion_UI_Xaml_TreeGrid_SfTreeGrid_ItemsSource).
10+
11+
``` csharp
12+
treeGrid.RequestTreeItems += TreeGrid_RequestTreeItems;
13+
14+
private void TreeGrid_RequestTreeItems(object sender, TreeGridRequestTreeItemsEventArgs e)
15+
{
16+
if (e.ParentItem == null)
17+
{
18+
//get the root list - get all employees who have no boss
19+
e.ChildItems = (this.treeGrid.DataContext as ViewModel).EmployeeDetails.Where(x => x.ReportsTo == -1); //get all employees whose boss's id is -1 (no boss)
20+
}
21+
else //if ParentItem not null, then set args.ChildList to the child items for the given ParentItem.
22+
{ //get the children of the parent object
23+
EmployeeInfo emp = e.ParentItem as EmployeeInfo;
24+
if (emp != null)
25+
{
26+
//get all employees that report to the parent employee
27+
e.ChildItems = (this.treeGrid.DataContext as ViewModel).GetReportees(emp.ID);
28+
}
29+
}
30+
}
31+
```
32+
33+
``` csharp
34+
public class EmployeeInfo : NotificationObject
35+
{
36+
int _id;
37+
38+
/// <summary>
39+
/// Gets or sets the ID.
40+
/// </summary>
41+
/// <value>The ID.</value>
42+
public int ID
43+
{
44+
get
45+
{
46+
return _id;
47+
}
48+
set
49+
{
50+
_id = value;
51+
RaisePropertyChanged("ID");
52+
}
53+
}
54+
string _firstName;
55+
56+
/// <summary>
57+
/// Gets or sets the first name.
58+
/// </summary>
59+
/// <value>The first name.</value>
60+
public string FirstName
61+
{
62+
get
63+
{
64+
return _firstName;
65+
}
66+
set
67+
{
68+
_firstName = value;
69+
RaisePropertyChanged("FirstName");
70+
}
71+
}
72+
string _lastName;
73+
74+
/// <summary>
75+
/// Gets or sets the last name.
76+
/// </summary>
77+
/// <value>The last name.</value>
78+
public string LastName
79+
{
80+
get
81+
{
82+
return _lastName;
83+
}
84+
set
85+
{
86+
_lastName = value;
87+
RaisePropertyChanged("LastName");
88+
}
89+
}
90+
91+
private string _title;
92+
93+
/// <summary>
94+
/// Gets or sets the title.
95+
/// </summary>
96+
/// <value>The title.</value>
97+
public string Title
98+
{
99+
get
100+
{
101+
return _title;
102+
}
103+
set
104+
{
105+
_title = value;
106+
RaisePropertyChanged("Title");
107+
}
108+
}
109+
110+
double? _salary;
111+
112+
/// <summary>
113+
/// Gets or sets the salary.
114+
/// </summary>
115+
/// <value>The salary.</value>
116+
public double? Salary
117+
{
118+
get
119+
{
120+
return _salary;
121+
}
122+
set
123+
{
124+
_salary = value;
125+
RaisePropertyChanged("Salary");
126+
}
127+
}
128+
129+
int _reportsTo;
130+
131+
/// <summary>
132+
/// Gets or sets the reports to.
133+
/// </summary>
134+
/// <value>The reports to.</value>
135+
public int ReportsTo
136+
{
137+
get
138+
{
139+
return _reportsTo;
140+
}
141+
set
142+
{
143+
_reportsTo = value;
144+
RaisePropertyChanged("ReportsTo");
145+
}
146+
}
147+
}
148+
```
149+
150+
``` csharp
151+
public class ViewModel : NotificationObject
152+
{
153+
/// <summary>
154+
/// Initializes a new instance of the <see cref="ViewModel"/> class.
155+
/// </summary>
156+
public ViewModel()
157+
{
158+
EmployeeDetails = new List<EmployeeInfo>();
159+
EmployeeDetails.Add(new EmployeeInfo() { FirstName = "Hwakin", ID = 65, LastName = "Grant", Title = "Business Manager", Salary = 200000, ReportsTo = -1 });
160+
EmployeeDetails.Add(new EmployeeInfo() { FirstName = "Madison", ID = 34, LastName = "Bush", Title = "Vice President", Salary = 200000, ReportsTo = -1 });
161+
EmployeeDetails.Add(new EmployeeInfo() { FirstName = "Richard", ID = 36, LastName = "Monroe", Title = "HR Coordinator", Salary = 200000, ReportsTo = -1 });
162+
EmployeeDetails.Add(new EmployeeInfo() { FirstName = "Jack", ID = 43, LastName = "Madison", Title = "Supervisor", Salary = 25000, ReportsTo = 55 });
163+
}
164+
165+
/// <summary>
166+
/// Gets or sets the employee details.
167+
/// </summary>
168+
/// <value>The employee details.</value>
169+
public List<EmployeeInfo> EmployeeDetails
170+
{
171+
get;
172+
set;
173+
}
174+
175+
/// <summary>
176+
/// Gets the reportees.
177+
/// </summary>
178+
/// <param name="bossID">The boss ID.</param>
179+
/// <returns></returns>
180+
public IEnumerable<EmployeeInfo> GetReportees(int bossID)
181+
{
182+
List<EmployeeInfo> list = new List<EmployeeInfo>();
183+
184+
if (bossID == 65)
185+
{
186+
list.Add(new EmployeeInfo() { FirstName = "John", ID = 5, LastName = "Polk", Title = "Marketing Specialist", Salary = 100000, ReportsTo = 65 });
187+
list.Add(new EmployeeInfo() { FirstName = "Bill", ID = 26, LastName = "Wilson", Title = "Senior Tool Designer", Salary = 100000, ReportsTo = 65 });
188+
list.Add(new EmployeeInfo() { FirstName = "Jimmy", ID = 23, LastName = "Harry", Title = "Stocker", Salary = 50000, ReportsTo = 65 });
189+
list.Add(new EmployeeInfo() { FirstName = "Harry", ID = 68, LastName = "Coolidge", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 65 });
190+
}
191+
192+
if (bossID == 34)
193+
{
194+
list.Add(new EmployeeInfo() { FirstName = "Franklin", ID = 24, LastName = "Madison", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 34 });
195+
list.Add(new EmployeeInfo() { FirstName = "William", ID = 66, LastName = "Nixon", Title = "Production Technician", Salary = 40000, ReportsTo = 34 });
196+
list.Add(new EmployeeInfo() { FirstName = "Grover", ID = 35, LastName = "Taft", Title = "Stocker", Salary = 50000, ReportsTo = 34 });
197+
list.Add(new EmployeeInfo() { FirstName = "Bill", ID = 18, LastName = "Nixon", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 34 });
198+
}
199+
200+
if (bossID == 36)
201+
{
202+
list.Add(new EmployeeInfo() { FirstName = "Madison", ID = 64, LastName = "Franklin", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 36 });
203+
list.Add(new EmployeeInfo() { FirstName = "Wilson", ID = 67, LastName = "Harry", Title = "Production Technician", Salary = 40000, ReportsTo = 36 });
204+
list.Add(new EmployeeInfo() { FirstName = "Harry", ID = 59, LastName = "Taft", Title = "Stocker", Salary = 50000, ReportsTo = 36 });
205+
list.Add(new EmployeeInfo() { FirstName = "Jimmy", ID = 08, LastName = "Grover", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 36 });
206+
}
207+
208+
if (bossID == 5)
209+
{
210+
list.Add(new EmployeeInfo() { FirstName = "Franklin", ID = 47, LastName = "William", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 5 });
211+
list.Add(new EmployeeInfo() { FirstName = "Taft", ID = 52, LastName = "Peter", Title = "Production Technician", Salary = 40000, ReportsTo = 5 });
212+
list.Add(new EmployeeInfo() { FirstName = "Harry", ID = 34, LastName = "Wilson", Title = "Stocker", Salary = 50000, ReportsTo = 5 });
213+
list.Add(new EmployeeInfo() { FirstName = "Grover", ID = 41, LastName = "John", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 5 });
214+
}
215+
216+
if (bossID == 26)
217+
{
218+
list.Add(new EmployeeInfo() { FirstName = "Andrew", ID = 11, LastName = "Wilson", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 26 });
219+
list.Add(new EmployeeInfo() { FirstName = "George", ID = 24, LastName = "Madison", Title = "Production Technician", Salary = 40000, ReportsTo = 26 });
220+
list.Add(new EmployeeInfo() { FirstName = "Peter", ID = 33, LastName = "Taft", Title = "Stocker", Salary = 50000, ReportsTo = 26 });
221+
list.Add(new EmployeeInfo() { FirstName = "Jimmy", ID = 54, LastName = "Harry", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 26 });
222+
}
223+
224+
if (bossID == 23)
225+
{
226+
list.Add(new EmployeeInfo() { FirstName = "Bush", ID = 98, LastName = "Bill", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 23 });
227+
list.Add(new EmployeeInfo() { FirstName = "Hayes", ID = 32, LastName = "William", Title = "Production Technician", Salary = 40000, ReportsTo = 23 });
228+
list.Add(new EmployeeInfo() { FirstName = "Madison", ID = 12, LastName = "Franklin", Title = "Stocker", Salary = 50000, ReportsTo = 23 });
229+
list.Add(new EmployeeInfo() { FirstName = "Arthur", ID = 96, LastName = "Grover", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 23 });
230+
}
231+
232+
if (bossID == 18)
233+
{
234+
list.Add(new EmployeeInfo() { FirstName = "Adams", ID = 71, LastName = "Reagan", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 18 });
235+
list.Add(new EmployeeInfo() { FirstName = "Nixon", ID = 92, LastName = "Tyler", Title = "Production Technician", Salary = 40000, ReportsTo = 18 });
236+
list.Add(new EmployeeInfo() { FirstName = "Coolidge", ID = 43, LastName = "Polk", Title = "Design Engineer", Salary = 50000, ReportsTo = 18 });
237+
list.Add(new EmployeeInfo() { FirstName = "George", ID = 84, LastName = "Harrison", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 18 });
238+
}
239+
240+
if (bossID == 68)
241+
{
242+
list.Add(new EmployeeInfo() { FirstName = "Madison", ID = 125, LastName = "Bill", Title = "Marketing Specialist", Salary = 100000, ReportsTo = 68 });
243+
list.Add(new EmployeeInfo() { FirstName = "Nixon", ID = 226, LastName = "Wilson", Title = "Senior Tool Designer", Salary = 100000, ReportsTo = 68 });
244+
list.Add(new EmployeeInfo() { FirstName = "Taft", ID = 253, LastName = "Franklin", Title = "Stocker", Salary = 50000, ReportsTo = 68 });
245+
list.Add(new EmployeeInfo() { FirstName = "Harry", ID = 618, LastName = "Coolidge", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 68 });
246+
}
247+
248+
if (bossID == 24)
249+
{
250+
list.Add(new EmployeeInfo() { FirstName = "Franklin", ID = 244, LastName = "Madison", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 24 });
251+
list.Add(new EmployeeInfo() { FirstName = "William", ID = 166, LastName = "Nixon", Title = "Production Technician", Salary = 40000, ReportsTo = 24 });
252+
list.Add(new EmployeeInfo() { FirstName = "Grover", ID = 355, LastName = "Taft", Title = "Stocker", Salary = 50000, ReportsTo = 24 });
253+
list.Add(new EmployeeInfo() { FirstName = "Bill", ID = 148, LastName = "Harry", Title = "Production Superviser", Salary = 50000, ReportsTo = 24 });
254+
}
255+
256+
if (bossID == 66)
257+
{
258+
list.Add(new EmployeeInfo() { FirstName = "Stogner", ID = 64, LastName = "Martin", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 66 });
259+
list.Add(new EmployeeInfo() { FirstName = "Wilson", ID = 67, LastName = "Harry", Title = "Production Technician", Salary = 40000, ReportsTo = 66 });
260+
list.Add(new EmployeeInfo() { FirstName = "Harrison", ID = 59, LastName = "Will", Title = "Stocker", Salary = 50000, ReportsTo = 66 });
261+
list.Add(new EmployeeInfo() { FirstName = "Jimmy", ID = 08, LastName = "Grover", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 66 });
262+
}
263+
264+
if (bossID == 35)
265+
{
266+
list.Add(new EmployeeInfo() { FirstName = "Franklin", ID = 417, LastName = "William", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 35 });
267+
list.Add(new EmployeeInfo() { FirstName = "Taft", ID = 522, LastName = "Peter", Title = "Production Technician", Salary = 40000, ReportsTo = 35 });
268+
list.Add(new EmployeeInfo() { FirstName = "Harry", ID = 341, LastName = "Wilson", Title = "Stocker", Salary = 50000, ReportsTo = 35 });
269+
list.Add(new EmployeeInfo() { FirstName = "Grover", ID = 141, LastName = "John", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 35 });
270+
}
271+
272+
if (bossID == 64)
273+
{
274+
list.Add(new EmployeeInfo() { FirstName = "Andrew", ID = 141, LastName = "Wilson", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 64 });
275+
list.Add(new EmployeeInfo() { FirstName = "Will", ID = 244, LastName = "Madison", Title = "Production Technician", Salary = 40000, ReportsTo = 64 });
276+
list.Add(new EmployeeInfo() { FirstName = "Harrison", ID = 343, LastName = "Taft", Title = "Stocker", Salary = 50000, ReportsTo = 64 });
277+
list.Add(new EmployeeInfo() { FirstName = "Jimmy", ID = 544, LastName = "Harry", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 64 });
278+
}
279+
280+
if (bossID == 67)
281+
{
282+
list.Add(new EmployeeInfo() { FirstName = "Bush", ID = 98, LastName = "Bill", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 67 });
283+
list.Add(new EmployeeInfo() { FirstName = "Hayes", ID = 32, LastName = "William", Title = "Production Technician", Salary = 40000, ReportsTo = 67 });
284+
list.Add(new EmployeeInfo() { FirstName = "Madison", ID = 12, LastName = "Franklin", Title = "Stocker", Salary = 50000, ReportsTo = 67 });
285+
list.Add(new EmployeeInfo() { FirstName = "Arthur", ID = 96, LastName = "Grover", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 67 });
286+
}
287+
288+
if (bossID == 59)
289+
{
290+
list.Add(new EmployeeInfo() { FirstName = "Adams", ID = 711, LastName = "Reagan", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 59 });
291+
list.Add(new EmployeeInfo() { FirstName = "Nixon", ID = 192, LastName = "Tyler", Title = "Production Technician", Salary = 40000, ReportsTo = 59 });
292+
list.Add(new EmployeeInfo() { FirstName = "Coolidge", ID = 413, LastName = "Polk", Title = "Design Engineer", Salary = 50000, ReportsTo = 59 });
293+
list.Add(new EmployeeInfo() { FirstName = "George", ID = 841, LastName = "Harrison", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 59 });
294+
}
295+
296+
if (bossID == 8)
297+
{
298+
list.Add(new EmployeeInfo() { FirstName = "William", ID = 71, LastName = "Bush", Title = "Quality Assurance Supervisor", Salary = 40000, ReportsTo = 8 });
299+
list.Add(new EmployeeInfo() { FirstName = "Harry", ID = 92, LastName = "Tyler", Title = "Production Technician", Salary = 40000, ReportsTo = 8 });
300+
list.Add(new EmployeeInfo() { FirstName = "Arthur", ID = 43, LastName = "Polk", Title = "Design Engineer", Salary = 50000, ReportsTo = 8 });
301+
list.Add(new EmployeeInfo() { FirstName = "George", ID = 84, LastName = "Harrison", Title = "Maintainence Superviser", Salary = 50000, ReportsTo = 8 });
302+
}
303+
304+
return list;
305+
}
306+
}
307+
```

0 commit comments

Comments
 (0)