The scrollbar will be displayed in the treegrid when content exceeds the element Width
or Height
. The vertical and horizontal scrollbars will be displayed based on the following criteria:
The vertical scrollbar appears when the total height of rows present in the treegrid exceeds its element height.
The horizontal scrollbar appears when the sum of columns width exceeds the treegrid element width.
The Height
and Width
are used to set the treegrid height and width, respectively.
To specify the Width
and Height
of the scroller in the pixel, set the pixel value to a number.
@(Html.EJS().TreeGrid("TreeGrid")
.DataSource((IEnumerable<object>)ViewBag.datasource)
.Columns(col =>
{
col.Field("TaskId").HeaderText("Task ID").Width(90).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("TaskName").HeaderText("Task Name").Width(180).Add();
col.Field("StartDate").HeaderText("Start Date").Format("yMd").Type("date").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width(120).Add();
col.Field("Duration").HeaderText("Duration").Width(110).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
}).Height(315).Width(400).ChildMapping("Children").TreeColumnIndex(1).Render())
public IActionResult Index()
{
var tree = TreeGridItems.GetTreeData();
ViewBag.datasource = tree;
return View();
}
Specify the Width
and Height
as 100% to make the treegrid element fill its parent container.
Setting the Height
to 100% requires the treegrid parent element to have explicit height.
@(Html.EJS().TreeGrid("TreeGrid")
.DataSource((IEnumerable<object>)ViewBag.datasource)
.Columns(col =>
{
col.Field("TaskId").HeaderText("Task ID").Width(90).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("TaskName").HeaderText("Task Name").Width(180).Add();
col.Field("StartDate").HeaderText("Start Date").Format("yMd").Type("date").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width(120).Add();
col.Field("Duration").HeaderText("Duration").Width(110).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
}).Height("100%").Width("100%").ChildMapping("Children").TreeColumnIndex(1).Render()
)
public IActionResult Index()
{
var tree = TreeGridItems.GetTreeData();
ViewBag.datasource = tree;
return View();
}
You can scroll the treegrid content to the selected row position by using the RowSelected
event.
@Html.EJS().NumericTextBox("numeric").Format("##").Min(0).Width(200).ShowSpinButton(false).Placeholder("Enter index to select a row").Change("onChange").Render()
@(Html.EJS().TreeGrid("TreeGrid")
.DataSource((IEnumerable<object>)ViewBag.datasource)
.Columns(col =>
{
col.Field("TaskId").HeaderText("Task ID").Width(90).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("TaskName").HeaderText("Task Name").Width(180).Add();
col.Field("StartDate").HeaderText("Start Date").Format("yMd").Type("date").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width(120).Add();
col.Field("Duration").HeaderText("Duration").Width(110).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
}).Height(270).Width("100%").ChildMapping("Children").TreeColumnIndex(1).RowSelected("rowSelected").Render()
)
<script>
function onChange(args) {
var treegrid = document.getElementById("TreeGrid").ej2_instances[0];
treegrid.selectRow(parseInt(this.getText(), 10));
}
function rowSelected(args) {
var rowHeight = this.getRows()[treegrid.getSelectedRowIndexes()[0]].scrollHeight;
this.getContent().children[0].scrollTop = rowHeight * this.getSelectedRowIndexes()[0];
}
</script>
public IActionResult Index()
{
var tree = TreeGridItems.GetTreeData();
ViewBag.datasource = tree;
return View();
}
Frozen rows and columns provides an option to make rows and columns always visible in the top and left side of the treegrid while scrolling.
In this demo, the FrozenColumns
is set as 2 and the FrozenRows
is set as 3. Hence, the left two columns and top three rows are frozen.
@Html.EJS().TreeGrid("DefaultFunctionalities").DataSource((IEnumerable<object>)ViewBag.datasource).AllowSelection(false).Columns(col =>
{
col.Field("TaskId").HeaderText("Task ID").Width(100).TextAlign(TextAlign.Right).Add();
col.Field("TaskName").HeaderText("Task Name").Width(230).Add();
col.Field("StartDate").HeaderText("Start Date").Width(150).TextAlign(TextAlign.Right).Format("yMd").Add();
col.Field("EndDate").HeaderText("End Date").Width(150).TextAlign(TextAlign.Right).Format("yMd").Add();
col.Field("Duration").HeaderText("Duration").Width(120).TextAlign(TextAlign.Right).Add();
col.Field("Progress").HeaderText("Progress").Width(120).TextAlign(TextAlign.Right).Add();
col.Field("Priority").HeaderText("Priority").Width(120).Add();
col.Field("Approved").HeaderText("Approved").TextAlign(TextAlign.Left).Type("boolean").Width(110).Add();
}).Height(410).ChildMapping("Children").TreeColumnIndex(1).FrozenColumns(2).FrozenRows(3).Render()
public IActionResult FrozenColumn()
{
ViewBag.datasource = TreeData.GetDefaultData();
return View();
}
To freeze particular column in the treegrid, the IsFrozen
property can be used.
In this demo, the columns with field name TaskName and StartDate is frozen using
the IsFrozen
property.
@Html.EJS().TreeGrid("DefaultFunctionalities").DataSource((IEnumerable<object>)ViewBag.datasource).AllowSelection(false).Columns(col =>
{
col.Field("TaskId").HeaderText("Task ID").Width(100).TextAlign(TextAlign.Right).Add();
col.Field("TaskName").HeaderText("Task Name").Width(230).IsFrozen(true).Add();
col.Field("StartDate").HeaderText("Start Date").Width(150).IsFrozen(true).TextAlign(TextAlign.Right).Format("yMd").Add();
col.Field("EndDate").HeaderText("End Date").Width(150).TextAlign(TextAlign.Right).Format("yMd").Add();
col.Field("Duration").HeaderText("Duration").Width(120).TextAlign(TextAlign.Right).Add();
col.Field("Progress").HeaderText("Progress").Width(120).TextAlign(TextAlign.Right).Add();
col.Field("Priority").HeaderText("Priority").Width(120).Add();
col.Field("Approved").HeaderText("Approved").TextAlign(TextAlign.Left).Type("boolean").Width(110).Add();
}).Height(410).ChildMapping("Children").Render()
public IActionResult FrozenColumn()
{
ViewBag.datasource = TreeData.GetDefaultData();
return View();
}
The following features are not supported in frozen rows and columns: