From 05395371a50a86600ca82f5a22afcc4f92aae377 Mon Sep 17 00:00:00 2001 From: ponselvajeganathan Date: Mon, 26 Feb 2024 15:11:23 +0530 Subject: [PATCH 1/5] Update changes --- .../ClientApp/src/app/app.component.ts | 4 +- .../Controllers/HomeController.cs | 111 ++++++++++-------- .../SyncfusionAngularASPNETMVC.csproj | 1 - 3 files changed, 67 insertions(+), 49 deletions(-) diff --git a/ExpandStateMapping/ClientApp/src/app/app.component.ts b/ExpandStateMapping/ClientApp/src/app/app.component.ts index c337661..1c121f4 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: 12,pageSizeMode:'Root' }; } diff --git a/ExpandStateMapping/Controllers/HomeController.cs b/ExpandStateMapping/Controllers/HomeController.cs index 3a6d8af..0571f3d 100644 --- a/ExpandStateMapping/Controllers/HomeController.cs +++ b/ExpandStateMapping/Controllers/HomeController.cs @@ -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,53 @@ 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) + //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) - { - DeepChildRecords.Add(rec as TreeData); - } - } - if (dm.Search != null && dm.Search.Count > 0) // searching the child records + IEnumerable ChildSort = DeepChildRecords; + ChildSort = operation.PerformSorting(ChildSort, dm.Sorted); + DeepChildRecords = new List(); + foreach (var rec in ChildSort) { - IEnumerable ChildSearch = DeepChildRecords; - ChildSearch = operation.PerformSearching(ChildSearch, dm.Search); - DeepChildRecords = new List(); - foreach (var rec in ChildSearch) - { - DeepChildRecords.Add(rec as TreeData); - } + 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; + } + //else + //{ + // Child.isParent = true; + // index += DeepChildRecords.Count; + //} } + //} + //else + //{ + // Child.isParent = false; + //} } } } @@ -255,26 +272,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"; 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 - From 4afd9e7ca61549c0bd8b1a78ab0c195817908e34 Mon Sep 17 00:00:00 2001 From: ponselvajeganathan <68591831+ponselvajeganathan@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:17:30 +0530 Subject: [PATCH 2/5] Update controller --- .../Controllers/HomeController.cs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/ExpandStateMapping/Controllers/HomeController.cs b/ExpandStateMapping/Controllers/HomeController.cs index 0571f3d..54e8a0b 100644 --- a/ExpandStateMapping/Controllers/HomeController.cs +++ b/ExpandStateMapping/Controllers/HomeController.cs @@ -132,8 +132,7 @@ public ActionResult DataSource(DataManagerRequest dm) DataOperations operation = new DataOperations(); foreach (var Child in ChildRecords) { - //if (ParentValue.IsExpanded) - //{ + string ParentId = Child.ParentValue.ToString(); if (TaskId == ParentId) { @@ -168,18 +167,8 @@ public ActionResult DataSource(DataManagerRequest dm) { index += DeepChildRecords.Count; } - //else - //{ - // Child.isParent = true; - // index += DeepChildRecords.Count; - //} } - //} - //else - //{ - // Child.isParent = false; - //} - } + } } } @@ -310,4 +299,4 @@ public static List GetTree() } } -} \ No newline at end of file +} From e38b27e2adbe5f3cdcae534b944ea47d475c190a Mon Sep 17 00:00:00 2001 From: ponselvajeganathan <68591831+ponselvajeganathan@users.noreply.github.com> Date: Mon, 26 Feb 2024 16:16:51 +0530 Subject: [PATCH 3/5] Update app.module.ts --- ExpandStateMapping/ClientApp/src/app/app.module.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 { } From 4910edbfec23782086fd1d086013da952c8a0d5a Mon Sep 17 00:00:00 2001 From: ponselvajeganathan <68591831+ponselvajeganathan@users.noreply.github.com> Date: Mon, 26 Feb 2024 17:20:25 +0530 Subject: [PATCH 4/5] Update HomeController.cs --- ExpandStateMapping/Controllers/HomeController.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ExpandStateMapping/Controllers/HomeController.cs b/ExpandStateMapping/Controllers/HomeController.cs index 54e8a0b..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; @@ -132,7 +132,6 @@ public ActionResult DataSource(DataManagerRequest dm) DataOperations operation = new DataOperations(); foreach (var Child in ChildRecords) { - string ParentId = Child.ParentValue.ToString(); if (TaskId == ParentId) { @@ -167,8 +166,9 @@ public ActionResult DataSource(DataManagerRequest dm) { index += DeepChildRecords.Count; } - } - } + } + + } } } From cde12976add82eff3579ad375d1c45ea558f5122 Mon Sep 17 00:00:00 2001 From: ponselvajeganathan <68591831+ponselvajeganathan@users.noreply.github.com> Date: Wed, 28 Feb 2024 11:50:37 +0530 Subject: [PATCH 5/5] Update app.component.ts --- ExpandStateMapping/ClientApp/src/app/app.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ExpandStateMapping/ClientApp/src/app/app.component.ts b/ExpandStateMapping/ClientApp/src/app/app.component.ts index 1c121f4..56d23bb 100644 --- a/ExpandStateMapping/ClientApp/src/app/app.component.ts +++ b/ExpandStateMapping/ClientApp/src/app/app.component.ts @@ -19,5 +19,5 @@ export class AppComponent { adaptor: new UrlAdaptor, url: "Home/Datasource", }); - public pagesettings = { pageSize: 12,pageSizeMode:'Root' }; + public pagesettings = { pageSize: 11,pageSizeMode:'Root' }; }