Splitter in ASP.NET MVC Gantt component

3 Jan 20243 minutes to read

Splitter

In the Gantt control, the Splitter separates the TreeGrid section from the Chart section. You can change the position of the Splitter when loading the Gantt control using the SplitterSettings property. By splitting the TreeGrid from the chart, the width of the TreeGrid and chart sections will vary in the control. The SplitterSettings.Position property denotes the percentage of the TreeGrid section’s width to be rendered and this property supports both pixels and percentage values. You can define the splitter position as column index value using the SplitterSettings.ColumnIndex property. You can also define the splitter position with built-in splitter view modes by using the SplitterSettings.View property. The following list is the possible values for this property:

  • Default: Shows Grid side and Gantt side.
  • Grid: Shows Grid side alone in Gantt.
  • Chart: Shows chart side alone in Gantt.
@Html.EJS().Gantt("Gantt").DataSource((IEnumerable<object>)ViewBag.DataSource).Height("450px").TaskFields(ts =>
             ts.Id("TaskId").Name("TaskName").StartDate("StartDate").EndDate("EndDate").Duration("Duration").Progress("Progress").Child("SubTasks")
             ).SplitterSettings(ss=>ss.Position("80%")).Render()
public IActionResult Index()
{
    ViewBag.DataSource = GanttData.ProjectNewData();
    return View();
}

Alt text

Change splitter position dynamically

In Gantt, we can change the splitter position dynamically by using setSplitterPosition method. We can change the splitter position by passing value and type parameter to setSplitterPosition method. Type parameter will accept one of the following values ‘position’, ‘columnIndex’, ‘viewType’. The following code example shows how to use this method.

@Html.EJS().DropDownList("SplitterView").DataSource((IEnumerable<object>)ViewBag.dropdata).Width("250px").Value("Default").Fields(new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings { Text = "id", Value = "view" }).Change("onViewChange").Render()
    @Html.EJS().Button("changeByPosition").Content("Change Splitter By Position").CssClass("e-primary").Render()
    @Html.EJS().Button("changeByIndex").Content("Change Splitter By ColumnIndex").CssClass("e-primary").Render()
    @(Html.EJS().Gantt("Gantt").DataSource((IEnumerable<object>)ViewBag.DataSource).Height("450px").TaskFields(ts =>
     ts.Id("TaskId").Name("TaskName").StartDate("StartDate").EndDate("EndDate").Duration("Duration").Progress("Progress").Child("SubTasks")
     ).Render())
				
	<script>
	 function onViewChange(e) {
            var viewType = e.value;
            var ganttObj = document.getElementById("Gantt").ej2_instances[0];
            ganttObj.setSplitterPosition(viewType, 'view');
        }
		
        document.getElementById("changeByPosition").addEventListener('click', () => {
            var ganttObj = document.getElementById("Gantt").ej2_instances[0];
            ganttObj.setSplitterPosition('50%', 'position');
        });

        document.getElementById("changeByIndex").addEventListener('click', () => {
            var ganttObj = document.getElementById("Gantt").ej2_instances[0];
            ganttObj.setSplitterPosition(0, 'columnIndex');
        });
	</script>
public IActionResult Index()
{
    ViewBag.DataSource = GanttData.ProjectNewData();
    ViewBag.dropdata = new List<object>() {
               new { id= "Default", view= "Default" },
               new { id= "Grid", view= "Grid" },
               new { id= "Chart", view= "Chart" }
            };
    return View();
}