How can I help you?
Search in gantt control
9 Jan 20238 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.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px" toolbar="@(new List<string>() { "Search" })">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
</ejs-gantt>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.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px" toolbar="@(new List<string>() { "Search" })">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
<e-gantt-searchsettings fields="@(new string[] { "TaskName"})" operator="contains" key="List" ignoreCase="true"></e-gantt-searchsettings>
</ejs-gantt>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.
<input type="text" id="searchText">
<ejs-button id="Search" content="Search Gantt" cssClass="e-primary"></ejs-button>
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
</ejs-gantt>
<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.
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px" toolbar="@(new List<string>() { "Search"})">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
<e-gantt-searchSettings fields="@(new string[] { "TaskName", "Duration"})"></e-gantt-searchSettings>
</ejs-gantt>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.
<ejs-button id="clear" content="Clear Search" cssClass="e-primary"></ejs-button>
<ejs-gantt id='Gantt' dataSource="ViewBag.dataSource" height="450px" toolbar="@(new List<string>() { "Search" })">
<e-gantt-taskfields id="TaskId" name="TaskName" startDate="StartDate"
endDate="EndDate" duration="Duration" progress="Progress" child="SubTasks">
</e-gantt-taskfields>
<e-gantt-searchsettings fields="@(new string[] { "TaskName"})" operator="contains" key="Perform" ignoreCase="true"></e-gantt-searchsettings>
</ejs-gantt>
<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();
}