Available in the Full Version
Tree Grid - Editing
This sample demonstrates how to enable the Updating feature in igTreeGrid.
This sample uses CTP (Community Technical Preview) features. The API and behavior may change when these features are released with full support.
ID | First Name | Last Name | Title | Hire Date |
---|---|---|---|---|
Add new row | ||||
381 | Oswaldo | Lubowitz | Director of Legal Counsel | 2/11/2006 |
386 | Adolphus | Braun | Associate Attorney | 11/29/2007 |
387 | Kaylee | Zieme | Contract Specialist Attorney | 12/27/2011 |
392 | Virginia | Lemke | Paralegal | 1/28/2008 |
388 | Earnestine | Roberts | Contract Specialist Attorney | 1/14/2004 |
394 | Guillermo | Goyette | Paralegal | 1/13/2004 |
382 | Rosalia | Reinger | Patent Attorney | 2/17/2013 |
384 | Edgardo | Bartell | Associate Attorney | 11/7/2012 |
397 | Brain | Konopelski | Paralegal | 12/18/2003 |
383 | Jerrod | Greenholt | Patent Attorney | 1/13/2011 |
398 | Mohamed | Krajcik | Paralegal | 2/19/2007 |
385 | Tanya | Kautzer | Associate Attorney | 11/3/2009 |
399 | Reid | Hintz | Paralegal | 2/23/2013 |
393 | Delphine | Konopelski | Paralegal | 12/30/2011 |
101 | Ansley | Botsford | Vice President of Product Development | 10/19/2012 |
115 | Ron | Bauch | Special Projects Lead | 10/7/2008 |
116 | Kamille | Windler | Senior Software Developer | 10/14/2008 |
118 | Henri | Greenfelder | Junior Software Developer | 2/27/2008 |
119 | Joshuah | Herman | Junior Software Developer | 10/30/2009 |
120 | Glenna | Von | Senior Software Developer | 11/17/2006 |
117 | Wilton | Heidenreich | Senior Software Developer | 11/20/2006 |
121 | Ebba | Adams | Special Projects Lead | 2/1/2012 |
122 | Triston | Will | Senior Software Developer | 10/30/2008 |
123 | Hubert | Leannon | Senior Software Developer | 11/21/2010 |
124 | Isabell | Schinner | Junior Software Developer | 1/3/2004 |
125 | Norene | Jacobi | Junior Software Developer | 10/17/2009 |
126 | Misael | Bernhard | Senior Software Developer | 10/27/2004 |
127 | Christophe | Douglas | Junior Software Developer | 1/17/2010 |
128 | Liana | McLaughlin | Junior Software Developer | 11/22/2011 |
129 | Queenie | Marks | Senior Software Developer | 12/7/2007 |
130 | Tito | Prosacco | Test Specialist | 11/25/2006 |
131 | Alexis | Renner | Test Specialist | 11/7/2013 |
132 | Natalia | Lindgren | Test Specialist | 1/27/2012 |
133 | Hailee | D'Amore | Test Specialist | 12/16/2003 |
166 | Israel | Connelly | Special Projects Lead | 11/22/2013 |
172 | Deshawn | Shanahan | Special Projects Lead | 1/21/2013 |
167 | Ottis | Howell | Senior Software Developer | 11/23/2007 |
181 | Landen | Larkin | Test Specialist | 2/14/2011 |
182 | Percy | Jacobson | Test Specialist | 11/25/2009 |
168 | Demarcus | Cruickshank | Senior Software Developer | 2/25/2005 |
169 | Karelle | Rippin | Junior Software Developer | 12/29/2004 |
170 | Luther | Hilpert | Junior Software Developer | 2/25/2014 |
171 | Alba | Farrell | Senior Software Developer | 10/16/2012 |
208 | Jordan | Nienow | Special Projects Lead | 1/23/2012 |
209 | Wilber | Powlowski | Senior Software Developer | 1/14/2009 |
210 | Allene | Wintheiser | Senior Software Developer | 1/19/2007 |
211 | Ulises | Langworth | Junior Software Developer | 12/19/2008 |
214 | Isaac | Corkery | Special Projects Lead | 11/15/2013 |
216 | Moses | Wolf | Senior Software Developer | 1/6/2008 |
217 | Duane | Berge | Junior Software Developer | 12/21/2006 |
218 | Mona | Cartwright | Junior Software Developer | 12/11/2009 |
219 | Eric | Grant | Senior Software Developer | 2/13/2014 |
220 | Brigitte | Okuneva | Junior Software Developer | 11/17/2006 |
221 | Chris | Oberbrunner | Junior Software Developer | 12/12/2011 |
222 | Jarred | Schuppe | Senior Software Developer | 1/27/2008 |
223 | Tracy | Goyette | Project Manager | 12/6/2011 |
102 | Maeve | Hermann | Chief Technical Officer | 12/15/2010 |
112 | Edyth | Bogisich | Administrative Assistant | 11/13/2010 |
103 | Katrine | Nader | Chief Operating Officer | 10/9/2013 |
104 | Howard | McDermott | Facilities Engineer | 11/14/2012 |
134 | Samson | DuBuque | Director of Research and Development | 11/29/2009 |
142 | Trey | Kessler | Senior Software Developer | 12/11/2003 |
143 | Emilio | Koss | Junior Software Developer | 11/25/2013 |
144 | Orin | Sawayn | Senior Software Developer | 1/5/2009 |
146 | Jefferey | White | Test Specialist | 10/28/2009 |
147 | Henriette | Pollich | Test Specialist | 3/2/2013 |
145 | Morton | Sipes | Junior Software Developer | 10/18/2008 |
148 | Shawn | Lowe | Test Specialist | 12/23/2006 |
149 | Dexter | Hyatt | Test Specialist | 1/22/2004 |
135 | Kailey | Macejkovic | Administrative Assistant | 10/24/2006 |
136 | Lela | Sanford | Project Team Lead | 10/25/2010 |
137 | Lilla | Nicolas | Senior Software Developer | 10/30/2009 |
138 | Marge | Rath | Senior Software Developer | 2/24/2014 |
139 | Kaitlyn | Harris | Senior Software Developer | 12/24/2003 |
140 | Mackenzie | Ullrich | Junior Software Developer | 2/6/2010 |
141 | Grover | Schmitt | Junior Software Developer | 12/18/2009 |
150 | Katelyn | Gibson | Test Specialist | 11/9/2004 |
185 | Oliver | Conn | Warehouse Manager | 1/29/2008 |
186 | Martine | Bednar | Shipping Lead | 1/3/2007 |
187 | Madeline | Stark | Shipping Specialist | 2/15/2007 |
188 | Tatyana | Cummerata | Shipping Specialist | 2/20/2013 |
189 | Reymundo | O'Connell | Shipping Specialist | 10/22/2004 |
190 | Tiara | Bednar | Shipping Specialist | 2/12/2008 |
191 | Lindsey | Wilderman | Shipping Specialist | 2/23/2006 |
192 | Kamryn | Bradtke | Shipping Specialist | 2/20/2008 |
193 | Franco | Kuhic | Shipping Specialist | 11/4/2003 |
194 | Viva | D'Amore | Shipping Specialist | 2/28/2008 |
195 | Jovan | Pagac | Shipping Specialist | 12/5/2003 |
196 | Grant | Yost | Shipping Specialist | 10/10/2004 |
197 | Leonard | Lakin | Shipping Specialist | 10/12/2009 |
198 | Oswaldo | Kuvalis | Shipping Specialist | 2/22/2007 |
199 | Hortense | Stark | Shipping Specialist | 12/22/2008 |
200 | Gabriel | Stracke | Shipping Specialist | 2/12/2012 |
201 | Ernestine | Kutch | Delivery Lead | 1/25/2006 |
202 | Lizeth | Fritsch | Delivery Specialist | 12/18/2013 |
203 | Vincenzo | Prosacco | Delivery Specialist | 1/28/2010 |
204 | Elnora | Hamill | Delivery Specialist | 3/2/2008 |
205 | Max | Prohaska | Delivery Specialist | 11/22/2009 |
273 | Brisa | Hamill | Director of Quality Assurance | 1/4/2007 |
274 | Hassan | Reichel | Administrative Assistant | 12/5/2004 |
275 | Virgil | Bechtelar | Quality Assurance Technician | 10/22/2008 |
276 | Adolph | Bins | Quality Assurance Technician | 1/20/2009 |
277 | Orpha | Swaniawski | Quality Assurance Technician | 1/5/2011 |
278 | Kellen | Krajcik | Quality Assurance Technician | 1/23/2006 |
279 | Freddy | Rowe | Quality Assurance Technician | 12/31/2013 |
280 | Robin | Hagenes | Quality Assurance Technician | 10/14/2012 |
281 | Timothy | Kutch | Quality Assurance Technician | 2/27/2005 |
282 | Isac | Stokes | Quality Assurance Technician | 2/15/2011 |
283 | Mervin | Waelchi | Quality Assurance Technician | 11/22/2006 |
284 | Vivianne | Hoeger | Director of Human Resources | 12/15/2010 |
285 | Allen | Heidenreich | HR Specialist | 12/13/2006 |
286 | Lou | Klocko | HR Specialist | 10/28/2003 |
287 | Darby | Hickle | HR Specialist | 12/3/2004 |
288 | Catharine | Streich | HR Specialist | 12/13/2003 |
289 | Mia | Toy | HR Specialist | 11/8/2005 |
290 | Eldridge | Kihn | HR Specialist | 12/23/2005 |
291 | Benedict | Dicki | HR Specialist | 11/6/2009 |
292 | Michaela | Ward | HR Specialist | 12/4/2013 |
293 | Nels | Simonis | HR Specialist | 11/18/2011 |
294 | April | Kohler | Call Center Manager | 11/8/2010 |
295 | Holly | Lemke | Call Center Team Lead | 12/23/2004 |
296 | Cletus | Wilderman | Customer Support Specialist | 1/23/2004 |
297 | Michale | Sawayn | Customer Support Specialist | 11/2/2004 |
298 | Beryl | Haag | Customer Support Specialist | 11/8/2009 |
299 | Efrain | Huel | Customer Support Specialist | 10/25/2007 |
300 | Rebeca | Emard | Customer Support Specialist | 2/25/2010 |
301 | Felicity | Barton | Customer Support Specialist | 1/18/2013 |
302 | Marilie | Morar | Customer Support Specialist | 10/14/2003 |
303 | Harry | Lubowitz | Customer Support Specialist | 11/27/2003 |
304 | Rosalee | Jenkins | Customer Support Specialist | 11/14/2009 |
305 | Mckenna | Powlowski | Customer Support Specialist | 1/29/2010 |
306 | Norval | Kozey | Customer Support Specialist | 1/19/2009 |
307 | Jamison | Howe | Customer Support Specialist | 11/20/2006 |
308 | Conrad | Rippin | Customer Support Specialist | 2/25/2009 |
309 | Paolo | Larkin | Customer Support Specialist | 11/23/2003 |
310 | Berneice | Tillman | Customer Support Specialist | 10/7/2003 |
311 | Rosemarie | Kuphal | Customer Support Specialist | 12/19/2010 |
312 | Uriah | Kuvalis | Customer Support Specialist | 2/7/2008 |
110 | Kayden | Will | Administrative Assistant | 1/16/2009 |
105 | Krystal | White | Chief Financial Officer | 12/23/2011 |
106 | Brice | Stark | Controller | 2/17/2009 |
107 | Kayley | Williams | Accountant | 1/13/2011 |
108 | Ruby | Casper | Accountant | 11/6/2003 |
114 | Lawrence | Prosacco | Administrative Assistant | 1/15/2004 |
109 | Breana | Ankunding | Accountant | 2/25/2007 |
113 | Herta | Stanton | Administrative Assistant | 1/9/2005 |
226 | Juliet | Ritchie | Chief Marketing Officer | 2/4/2008 |
227 | Ralph | Jacobson | Enterprise Sales Lead | 10/21/2005 |
228 | Ted | Schultz | Sales Associate | 1/22/2007 |
260 | Gwendolyn | Wolff | Director of Marketing | 11/13/2004 |
261 | Leila | Wintheiser | Web Marketing Lead | 11/10/2009 |
This sample is designed for a larger screen size.
On mobile, try rotating your screen, view full size, or email to another device.
The feature allows editing, deleting and adding rows on root and child levels. Hover on a row to see the buttons for deleting a row and adding a child row.
Code View
Copy to Clipboard
@using Infragistics.Web.Mvc @using IgniteUI.SamplesBrowser.Models.Northwind @using System.Data @model Infragistics.Web.Mvc.TreeGridModel <!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" /> <link href="http://cdn-na.infragistics.com/igniteui/2024.2/latest/css/structure/modules/infragistics.ui.treegrid.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> <!-- Used to add modal loading indicator for igTreeGrid --> <script src="http://igniteui.com/js/grid-modal-loading-inicator.js"></script> <style type="text/css"> input.button-style { margin-top: 10px; } </style> </head> <body> @(Html.Infragistics().TreeGrid<IgniteUI.SamplesBrowser.Models.EmployeeData>() .DataSourceUrl(Url.Action("GetTreeGridData")) .Width("100%") .Height("600px") .ID("TreeGrid") .AutoGenerateColumns(false) .UpdateUrl(Url.Action("EmployeeSaveData")) .Columns(column => { column.For(x => x.ID).HeaderText("ID").DataType("number").Width("25%"); column.For(x => x.FirstName).HeaderText("First Name").DataType("string").Width("15%"); column.For(x => x.LastName).HeaderText("Last Name").DataType("string").Width("15%"); column.For(x => x.Title).HeaderText("Title").DataType("string").Width("25%"); column.For(x => x.HireDate).HeaderText("Hire Date").DataType("date").Width("20%"); }) .PrimaryKey("ID") .ChildDataKey("Employees") .Features(features => { features.Updating().ColumnSettings(cs => { cs.ColumnSetting().ColumnKey("HireDate").Required(true); }); }) .DataBind() .Render() ) <input type="button" id="saveChanges" class="button-style" value="Save Changes" /> <input type="button" id="undo" class="button-style" value="Undo" /> <input type="button" id="redo" class="button-style" value="Redo" /> <script> var updates, customersLookup = [], loadingIndicator; $(function () { var grid = $("#TreeGrid"); $("#saveChanges").igButton({ labelText: $("#saveChanges").val(), disabled: true }); $("#undo").igButton({ labelText: $("#undo").val(), disabled: true }); $("#redo").igButton({ labelText: $("#redo").val(), disabled: true }); loadingIndicator = new GridModalLoadingIndicator(grid); grid.on("igtreegriddatabinding", function (e, args) { loadingIndicator.show(); }); grid.on("igtreegriddatabound", function (e, args) { loadingIndicator.hide(); }); grid.on("igtreegridupdatingrowdeleted", function (e, args) { $("#undo").igButton("option", "disabled", false); $("#saveChanges").igButton("option", "disabled", false); }); grid.on("igtreegridupdatingrowadded", function (e, args) { $("#undo").igButton("option", "disabled", false); $("#saveChanges").igButton("option", "disabled", false); }); grid.on("igtreegridupdatingeditrowended", function (e, args) { if (args.update) { $("#undo").igButton("option", "disabled", false); $("#saveChanges").igButton("option", "disabled", false); } }); $("#undo").on('igbuttonclick', function (e, args) { updates = $.extend({}, grid.data('igTreeGrid').pendingTransactions()); $.each(updates, function (index, transaction) { grid.igTreeGrid("rollback", transaction.rowId, true); }); $("#redo").igButton("option", "disabled", false); $("#undo").igButton("disable"); $("#saveChanges").igButton("disable"); return false; } ); $("#redo").on('igbuttonclick', function (e) { $.each(updates, function (index, transaction) { switch (transaction.type) { case "row": grid.igTreeGridUpdating('updateRow', transaction.rowId, transaction.row, null, false); break; case "newrow": grid.igTreeGridUpdating('addRow', transaction.row, false); break; case "deleterow": grid.igTreeGridUpdating('deleteRow', transaction.rowId, false); break; case "insertnode": grid.igTreeGridUpdating('addChild', transaction.row, transaction.parentRowId, false); break; } }); $(this).igButton("disable"); $("#undo").igButton("option", "disabled", false); $("#saveChanges").igButton("option", "disabled", false); } ); $("#saveChanges").on('igbuttonclick', function (e) { grid.igTreeGrid("saveChanges", function saveSuccess() { loadingIndicator.hide(); }); loadingIndicator.show(); $("#undo").igButton("disable"); $(this).igButton("disable"); return false; } ); grid.on("igtreegridupdatingdatadirty", function (event, ui) { grid.igTreeGrid("commit"); //saving local changes to the datasource when sorting return false; }); }); </script> </body> </html>
using IgniteUI.SamplesBrowser.Models; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Infragistics.Web.Mvc; using IgniteUI.SamplesBrowser.Models.Repositories; using IgniteUI.SamplesBrowser.Models.Northwind; using System.Linq.Expressions; using System.Text.RegularExpressions; using System.Text; namespace IgniteUI.SamplesBrowser.Controllers { public class TreeGridController : Controller { // // GET: /TreeGrid/ [ActionName("aspnet-mvc-helper")] public ActionResult AspMvcHelper() { var files = new List<FileExplorer>(); files.Add(new FileExplorer { ID = "1", Name = "Documents", DateModified = new DateTime(2013, 9, 12), Type = "File Folder", Size = 4480, Files = new List<FileExplorer> { new FileExplorer { ID = "4", Name = "To do list.txt", DateModified = new DateTime(2013,11,30), Type = "TXT File", Size = 4448 }, new FileExplorer { ID = "5", Name = "To do list.txt", DateModified = new DateTime(11/30/2013), Type = "TXT File", Size = 4448 } } }); files.Add(new FileExplorer { ID = "2", Name = "Music", DateModified = new DateTime(2014, 6, 10), Type = "File Folder", Size = 5594, Files = new List<FileExplorer> { new FileExplorer { ID = "6", Name = "AC/DC", DateModified =new DateTime(2014,6,10), Type = "File Folder", Size = 2726 , Files = new List<FileExplorer> { new FileExplorer { ID = "8", Name = "Stand Up.mp3", DateModified = new DateTime(2014,6,10), Type = "MP3 File", Size = 456 }, new FileExplorer { ID = "9", Name = "T.N.T.mp3", DateModified = new DateTime(2014,6,10), Type = "MP3 File", Size = 1155 }, new FileExplorer { ID = "10", Name = "The Jack.mp3", DateModified = new DateTime(2014,6,10), Type = "MP3 File", Size = 1115 } } }, new FileExplorer { ID = "7", Name = "WhiteSnake", DateModified = new DateTime(2014,6,11), Type = "File Folder", Size = 2868, Files = new List<FileExplorer> { new FileExplorer { ID = "11", Name = "Trouble.mp3", DateModified = new DateTime(2014,6,11), Type = "MP3 File", Size = 1234 }, new FileExplorer { ID = "12", Name = "Bad Boys.mp3", DateModified = new DateTime(2014,6,11), Type = "MP3 File", Size = 522 }, new FileExplorer { ID = "13", Name = "Is This Love.mp3", DateModified = new DateTime(2014,6,11), Type = "MP3 File", Size = 1112 } } } } }); files.Add(new FileExplorer { ID = "3", Name = "Pictures", DateModified = new DateTime(2014, 1, 20), Type = "File Folder", Size = 1825, Files = new List<FileExplorer> { new FileExplorer { ID = "14", Name = "Jack's Birthday", DateModified = new DateTime(2014,6,21), Type = "File Folder", Size = 631, Files = new List<FileExplorer> { new FileExplorer { ID = "16", Name = "Picture1.png", DateModified = new DateTime(2014,6,21), Type = "PNG image", Size = 493 }, new FileExplorer { ID = "17", Name = "Picture2.png", DateModified = new DateTime(2014,6,21), Type = "PNG image", Size = 88 }, new FileExplorer { ID = "18", Name = "Picture3.gif", DateModified = new DateTime(2014,6,21), Type = "GIF File", Size = 50 } } }, new FileExplorer { ID = "15", Name = "Trip to London", DateModified = new DateTime(2014,3,11), Type = "File Folder", Size = 1194, Files = new List<FileExplorer> { new FileExplorer { ID = "19", Name = "Picture1.png", DateModified = new DateTime(2014,3,11), Type = "PNG image", Size = 974 }, new FileExplorer { ID = "20", Name = "Picture2.png", DateModified = new DateTime(2014,3,11), Type = "PNG image", Size = 142 }, new FileExplorer { ID = "21", Name = "Picture3.png", DateModified = new DateTime(2014,3,11), Type = "PNG image", Size = 41 }, new FileExplorer { ID = "22", Name = "Picture4.png", DateModified = new DateTime(2014,3,11), Type = "PNG image", Size = 25 }, new FileExplorer { ID = "23", Name = "Picture5.png", DateModified = new DateTime(2014,3,11), Type = "PNG image", Size = 12 } } } } }); return View("aspnet-mvc-helper", files.AsQueryable()); } [ActionName("load-on-demand")] public ActionResult LoadOnDemand() { return View(); } [ActionName("remote-features")] public ActionResult RemoteFeatures() { return View(); } [ActionName("updating")] public ActionResult Updating() { return View(); } [ActionName("editing-knockout")] [TreeGridDataSourceAction] public ActionResult EditingKnockout() { var employees = OrgChartEmployeesRepository.GetEmployees(); return View(employees.AsQueryable()); } public JsonResult GetDirectors() { var directors = OrgChartEmployeesRepository.GetDirectors(); return Json(directors, JsonRequestBehavior.AllowGet); } #region Data [TreeGridDataSourceAction] public ActionResult ChildEmployeesOnDemand() { IQueryable allData = RepositoryFactory.GetHierarchicalEmployeeData().AsQueryable(); return View("load-on-demand", allData); } [TreeGridDataSourceAction] public ActionResult GetTreeData() { IQueryable allData = RepositoryFactory.GetHierarchicalEmployeeData().AsQueryable(); return View("remote-features", allData); } [TreeGridDataSourceAction] public ActionResult GetTreeGridData() { IQueryable allData = RepositoryFactory.GetTreeGridRepository().Get().AsQueryable(); return View("updating", allData); } #endregion //Data public ActionResult EmployeeSaveData() { TreeGridModel treeGridModel = new TreeGridModel(); List<Transaction<EmployeeData>> transactions = treeGridModel.LoadTransactions<EmployeeData>(HttpContext.Request.Form["ig_transactions"]); var employees = RepositoryFactory.GetTreeGridRepository(); foreach (Transaction<EmployeeData> t in transactions) { if (t.type == "newrow") { employees.Add(t.row); } else if (t.type == "deleterow") { employees.Delete(o => o.ID == Int32.Parse(t.rowId)); } else if (t.type == "row") { var employee = FindElementEmployees(employees.Get(), Int32.Parse(t.rowId)); if (t.row.FirstName != null) { employee.FirstName = t.row.FirstName; } if (t.row.LastName != null) { employee.LastName = t.row.LastName; } if (t.row.Title != null) { employee.Title = t.row.Title; } if (t.row.Email != null) { employee.Email = t.row.Email; } if (t.row.HireDate != null) { employee.HireDate = t.row.HireDate; } employees.Update(employee, o => o.ID == Int32.Parse(t.rowId)); } else if (t.type == "insertnode") { var parentEmployee = FindElementEmployees(employees.Get(), Int32.Parse(t.parentRowId)); if (parentEmployee.Employees == null) { parentEmployee.Employees = new List<EmployeeData>() as IEnumerable<EmployeeData>; } var temp = parentEmployee.Employees.ToList(); temp.Add(t.row); parentEmployee.Employees = temp as IEnumerable<EmployeeData>; } } employees.Save(); JsonResult result = new JsonResult(); Dictionary<string, bool> response = new Dictionary<string, bool>(); response.Add("Success", true); result.Data = response; return result; } private EmployeeData FindElementEmployees(IEnumerable<EmployeeData> data, int id) { EmployeeData employee = null; for (int i = 0; i < data.Count(); i++) { if (employee != null) { break; } employee = GetNode(data.ElementAt(i), id); } return employee; } public static EmployeeData GetNode(EmployeeData parent, int id) { if (parent != null) { if (parent.ID.Equals(id)) { return parent; } } if (parent.Employees != null) foreach (var child in parent.Employees) { if (child.ID.Equals(id)) { return child; } var employee = GetNode(child, id); if (employee != null) { return employee; } } return null; } } }