diff --git a/ExpandStateMapping/ClientApp/src/app/app.component.ts b/ExpandStateMapping/ClientApp/src/app/app.component.ts index c337661..56d23bb 100644 --- a/ExpandStateMapping/ClientApp/src/app/app.component.ts +++ b/ExpandStateMapping/ClientApp/src/app/app.component.ts @@ -4,7 +4,7 @@ import { DataManager, UrlAdaptor } from '@syncfusion/ej2-data'; @Component({ selector: 'app-root', template: ` - + @@ -19,5 +19,5 @@ export class AppComponent { adaptor: new UrlAdaptor, url: "Home/Datasource", }); - + public pagesettings = { pageSize: 11,pageSizeMode:'Root' }; } diff --git a/ExpandStateMapping/ClientApp/src/app/app.module.ts b/ExpandStateMapping/ClientApp/src/app/app.module.ts index dc8f694..a8d06c0 100644 --- a/ExpandStateMapping/ClientApp/src/app/app.module.ts +++ b/ExpandStateMapping/ClientApp/src/app/app.module.ts @@ -3,7 +3,7 @@ import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { GridModule } from '@syncfusion/ej2-angular-grids'; -import { TreeGridModule } from '@syncfusion/ej2-angular-treegrid'; +import { TreeGridModule , PageService } from '@syncfusion/ej2-angular-treegrid'; @NgModule({ declarations: [ @@ -13,7 +13,7 @@ import { TreeGridModule } from '@syncfusion/ej2-angular-treegrid'; BrowserModule, GridModule, TreeGridModule ], - providers: [], + providers: [ PageService], bootstrap: [AppComponent] }) export class AppModule { } diff --git a/ExpandStateMapping/Controllers/HomeController.cs b/ExpandStateMapping/Controllers/HomeController.cs index 3a6d8af..4bb9cce 100644 --- a/ExpandStateMapping/Controllers/HomeController.cs +++ b/ExpandStateMapping/Controllers/HomeController.cs @@ -1,4 +1,4 @@ -using Syncfusion.EJ2.Base; +using Syncfusion.EJ2.Base; using System; using System.Collections; using System.Collections.Generic; @@ -17,18 +17,23 @@ public ActionResult Index() public ActionResult DataSource(DataManagerRequest dm) { List data = new List(); - data = TreeData.GetTree(); + if (data.Count == 0) + { + Session["data1"] = TreeData.GetTree(); + } + data = (List)Session["data1"]; DataOperations operation = new DataOperations(); - IEnumerable DataSource = data; - if (dm.Expand != null && dm.Expand[0] == "CollapsingAction") // setting the ExpandStateMapping property whether is true or false + IEnumerable DataSource = (IEnumerable)Session["data1"]; + List ExpandedParentRecords = new List(); + if (dm.Expand != null && dm.Expand[0] == "ExpandingAction") // setting the ExpandStateMapping property whether is true or false { var val = TreeData.GetTree().Where(ds => ds.TaskID == int.Parse(dm.Expand[1])).FirstOrDefault(); - val.IsExpanded = false; + val.IsExpanded = true; } - else if (dm.Expand != null && dm.Expand[0] == "ExpandingAction") + else if (dm.Expand != null && dm.Expand[0] == "CollapsingAction") { var val = TreeData.GetTree().Where(ds => ds.TaskID == int.Parse(dm.Expand[1])).FirstOrDefault(); - val.IsExpanded = true; + val.IsExpanded = false; } if (!(dm.Where != null && dm.Where.Count > 1)) { @@ -50,16 +55,21 @@ public ActionResult DataSource(DataManagerRequest dm) data = new List(); foreach (var rec in DataSource) { + //Here retained the expanded and collapsed state of parent rows + if (rec.IsExpanded) + { + ExpandedParentRecords.Add(rec as TreeData); // saving the expanded parent records + } data.Add(rec as TreeData); } var GroupData = TreeData.GetTree().ToList().GroupBy(rec => rec.ParentValue) .Where(g => g.Key != null).ToDictionary(g => g.Key?.ToString(), g => g.ToList()); - foreach (var Record in data.ToList()) + if (ExpandedParentRecords.Count > 0) { - if (GroupData.ContainsKey(Record.TaskID.ToString())) + foreach (var Record in ExpandedParentRecords.ToList()) { var ChildGroup = GroupData[Record.TaskID.ToString()]; - if (dm.Sorted != null && dm.Sorted.Count > 0 && dm.Sorted[0].Name != null) // Sorting the child records + if (dm.Sorted != null && dm.Sorted.Count > 0 && dm.Sorted[0].Name != null) // sorting the child records { IEnumerable ChildSort = ChildGroup; ChildSort = operation.PerformSorting(ChildSort, dm.Sorted); @@ -69,7 +79,7 @@ public ActionResult DataSource(DataManagerRequest dm) ChildGroup.Add(rec as TreeData); } } - if (dm.Search != null && dm.Search.Count > 0) // Searching the child records + if (dm.Search != null && dm.Search.Count > 0) // searching the child records { IEnumerable ChildSearch = ChildGroup; ChildSearch = operation.PerformSearching(ChildSearch, dm.Search); @@ -79,8 +89,7 @@ public ActionResult DataSource(DataManagerRequest dm) ChildGroup.Add(rec as TreeData); } } - if (ChildGroup?.Count > 0) - AppendChildren(dm, ChildGroup, Record, GroupData, data); + AppendChildren(dm, ChildGroup, Record, GroupData, data); } } DataSource = data; @@ -123,45 +132,42 @@ public ActionResult DataSource(DataManagerRequest dm) DataOperations operation = new DataOperations(); foreach (var Child in ChildRecords) { - //Based on the provided condition, the child records are retained and the value is passed from the server to the client. - if (ParentValue.IsExpanded) + string ParentId = Child.ParentValue.ToString(); + if (TaskId == ParentId) { - string ParentId = Child.ParentValue.ToString(); - if (TaskId == ParentId) + ((IList)data).Insert(++index, Child); + if (GroupData.ContainsKey(Child.TaskID.ToString())) { - ((IList)data).Insert(++index, Child); - if (GroupData.ContainsKey(Child.TaskID.ToString())) + var DeepChildRecords = GroupData[Child.TaskID.ToString()]; + if (DeepChildRecords?.Count > 0) { - var DeepChildRecords = GroupData[Child.TaskID.ToString()]; - if (DeepChildRecords?.Count > 0) + if (dm.Sorted != null && dm.Sorted.Count > 0 && dm.Sorted[0].Name != null) // sorting the child records { - if (dm.Sorted != null && dm.Sorted.Count > 0 && dm.Sorted[0].Name != null) // sorting the child records + IEnumerable ChildSort = DeepChildRecords; + ChildSort = operation.PerformSorting(ChildSort, dm.Sorted); + DeepChildRecords = new List(); + foreach (var rec in ChildSort) { - IEnumerable ChildSort = DeepChildRecords; - ChildSort = operation.PerformSorting(ChildSort, dm.Sorted); - DeepChildRecords = new List(); - foreach (var rec in ChildSort) - { - DeepChildRecords.Add(rec as TreeData); - } + DeepChildRecords.Add(rec as TreeData); } - if (dm.Search != null && dm.Search.Count > 0) // searching the child records - { - IEnumerable ChildSearch = DeepChildRecords; - ChildSearch = operation.PerformSearching(ChildSearch, dm.Search); - DeepChildRecords = new List(); - foreach (var rec in ChildSearch) - { - DeepChildRecords.Add(rec as TreeData); - } - } - AppendChildren(dm, DeepChildRecords, Child, GroupData, data); - if (Child.IsExpanded) + } + if (dm.Search != null && dm.Search.Count > 0) // searching the child records + { + IEnumerable ChildSearch = DeepChildRecords; + ChildSearch = operation.PerformSearching(ChildSearch, dm.Search); + DeepChildRecords = new List(); + foreach (var rec in ChildSearch) { - index += DeepChildRecords.Count; + DeepChildRecords.Add(rec as TreeData); } } - } + AppendChildren(dm, DeepChildRecords, Child, GroupData, data); + if (Child.IsExpanded) + { + index += DeepChildRecords.Count; + } + } + } } } @@ -255,26 +261,28 @@ public static List GetTree() if (tree.Count == 0) { int root = 0; - for (var t = 1; t <= 5; t++) + for (var t = 1; t <=3; t++) { Random ran = new Random(); string math = (ran.Next() % 3) == 0 ? "High" : (ran.Next() % 2) == 0 ? "Release Breaker" : "Critical"; string progr = (ran.Next() % 3) == 0 ? "Started" : (ran.Next() % 2) == 0 ? "Open" : "In Progress"; root++; int rootItem = root; + + bool flags = t == 1 ? false : true; tree.Add(new TreeData() { TaskID = rootItem, TaskName = "Parent task " + rootItem.ToString(), isParent = true, IsExpanded = true, ParentValue = null, Duration = ran.Next(1, 50) }); int parent = root; - for (var d = 0; d < 3; d++) + for (var d = 0; d < 2; d++) { root++; string value = ((parent + 1) % 3 == 0) ? "Low" : "Critical"; int par = parent + 1; progr = (ran.Next() % 3) == 0 ? "In Progress" : (ran.Next() % 2) == 0 ? "Open" : "Validated"; int iD = root; - bool flag= (ran.Next() % 2) == 0 ? false : true; - tree.Add(new TreeData() { TaskID = iD, TaskName = "Child task " + iD.ToString(), isParent = true, IsExpanded = true, ParentValue = rootItem, Duration = ran.Next(1, 50) }); + bool flag= iD == 9 ? true : false; + tree.Add(new TreeData() { TaskID = iD, TaskName = "Child task " + iD.ToString(), isParent = true, IsExpanded = flag, ParentValue = rootItem, Duration = ran.Next(1, 50) }); int subparent = root; - for (var c = 0; c < 3; c++) + for (var c = 0; c <2; c++) { root++; string val = ((subparent + c + 1) % 3 == 0) ? "Low" : "Critical"; @@ -291,4 +299,4 @@ public static List GetTree() } } -} \ No newline at end of file +} diff --git a/ExpandStateMapping/SyncfusionAngularASPNETMVC.csproj b/ExpandStateMapping/SyncfusionAngularASPNETMVC.csproj index 0439ead..3b47013 100644 --- a/ExpandStateMapping/SyncfusionAngularASPNETMVC.csproj +++ b/ExpandStateMapping/SyncfusionAngularASPNETMVC.csproj @@ -131,7 +131,6 @@ Global.asax -