Filter menu in EJ2 JavaScript Gantt control
2 May 20239 minutes to read
The Gantt control provides the menu filtering support for each column. You can enable the filter menu by setting the allowFiltering
to true
. The filter menu UI will be rendered based on its column type, which allows you to filter data. You can filter the records with different operators.
ej.gantt.Gantt.Inject(ej.gantt.Filter);
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height:'450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
filterSettings: {
type:'Menu'
},
allowFiltering: true
});
ganttChart.appendTo('#Gantt');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/23.1.36/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="Gantt"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>
The
allowFiltering
property should be set totrue
to enable the filter menu.
Setting thecolumns.allowFiltering
property tofalse
prevents rendering filter menu for a particular column.
Custom component in filter menu
The column.filter.ui
is used to add custom filter components to a particular column.
To implement custom filter ui, define the following functions:
-
create
: Creates custom component. -
write
: Wire events for custom component. -
read
: Read the filter value from custom component.
In the following sample, dropdown is used as custom component in the TaskName column.
ej.gantt.Gantt.Inject(ej.gantt.Filter);
var ganttChart = new ej.gantt.Gantt({
dataSource: GanttData,
height: '450px',
taskFields: {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
child: 'subtasks'
},
columns: [
{ field: 'TaskID' },
{ field: 'TaskName', filter: {
ui: {
create: function(args){
var db = new ej.data.DataManager(ganttChart.treeGrid.grid.dataSource);
var flValInput = ej.base.createElement('input', { className: 'flm-input' });
args.target.appendChild(flValInput);
this.dropInstance = new ej.dropdowns.DropDownList({
dataSource: new ej.data.DataManager(ganttChart.treeGrid.grid.dataSource),
fields: { text: 'TaskName', value: 'TaskName' },
placeholder: 'Select a value',
popupHeight: '200px'
});
this.dropInstance.appendTo(flValInput);
},
write: function(args){
this.dropInstance.value = args.filteredValue;
},
read: function(args) {
args.fltrObj.filterByColumn(args.column.field, args.operator, this.dropInstance.value);
}
}
}
},
{ field: 'StartDate' },
{ field: 'Duration' }
],
allowFiltering: true
});
ganttChart.appendTo('#Gantt');
<!DOCTYPE html><html lang="en"><head>
<title>EJ2 Gantt</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript Gantt Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/material.css" rel="stylesheet" type="text/css">
<script src="https://cdn.syncfusion.com/ej2/23.1.36/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="Gantt"></div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>