How can I help you?
Search in gantt control
9 Jan 20237 minutes to read
You can search records in the Gantt control by using the search method with search key as a parameter. The Gantt control provides an option to integrate the search text box in the toolbar by adding the search item to the Toolbar property.
@(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")
).Toolbar(new List<string>() { "Search" }).Render()public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}The following screenshot shows the output of searching for string in Gantt control.

Initial search
In the Gantt control, you can load a task with some search criteria and this can be done by using the SearchSettings property. To apply search at initial rendering, set the value for Fields, Operator, Key, and IgnoreCase in the SearchSettings property.
@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")).Toolbar(new List<string>() {
"Search" }).SearchSettings(search =>
{
search.Fields(new string[] { "TaskName" })
.Operator("contains")
.Key("List")
.IgnoreCase(true);
}).Render()public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}
NOTE
By default, Gantt searches all the bound column values. To customize this behavior, define the
SearchSettings.Fieldsproperty.
Search operators
The search operator can be defined in the SearchSettings.Operator property to configure specific searching.
The following operators are supported in searching:
| Operator | Description |
|---|---|
| startsWith | Checks whether a value begins with the specified value. |
| endsWith | Checks whether a value ends with the specified value. |
| contains | Checks whether a value contains the specified value. |
| equal | Checks whether a value is equal to the specified value. |
| notEqual | Checks for the values that are not equal to the specified value. |
NOTE
By default, the
SearchSettings.Operatorvalue iscontains.
Search by external button
To search the Gantt records from an external button, invoke the search method.
@Html.TextBox("searchText")
@Html.EJS().Button("Search").Content("Search Gantt").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>
document.getElementById('Search').addEventListener('click', function (args) {
var val = document.getElementById('searchText').value;
var ganttObj = document.getElementById('Gantt').ej2_instances[0];
ganttObj.search(val);
});
</script>public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}Search specific columns
By default, the Gantt control searches all the columns. You can search specific columns by defining the specific column’s field names in the SearchSettings.Fields property.
@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")).SearchSettings(search =>{ search.Fields(new string[] { "TaskName", "Duration" });}
).Toolbar(new List<string>() { "Search" }).Render()public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}NOTE
In above sample, you can search only
TaskNameandDurationcolumn values.
Clear search by external button
You can set searchSettings.key property as empty string, to clear the searched Gantt records from external button.
@Html.EJS().Button("clear").Content("Clear Search").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")).Toolbar(new List<string>() {
"Search" }).SearchSettings(search =>
{
search.Fields(new string[] { "TaskName" })
.Operator("contains")
.Key("Perform")
.IgnoreCase(true);
}).Render()
<script>
document.getElementById('clear').addEventListener('click', function (args) {
var ganttObj = document.getElementById('Gantt').ej2_instances[0];
ganttObj.searchSettings.key = "";
});
</script>public IActionResult Index()
{
ViewBag.DataSource = GanttData.ProjectNewData();
return View();
}