Example of Show or Hide Column in ASP.NET MVC Tree Grid Control
This sample demonstrates dynamic show/hide columns feature of Tree Grid. Select column name from the properties panel and click hide/show to toggle visibility.
Properties
@Html.UiTreeGrid(new UiTreeGridOptions
{
Id = "ShowHide",
Data = ViewData["datasource"],
Height = "400px",
ChildMapping = "Children",
TreeColumnIndex = 1,
AllowPaging = false,
Selection = UiGridSelection.Single,
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "TaskId", HeaderText = "Task ID", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "TaskName", HeaderText = "Task Name" },
new UiGridColumn { Field = "StartDate", HeaderText = "Start Date", Type = UiColumnType.Date, TextAlign = UiTextAlign.Right, Format = "M/d/yyyy" },
new UiGridColumn { Field = "Duration", HeaderText = "Duration", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "Progress", HeaderText = "Progress", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right }
}
})
@Html.UiTreeGrid(new UiTreeGridOptions
{
Id = "ShowHide",
Data = ViewData["datasource"],
Height = "400px",
ChildMapping = "Children",
TreeColumnIndex = 1,
AllowPaging = false,
Selection = UiGridSelection.Single,
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "TaskId", HeaderText = "Task ID", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "TaskName", HeaderText = "Task Name" },
new UiGridColumn { Field = "StartDate", HeaderText = "Start Date", Type = UiColumnType.Date, TextAlign = UiTextAlign.Right, Format = "M/d/yyyy" },
new UiGridColumn { Field = "Duration", HeaderText = "Duration", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "Progress", HeaderText = "Progress", Type = UiColumnType.Number, TextAlign = UiTextAlign.Right }
}
})
<div class="demo-property-panel">
<h3>Properties</h3>
<div class="demo-property-row"><label for="dropdown">Column</label><select id="dropdown">@foreach (var option in (List<KeyValuePair<string, string>>)ViewData["columns"]) { <option value="@option.Value">@option.Key</option> }</select></div>
<div class="demo-property-row"><button type="button" id="hide">HIDE</button> <button type="button" id="show" disabled>SHOW</button></div>
<div class="demo-property-row"><label for="hiddencolumns">Hidden Columns</label><textarea id="hiddencolumns" rows="3" readonly></textarea></div>
</div>
<script>
var showHideTree = function () { return window.Lumen.get('ShowHide'); };
var hiddenColumns = document.getElementById('hiddencolumns');
var columnOf = function (field) { return showHideTree().getColumns().filter(function (c) { return c.field === field; })[0]; };
document.getElementById('dropdown').value = 'TaskId';
// Syncfusion: HIDE is for a column that is shown, SHOW for one that is hidden.
document.getElementById('dropdown').addEventListener('change', function (e) {
var shown = columnOf(e.target.value).visible;
document.getElementById('show').disabled = shown;
document.getElementById('hide').disabled = !shown;
});
document.getElementById('show').addEventListener('click', function () {
var column = columnOf(document.getElementById('dropdown').value);
showHideTree().showColumns(column.headerText);
document.getElementById('show').disabled = true;
document.getElementById('hide').disabled = false;
hiddenColumns.value = hiddenColumns.value.replace(column.headerText + '\n', '');
});
document.getElementById('hide').addEventListener('click', function () {
var column = columnOf(document.getElementById('dropdown').value);
if (showHideTree().getColumns().filter(function (c) { return !c.visible; }).length === 3) {
window.Lumen.alert({ title: 'Hide column', content: 'Atleast one Column should be visible', okText: 'OK' });
} else {
showHideTree().hideColumns(column.headerText);
document.getElementById('hide').disabled = true;
document.getElementById('show').disabled = false;
hiddenColumns.value = hiddenColumns.value + column.headerText + '\n';
}
});
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TreeGridController : Controller
{
// The page is Views/TreeGrid/ShowOrHideColumn.cshtml; it draws what ViewData holds.
public ActionResult ShowOrHideColumn()
{
var treeData = TreeGridItems.GetTreeData();
ViewData["datasource"] = treeData;
ViewData["columns"] = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("Task ID", "TaskId"),
new KeyValuePair<string, string>("Start Date", "StartDate"),
new KeyValuePair<string, string>("Duration", "Duration"),
new KeyValuePair<string, string>("Progress", "Progress")
};
return View();
}
public class TreeGridItems
{
public TreeGridItems() { }
public int TaskId { get; set; }
public string TaskName { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int Duration { get; set; }
public int Progress { get; set; }
public string Priority { get; set; }
public bool Approved { get; set; }
public DateTime FilterStartDate { get; set; }
public DateTime FilterEndDate { get; set; }
public List<TreeGridItems> Children { get; set; }
public int? ParentId { get; set; }
public static List<TreeGridItems> GetTreeData()
{
List<TreeGridItems> BusinessObjectCollection = new List<TreeGridItems>();
TreeGridItems Record1 = null;
Record1 = new TreeGridItems()
{
TaskId = 1,
TaskName = "Planning",
StartDate = new DateTime(2016, 06, 07),
EndDate = new DateTime(2021, 08, 25),
Progress = 100,
Duration = 5,
Priority = "Normal",
Approved = false,
FilterStartDate = new DateTime(2017, 02, 03),
FilterEndDate = new DateTime(2017, 02, 07),
Children = new List<TreeGridItems>(),
};
TreeGridItems Child1 = new TreeGridItems()
{
TaskId = 2,
TaskName = "Plan timeline",
StartDate = new DateTime(2016, 06, 07),
EndDate = new DateTime(2021, 08, 25),
Progress = 100,
Duration = 5,
Priority = "Normal",
Approved = false,
FilterStartDate = new DateTime(2017, 02, 03),
FilterEndDate = new DateTime(2017, 02, 07),
};
TreeGridItems Child2 = new TreeGridItems()
{
TaskId = 3,
TaskName = "Plan budget",
StartDate = new DateTime(2016, 06, 07),
EndDate = new DateTime(2021, 08, 25),
Duration = 5,
Priority = "Critical",
Progress = 100,
Approved = true,
FilterStartDate = new DateTime(2017, 02, 03),
FilterEndDate = new DateTime(2017, 02, 07),
};
TreeGridItems Child3 = new TreeGridItems()
{
TaskId = 4,
TaskName = "Allocate resources",
StartDate = new DateTime(2016, 06, 07),
EndDate = new DateTime(2021, 08, 25),
Duration = 5,
Progress = 100,
Priority = "Critical",
FilterStartDate = new DateTime(2017, 02, 03),
FilterEndDate = new DateTime(2017, 02, 07),
Approved = false
};
TreeGridItems Child4 = new TreeGridItems()
{
TaskId = 5,
TaskName = "Planning complete",
StartDate = new DateTime(2021, 08, 25),
EndDate = new DateTime(2021, 08, 25),
Duration = 3,
Progress = 25,
Priority = "Low",
FilterStartDate = new DateTime(2017, 02, 07),
FilterEndDate = new DateTime(2017, 02, 07),
Approved = true
};
Record1.Children.Add(Child1);
Record1.Children.Add(Child2);
Record1.Children.Add(Child3);
Record1.Children.Add(Child4);
TreeGridItems Record2 = new TreeGridItems()
{
TaskId = 6,
TaskName = "Design",
StartDate = new DateTime(2021, 08, 25),
EndDate = new DateTime(2024, 06, 27),
Progress = 86,
Duration = 3,
Priority = "High",
FilterStartDate = new DateTime(2017, 02, 10),
FilterEndDate = new DateTime(2017, 02, 14),
Approved = false,
Children = new List<TreeGridItems>(),
};
TreeGridItems Child5 = new TreeGridItems()
{
TaskId = 7,
TaskName = "Software Specification",
StartDate = new DateTime(2021, 08, 25),
EndDate = new DateTime(2024, 06, 27),
Duration = 3,
Progress = 60,
Priority = "Normal",
FilterStartDate = new DateTime(2017, 02, 10),
FilterEndDate = new DateTime(2017, 02, 12),
Approved = false
};
TreeGridItems Child6 = new TreeGridItems()
{
TaskId = 8,
TaskName = "Develop prototype",
StartDate = new DateTime(2021, 08, 25),
EndDate = new DateTime(2024, 06, 27),
Duration = 3,
Progress = 100,
Priority = "Critical",
FilterStartDate = new DateTime(2017, 02, 10),
FilterEndDate = new DateTime(2017, 02, 12),
Approved = false
};
TreeGridItems Child7 = new TreeGridItems()
{
TaskId = 9,
TaskName = "Get approval from customer",
StartDate = new DateTime(2024, 06, 27),
EndDate = new DateTime(2024, 06, 27),
Duration = 2,
Progress = 100,
Approved = true,
Priority = "Critical",
FilterStartDate = new DateTime(2017, 02, 13),
FilterEndDate = new DateTime(2017, 02, 14),
};
TreeGridItems Child8 = new TreeGridItems()
{
TaskId = 10,
TaskName = "Design complete",
StartDate = new DateTime(2024, 06, 27),
EndDate = new DateTime(2024, 06, 27),
Duration = 3,
Progress = 25,
Priority = "Normal",
FilterStartDate = new DateTime(2017, 02, 14),
FilterEndDate = new DateTime(2017, 02, 14),
Approved = true
};
Record2.Children.Add(Child5);
Record2.Children.Add(Child6);
Record2.Children.Add(Child7);
Record2.Children.Add(Child8);
TreeGridItems Record3 = new TreeGridItems()
{
TaskId = 11,
TaskName = "Implementation Phase",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 17),
Priority = "Normal",
Approved = false,
Duration = 11,
Progress = 25,
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 17),
Children = new List<TreeGridItems>(),
};
TreeGridItems Record4 = new TreeGridItems()
{
TaskId = 12,
TaskName = "Phase 1",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 27),
Priority = "High",
Approved = false,
Duration = 11,
Progress = 25,
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 27),
Children = new List<TreeGridItems>(),
};
TreeGridItems Record7 = new TreeGridItems()
{
TaskId = 13,
TaskName = "Implementation Module 1",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 27),
Priority = "Normal",
Duration = 11,
Approved = false,
Progress = 25,
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 27),
Children = new List<TreeGridItems>(),
};
TreeGridItems Child9 = new TreeGridItems()
{
TaskId = 14,
TaskName = "Development Task 1",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 19),
Duration = 3,
Progress = 50,
Priority = "High",
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 19),
Approved = false
};
TreeGridItems Child10 = new TreeGridItems()
{
TaskId = 15,
TaskName = "Development Task 2",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 19),
Duration = 3,
Progress = 50,
Priority = "Low",
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 19),
Approved = true
};
TreeGridItems Child11 = new TreeGridItems()
{
TaskId = 16,
TaskName = "Testing",
StartDate = new DateTime(2017, 02, 20),
EndDate = new DateTime(2017, 02, 21),
Duration = 2,
Progress = 25,
Priority = "Normal",
FilterStartDate = new DateTime(2017, 02, 20),
FilterEndDate = new DateTime(2017, 02, 21),
Approved = true
};
TreeGridItems Child12 = new TreeGridItems()
{
TaskId = 17,
TaskName = "Bug fix",
StartDate = new DateTime(2017, 02, 24),
EndDate = new DateTime(2017, 02, 25),
Duration = 2,
Progress = 25,
Priority = "Critical",
FilterStartDate = new DateTime(2017, 02, 24),
FilterEndDate = new DateTime(2017, 02, 25),
Approved = false
};
TreeGridItems Child13 = new TreeGridItems()
{
TaskId = 18,
TaskName = "Customer review meeting",
StartDate = new DateTime(2017, 02, 26),
EndDate = new DateTime(2017, 02, 27),
Duration = 2,
Progress = 25,
Priority = "High",
FilterStartDate = new DateTime(2017, 02, 26),
FilterEndDate = new DateTime(2017, 02, 27),
Approved = false
};
TreeGridItems Child14 = new TreeGridItems()
{
TaskId = 19,
TaskName = "Phase 1 complete",
StartDate = new DateTime(2017, 02, 27),
EndDate = new DateTime(2017, 02, 27),
Duration = 2,
Progress = 25,
Priority = "Low",
FilterStartDate = new DateTime(2017, 02, 27),
FilterEndDate = new DateTime(2017, 02, 27),
Approved = true
};
Record7.Children.Add(Child9);
Record7.Children.Add(Child10);
Record7.Children.Add(Child11);
Record7.Children.Add(Child12);
Record7.Children.Add(Child13);
Record7.Children.Add(Child14);
Record4.Children.Add(Record7);
Record3.Children.Add(Record4);
TreeGridItems Record5 = new TreeGridItems()
{
TaskId = 20,
TaskName = "Phase 2",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 28),
Children = new List<TreeGridItems>(),
Priority = "High",
Approved = false,
Progress = 25,
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 28),
Duration = 12,
};
TreeGridItems Record8 = new TreeGridItems()
{
TaskId = 21,
TaskName = "Implementation Module 2",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 28),
Priority = "Critical",
Approved = false,
Progress = 25,
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 28),
Duration = 12,
Children = new List<TreeGridItems>(),
};
TreeGridItems Child15 = new TreeGridItems()
{
TaskId = 22,
TaskName = "Development Task 1",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 20),
Duration = 4,
Progress = 50,
Priority = "Normal",
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 20),
Approved = true,
};
TreeGridItems Child16 = new TreeGridItems()
{
TaskId = 23,
TaskName = "Development Task 2",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 20),
Duration = 4,
Progress = 50,
Priority = "Critical",
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 20),
Approved = true,
};
TreeGridItems Child17 = new TreeGridItems()
{
TaskId = 24,
TaskName = "Testing",
StartDate = new DateTime(2017, 02, 21),
EndDate = new DateTime(2017, 02, 24),
Duration = 2,
Progress = 25,
Priority = "High",
FilterStartDate = new DateTime(2017, 02, 21),
FilterEndDate = new DateTime(2017, 02, 24),
Approved = false,
};
TreeGridItems Child18 = new TreeGridItems()
{
TaskId = 25,
TaskName = "Bug fix",
StartDate = new DateTime(2017, 02, 25),
EndDate = new DateTime(2017, 02, 26),
Duration = 2,
Progress = 25,
Priority = "Low",
Approved = false,
FilterStartDate = new DateTime(2017, 02, 25),
FilterEndDate = new DateTime(2017, 02, 26),
};
TreeGridItems Child19 = new TreeGridItems()
{
TaskId = 26,
TaskName = "Customer review meeting",
StartDate = new DateTime(2017, 02, 27),
EndDate = new DateTime(2017, 02, 28),
Duration = 2,
Progress = 25,
Priority = "Critical",
FilterStartDate = new DateTime(2017, 02, 27),
FilterEndDate = new DateTime(2017, 02, 28),
Approved = true,
};
TreeGridItems Child20 = new TreeGridItems()
{
TaskId = 27,
TaskName = "Phase 2 complete",
StartDate = new DateTime(2017, 02, 28),
EndDate = new DateTime(2017, 02, 28),
Duration = 2,
Progress = 25,
Priority = "Normal",
FilterStartDate = new DateTime(2017, 02, 28),
FilterEndDate = new DateTime(2017, 02, 28),
Approved = false,
};
Record8.Children.Add(Child15);
Record8.Children.Add(Child16);
Record8.Children.Add(Child17);
Record8.Children.Add(Child18);
Record8.Children.Add(Child19);
Record8.Children.Add(Child20);
Record5.Children.Add(Record8);
Record3.Children.Add(Record5);
TreeGridItems Record6 = new TreeGridItems()
{
TaskId = 28,
TaskName = "Phase 3",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 27),
Priority = "Normal",
Approved = false,
Progress = 25,
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 27),
Duration = 11,
Children = new List<TreeGridItems>(),
};
TreeGridItems Record9 = new TreeGridItems()
{
TaskId = 29,
TaskName = "Implementation Module 3",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 27),
Priority = "High",
Progress = 25,
Approved = false,
Duration = 11,
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 27),
Children = new List<TreeGridItems>(),
};
TreeGridItems Child21 = new TreeGridItems()
{
TaskId = 30,
TaskName = "Development Task 1",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 19),
Duration = 3,
Progress = 50,
Priority = "Low",
Approved = true,
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 19),
};
TreeGridItems Child22 = new TreeGridItems()
{
TaskId = 31,
TaskName = "Development Task 2",
StartDate = new DateTime(2017, 02, 17),
EndDate = new DateTime(2017, 02, 19),
Duration = 3,
Progress = 50,
Priority = "Normal",
Approved = false,
FilterStartDate = new DateTime(2017, 02, 17),
FilterEndDate = new DateTime(2017, 02, 19),
};
TreeGridItems Child23 = new TreeGridItems()
{
TaskId = 32,
TaskName = "Testing",
StartDate = new DateTime(2017, 02, 20),
EndDate = new DateTime(2017, 02, 21),
Duration = 2,
Progress = 25,
Priority = "Critical",
FilterStartDate = new DateTime(2017, 02, 20),
FilterEndDate = new DateTime(2017, 02, 21),
Approved = true,
};
TreeGridItems Child24 = new TreeGridItems()
{
TaskId = 33,
TaskName = "Bug fix",
StartDate = new DateTime(2017, 02, 24),
EndDate = new DateTime(2017, 02, 25),
Duration = 2,
Progress = 25,
Priority = "High",
Approved = false,
FilterStartDate = new DateTime(2017, 02, 24),
FilterEndDate = new DateTime(2017, 02, 25),
};
TreeGridItems Child25 = new TreeGridItems()
{
TaskId = 34,
TaskName = "Customer review meeting",
StartDate = new DateTime(2017, 02, 26),
EndDate = new DateTime(2017, 02, 27),
Duration = 2,
Progress = 25,
Priority = "Normal",
FilterStartDate = new DateTime(2017, 02, 26),
FilterEndDate = new DateTime(2017, 02, 27),
Approved = true,
};
TreeGridItems Child26 = new TreeGridItems()
{
TaskId = 35,
TaskName = "Phase 3 complete",
StartDate = new DateTime(2017, 02, 27),
EndDate = new DateTime(2017, 02, 27),
Duration = 2,
Progress = 25,
Priority = "Critical",
FilterStartDate = new DateTime(2017, 02, 27),
FilterEndDate = new DateTime(2017, 02, 27),
Approved = false,
};
Record9.Children.Add(Child21);
Record9.Children.Add(Child22);
Record9.Children.Add(Child23);
Record9.Children.Add(Child24);
Record9.Children.Add(Child25);
Record9.Children.Add(Child26);
Record6.Children.Add(Record9);
Record3.Children.Add(Record6);
BusinessObjectCollection.Add(Record1);
BusinessObjectCollection.Add(Record2);
BusinessObjectCollection.Add(Record3);
return BusinessObjectCollection;
}
public static List<object> GetTemplateData()
{
List<Object> DataCollection = new List<object>();
List<Object> Child111 = new List<object>();
Child111.Add(new
{
Name = "Andrew Fuller",
FullName = "AndrewFuller",
Designation = "Sales Representative",
EmployeeID = "4",
EmpID = "EMP045",
Address = "14 Garrett Hill, London",
Contact = "(71) 555-4848",
Country = "UK",
DOB = new DateTime(1980, 9, 20)
});
Child111.Add(new
{
Name = "Anne Dodsworth",
FullName = "AnneDodsworth",
Designation = "Sales Representative",
EmployeeID = "5",
EmpID = "EMP091",
Address = "4726 - 11th Ave. N.E., Seattle",
Contact = "(206) 555-1189",
Country = "USA",
DOB = new DateTime(1989, 10, 19)
});
Child111.Add(new
{
Name = "Michael Suyama",
FullName = "MichaelSuyama",
Designation = "Sales Representative",
EmployeeID = "6",
EmpID = "EMP110",
Address = "Coventry House Miner Rd., London",
Contact = "(71) 555-3636",
Country = "UK",
DOB = new DateTime(1987, 11, 02)
});
Child111.Add(new
{
Name = "Janet Leverling",
FullName = "JanetLeverling",
Designation = "Sales Coordinator",
EmployeeID = "7",
EmpID = "EMP131",
Address = "Edgeham Hollow Winchester Way, London",
Contact = "(71) 555-3636",
Country = "UK",
DOB = new DateTime(1090, 11, 06)
});
List<Object> Child11 = new List<object>();
Child11.Add(new
{
Name = "Nancy Davolio",
FullName = "NancyDavolio",
Designation = "Marketing Executive",
EmployeeID = "3",
EmpID = "EMP035",
Address = "4110 Old Redmond Rd., Redmond",
Contact = "(206) 555-8122",
Country = "USA",
DOB = new DateTime(1966, 3, 19),
Children = Child111
});
List<Object> Child112 = new List<object>();
Child112.Add(new
{
Name = "Margaret Peacock",
FullName = "MargaretPeacock",
Designation = "Sales Representative",
EmployeeID = "9",
EmpID = "EMP213",
Address = "4726 - 11th Ave. N.E., California",
Contact = "(206) 555-1989",
Country = "USA",
DOB = new DateTime(1986, 1, 21)
});
Child112.Add(new
{
Name = "Steven Buchanan",
FullName = "StevenBuchanan",
Designation = "Sales Representative",
EmployeeID = "11",
EmpID = "EMP197",
Address = "200 Lincoln Ave, Salinas, CA 93901",
Contact = "(831) 758-7408",
Country = "USA",
DOB = new DateTime(1987, 3, 23)
});
Child112.Add(new
{
Name = "Tedd Lawson",
FullName = "TeddLawson",
Designation = "Sales Representative",
EmployeeID = "12",
EmpID = "EMP167",
Address = "200 Lincoln Ave, Salinas, CA 93901",
Contact = "(831) 758-7368",
Country = "USA",
DOB = new DateTime(1989, 8, 9)
});
Child11.Add(new
{
Name = "Romey Wilson",
FullName = "RomeyWilson",
Designation = "Sales Executive",
EmployeeID = "8",
EmpID = "EMP039",
Address = "7 Houndstooth Rd., London",
Contact = "(71) 555-3690",
Country = "UK",
DOB = new DateTime(1980, 2, 2),
Children = Child112
});
List<Object> Child1 = new List<object>();
Child1.Add(new
{
Name = "David william",
FullName = "DavidWilliam",
Designation = "Vice President",
EmployeeID = "2",
EmpID = "EMP004",
Address = "722 Moss Bay Blvd., Kirkland",
Contact = "(206) 555-3412",
Country = "USA",
DOB = new DateTime(1971, 5, 20),
Children = Child11
});
DataCollection.Add(new
{
Name = "Robert King",
FullName = "RobertKing",
Designation = "Chief Executive Officer",
EmployeeID = "1",
EmpID = "EMP001",
Address = "507 - 20th Ave. E.Apt. 2A, Seattle",
Contact = "(206) 555-9857",
Country = "USA",
DOB = new DateTime(1963, 2, 15),
Children = Child1
});
return DataCollection;
}
public static List<TreeGridItems> GetSelfData()
{
List<TreeGridItems> BusinessObjectCollection = new List<TreeGridItems>();
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 1,
TaskName = "Parent Task 1",
StartDate = new DateTime(2017, 10, 23),
EndDate = new DateTime(2017, 11, 27),
Duration = 10,
Progress = 70,
Priority = "Critical",
ParentId = null
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 2,
TaskName = "Child task 1",
StartDate = new DateTime(2017, 10, 23),
EndDate = new DateTime(2017, 12, 25),
Duration = 4,
Progress = 80,
Priority = "Low",
ParentId = 1
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 3,
TaskName = "Child Task 2",
StartDate = new DateTime(2017, 10, 24),
EndDate = new DateTime(2018, 03, 19),
Duration = 5,
Progress = 65,
Priority = "High",
ParentId = 1
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 4,
TaskName = "Child task 3",
StartDate = new DateTime(2017, 10, 25),
EndDate = new DateTime(2018, 10, 26),
Duration = 6,
Progress = 77,
Priority = "Low",
ParentId = 1
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 5,
TaskName = "Parent Task 2",
StartDate = new DateTime(2017, 10, 23),
EndDate = new DateTime(2018, 10, 27),
Duration = 10,
Progress = 70,
Priority = "Breaking",
ParentId = null
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 6,
TaskName = "Child task 1",
StartDate = new DateTime(2017, 10, 23),
EndDate = new DateTime(2017, 12, 19),
Duration = 4,
Progress = 80,
Priority = "Normal",
ParentId = 5
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 7,
TaskName = "Child Task 2",
StartDate = new DateTime(2017, 10, 24),
EndDate = new DateTime(2017, 11, 20),
Duration = 5,
Priority = "High",
Progress = 65,
ParentId = 5
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 8,
TaskName = "Child task 3",
StartDate = new DateTime(2017, 10, 25),
EndDate = new DateTime(2018, 11, 20),
Duration = 6,
Priority = "High",
Progress = 77,
ParentId = 5
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 9,
TaskName = "Child task 4",
StartDate = new DateTime(2017, 10, 25),
EndDate = new DateTime(2018, 03, 19),
Duration = 6,
Progress = 77,
Priority = "Low",
ParentId = 5
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 10,
TaskName = "Parent Task 3",
StartDate = new DateTime(2017, 10, 23),
EndDate = new DateTime(2018, 03, 25),
Duration = 10,
Progress = 70,
Priority = "Normal",
ParentId = null
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 11,
TaskName = "Child task 1",
StartDate = new DateTime(2017, 10, 23),
Duration = 4,
EndDate = new DateTime(2017, 10, 30),
Priority = "Low",
Progress = 80,
ParentId = 10
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 12,
TaskName = "Child Task 2",
StartDate = new DateTime(2017, 10, 24),
EndDate = new DateTime(2018, 11, 19),
Duration = 5,
Progress = 65,
Priority = "Critical",
ParentId = 10
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 13,
TaskName = "Child task 3",
StartDate = new DateTime(2017, 10, 25),
EndDate = new DateTime(2017, 11, 10),
Duration = 6,
Progress = 77,
Priority = "Critical",
ParentId = 10
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 14,
TaskName = "Child task 4",
StartDate = new DateTime(2017, 10, 25),
EndDate = new DateTime(2017, 11, 12),
Duration = 6,
Progress = 77,
Priority = "High",
ParentId = 10
});
BusinessObjectCollection.Add(new TreeGridItems()
{
TaskId = 15,
TaskName = "Child task 5",
StartDate = new DateTime(2017, 10, 25),
EndDate = new DateTime(2017, 11, 23),
Duration = 6,
Progress = 77,
Priority = "Low",
ParentId = 10
});
return BusinessObjectCollection;
}
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
The Tree Grid column can be showed/hidden dynamically using showColumns and hideColumns methods.
In this demo, the columns can be showed and hidden by selecting the column name in the dropdown and click the Show or Hide buttons to toggle visibility. And the column`s visibility is toggled based on the Columns->HeaderText value.
The Columns->Visible property specifies the visibility of a column. To hide a column at the initial rendering, set the Columns->Visible property to false.