Overview of Syncfusion React Gantt Chart Component
Tags: react, javascript, productivity
Published: 2019-11-25 12:39:24

---
title: Overview of Syncfusion React Gantt Chart Component
published: true
date: 2019-11-25 12:00:10 UTC
tags: react, javascript, productivity
canonical_url: https://www.syncfusion.com/blogs/post/overview-syncfusion-react-gantt-chart.aspx
cover_image: https://www.syncfusion.com/blogs/wp-content/uploads/2019/11/Blog_1x.jpg
---

The [Syncfusion React Gantt Chart](https://www.syncfusion.com/react-ui-components/react-gantt-chart) is a modern web component for visualizing a project’s status and activities in a webpage. Using this, we can schedule the task activities of a project, track the status of those activities, and track resource allocation in projects. We can also manage the project activities, like update the values and add and delete the activities. The Gantt Chart component is built based on modular architecture, so we can load feature modules on demand.

In this article, we are going to learn how to use the Syncfusion Gantt Chart component in a React application and how to inject feature modules such as sorting, filtering, editing, and day markers.

## Setting up a development environment

Let’s use [create-react-app](https://www.npmjs.com/package/create-react-app) to create a React application with basic configuration. For this, you need to install the create-react-app CLI. You’ll use the following command.

```
npm install -g create-react-app
```

Then, create a new React application using the following command.

```
create-react-app react-gantt
```

Here, react-gantt is the name of an application, and you can name it as you wish. Ensure that your application has been created properly by running the application using the following command.

```
npm start
```

While running this command, the React application will be launched in the browser with **localhost:3000** URL.

## Configuring Gantt Chart in a React application

Now, the React application is ready, and you can configure the Gantt Chart component in it. The Gantt Chart component is available in the [@syncfusion/ej2-react-gantt](https://www.npmjs.com/package/@syncfusion/ej2-react-gantt) package.

Install this package in the React application. You can do this using the following command.

```
npm install @syncfusion/ej2-react-gantt --save
```

### Themes in Gantt Chart

The following themes are available to paint the Gantt Chart as per your website theme preference:

- Material
- Bootstrap
- Fabric
- High contrast

Gantt Chart has some subcomponents. To apply a theme to the component, add theme files from the node-modules folder for all the components. Or load it from a single theme file for all the Syncfusion components. Here, we are going to reference a common theme file for all the components. In this sample, we are going to add Material theme in the index.html file.

```
<link href="https://cdn.syncfusion.com/ej2/material.css" rel="stylesheet">
```

### Initializing Gantt Chart

We have configured the packages and themes to render Gantt Chart in this application, and now we can initialize the component using the following code snippet in the **App.js** file.

```js
import React from 'react';
import { GanttComponent } from '@syncfusion/ej2-react-gantt';
 
function App() {
  return (
   <div>
     <GanttComponent></GanttComponent>
   </div>
  );
}
 
export default App;
```

### Defining task details to Gantt Chart

To render the Gantt Chart component, we need to define a data source and basic properties to it. The data source object should contain minimal fields such as ID, start date, and end date to render the Gantt Chart. The data source can be an array of JavaScript objects or remote data. To keep this application simple, we are going to reference a JavaScript array of objects as the data source. Add the data source in the App.js file itself, and use the [dataSource](https://ej2.syncfusion.com/react/documentation/api/gantt/#datasource) property to pass it to the Gantt Chart component.

```js
const dataSource = [
    {
      taskID: 1,
      taskName: "Planning",
      startDate: new Date("02/06/2019"),
      subtasks: [
        {
          taskID: 2,
          taskName: "Plan timeline",
          startDate: new Date("02/04/2019"),
          duration: 5,
          progress: 100
        },
        {
          taskID: 3,
          taskName: "Plan budget",
          startDate: new Date("02/07/2019"),
          duration: 5, progress: 100
        },
        {
          taskID: 4,
          taskName: "Allocate resources",
          startDate: new Date("02/10/2019"),
          duration: 5,
          progress: 100
        },
        {
          taskID: 5,
          taskName: "Planning complete",
          startDate: new Date("02/13/2019"),
          duration: 0,
          progress: 0
        }
      ]
    }
  ];
```

### Mapping task properties to Gantt Chart

You have prepared the data source for the Gantt Chart component, and now you should map important fields from the data source to it. This can be done using the [taskFields](https://ej2.syncfusion.com/react/documentation/api/gantt/#taskfields) property. The [taskFileds](https://ej2.syncfusion.com/react/documentation/api/gantt/#taskfields) property has the following fields to map value from the data source.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/7erd02x0o8xne8mdo7go.png)

In this application, you’ll map some important fields alone to the Gantt Chart component.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/flu341wg63khm5cj3b6n.png)

### Running the application

This application can be run using the following command. While running the command, the application will be launched in the browser with the port number 3000.

```
npm start
```

![React Gantt Chart in a React application](https://www.syncfusion.com/blogs/wp-content/uploads/2019/11/React-Gantt-Chart-in-a-React-application.png)<figcaption>React Gantt Chart in a React application</figcaption>

### Injecting modules

The Gantt Chart component is built based on modular architecture, so we can import and use just required features in our applications. The component has the following feature modules.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/bl4vaneqjv5a03hiafzf.png)

Feature modules can be injected using the Inject component, and this component is available in the Syncfusion React Gantt Chart package. The following code snippet demonstrates how to inject feature modules using the Inject component.

```js
import { GanttComponent, Inject, Sort } from '@syncfusion/ej2-react-gantt';
//...
 
<GanttComponent dataSource={dataSource} taskFields={taskFields} height="350px"
        allowSorting={true}
      >
        <Inject services={[Sort]} />
</GanttComponent>
```

In this article, we are also going to discuss some important modules and features available in Gantt Chart.

## Defining timeline settings

The Syncfusion React Gantt Chart component provides various options to customize its timeline. In this component, we can make a timeline a single tier or double tier, render a timeline with various timescale units (minute, hour, day, week, month, year, and decade), and combine the timescale units per cell with the required count. We can also specify the required format for the top and bottom timeline cells. By default, Gantt Chart’s timeline has the week unit at the top and the day unit on the bottom tier. In this application, we will make the timeline’s top tier the day unit, the timeline’s bottom tier the hour unit, and combine the hour unit cells with eight hours.

```js
//...
  const timelineSettings = {
    topTier: {
      unit: 'Day',
      format: 'dddd MMM yyyy'
    },
    bottomTier: {
      unit: 'Hour',
      count: 8,
      format: 'H'
    }
  };
 
 return (
   <div>
      <GanttComponent dataSource={dataSource} taskFields={taskFields} height="350px"
        timelineSettings={timelineSettings}
      >
      </GanttComponent>
   </div>
  );
```

Refer to this [documentation](https://ej2.syncfusion.com/react/documentation/api/gantt/timelineSettingsModel/) to learn more about the [timelineSettings](https://ej2.syncfusion.com/react/documentation/api/gantt/timelineSettingsModel/) of the Gantt Chart.

![Defining timeline settings in React Gantt Chart.](https://www.syncfusion.com/blogs/wp-content/uploads/2019/11/Defining-timeline-settings-in-React-Gantt-Chart.png)<figcaption>Defining timeline settings in React Gantt Chart</figcaption>

## Sorting

The sorting feature is used to reorder records in ascending or descending order based on fields such as ID, start date, duration, and progress. To enable the sorting feature, you need to inject the **Sort** module in Gantt and set the [allowSorting](https://ej2.syncfusion.com/react/documentation/api/gantt/#allowsorting) property to **true**. Sorting action is performed by clicking the required column header in the grid. On first click, records will be sorted in ascending order. On second click, records will be sorted in descending order. On third click, sorting is cleared for that specific column.

```js
import { GanttComponent, Inject, Sort } from '@syncfusion/ej2-react-gantt';
//...
 <GanttComponent dataSource={dataSource} taskFields={taskFields} height="350px"
        allowSorting={true}
      >
        <Inject services={[Sort]} />
 </GanttComponent>
```

Gantt tasks can be loaded in a sorted order by default by specifying the [sortSettings.columns](https://ej2.syncfusion.com/react/documentation/api/gantt/sortSettingsModel/) property.

![Using the sorting feature in React Gantt Chart.](https://www.syncfusion.com/blogs/wp-content/uploads/2019/11/Using-the-sorting-feature-in-React-Gantt-Chart.png)<figcaption>Using the sorting feature in React Gantt Chart</figcaption>

## Filtering

This feature is used to render just a required task based on some conditions. Gantt Chart has built-in support to filter tasks by using the filter menu. This can be enabled by injecting the **Filter** module in Gantt by setting the [allowFiltering](https://ej2.syncfusion.com/react/documentation/api/gantt/#allowfiltering) property to **true**. When we enable the filter feature, the filter icon will be added in all columns’ header cells. We can open the filter menu by clicking this icon. In this filter menu, we can specify conditions and values, initialize the filter action using the filter button, and clear previous filtering using the clear button. The filter menu will vary based on column data type: for a task name column, the menu will be based on string values; and for start date and end date columns, the menu will be based on date values.

```js
import { GanttComponent, Inject, Filter } from '@syncfusion/ej2-react-gantt';
//...
<GanttComponent dataSource={dataSource} taskFields={taskFields} height="350px"
        allowFiltering={true}
      >
        <Inject services={[Filter]} />
 </GanttComponent>
```

Gantt Chart can be loaded with filtered tasks by specifying values in the [filterSettings.columns](https://ej2.syncfusion.com/react/documentation/api/gantt/filterSettingsModel/) property.

![Using the filtering feature in React Gantt Chart.](https://www.syncfusion.com/blogs/wp-content/uploads/2019/11/Using-the-filtering-feature-in-React-Gantt-Chart.png)<figcaption>Using the filtering feature in React Gantt Chart</figcaption>

## Day markers

Using this module, we can represent holidays, event markers, and weekend days in the Gantt Chart. Holidays during the project timeline are specified using the [holidays](https://ej2.syncfusion.com/react/documentation/api/gantt/#holidays) property. Event marker support is used to represent some important date and stages, and this can be defined using the [eventMarkers](https://ej2.syncfusion.com/react/documentation/api/gantt/#eventmarkers) property. Weekend days can be highlighted using the [highlightWeekends](https://ej2.syncfusion.com/react/documentation/api/gantt/#highlightweekends) property. We can define weekends by using the [workWeek](https://ej2.syncfusion.com/react/documentation/api/gantt/#workweek) property, and days that are not included in the [workWeek](https://ej2.syncfusion.com/react/documentation/api/gantt/#workweek) property are considered weekend days.

```js
import { GanttComponent, Inject, DayMarkers } from '@syncfusion/ej2-react-gantt';
//...
 <GanttComponent dataSource={dataSource} taskFields={taskFields} height="350px"
        highlightWeekends={true}
        holidays={holidays}
        eventMarkers={eventMarkers}
      >
      <Inject services={[Sort, Filter, DayMarkers]} />
</GanttComponent>
```

![Using day markers in React Gantt Chart.](https://www.syncfusion.com/blogs/wp-content/uploads/2019/11/Using-day-markers-in-React-Gantt-Chart.png)<figcaption>Using day markers in React Gantt Chart</figcaption>

## Selection

This support is used to select a task and perform some action on it like edit and delete. We can get selected tasks dynamically from the Gantt Chart component and use them based on our requirements. Gantt supports row and cell selection, as well as multiple selection. To enable the selection support, we need to inject the **Selection** module, and set the [allowSelection](https://ej2.syncfusion.com/react/documentation/api/gantt/#allowselection) property to **true.** We can configure the selection mode to row or cell, and the selection type to single or multiple by using the [selectionSettings](https://ej2.syncfusion.com/react/documentation/api/gantt/#selectionsettings) property. In this application, we will enable row selection with multiple selection support.

```js
import {
  GanttComponent, Inject, Selection
} from '@syncfusion/ej2-react-gantt';
//...
 const selectionSettings = {
    mode: 'Row',
    type: 'Multiple'
  };
 
//...
 
 <GanttComponent dataSource={dataSource} taskFields={taskFields} height="400px"
        allowSelection={true}
        selectionSettings={selectionSettings}
      >
        <Inject services={[Selection]} />
 </GanttComponent>
```

![Using the selection support in React Gantt Chart.](https://www.syncfusion.com/blogs/wp-content/uploads/2019/11/Using-the-selection-support-in-React-Gantt-Chart.png)<figcaption>Using the selection support in React Gantt Chart</figcaption>

## Managing tasks

Syncfusion React Gantt Chart provides various options to manage tasks. We can perform add, edit, and delete actions by using the toolbar, context menu, keyboard shortcuts, and public methods. To perform add, edit, and delete actions, we need to inject the **Edit** module in Gantt Chart, and we need to enable these actions using the [editSettings](https://ej2.syncfusion.com/react/documentation/api/gantt/#editsettings) property. Gantt provides various options to edit task values: cell editing, dialog editing, and taskbar editing. Cell editing and dialog editing are controlled by the [editSettings.mode](https://ej2.syncfusion.com/react/documentation/api/gantt/editSettingsModel/#mode) property, and taskbar editing is enabled or disabled using the [editSettings.allowTaskbarEditing](https://ej2.syncfusion.com/react/documentation/api/gantt/editSettingsModel/#allowtaskbarediting) property. As we said earlier, we can use toolbar and context menu for managing the task, so in this application, we will enable the toolbar and context menu. These options are available as separate modules, so we need to import them to our application.

```js
import {
  GanttComponent, Inject,
  Edit, Toolbar, ContextMenu, Selection
} from '@syncfusion/ej2-react-gantt';
 
//...
 
 const editSettings = {
    allowAdding: true,
    allowEditing: true,
    allowDeleting: true,
    allowTaskbarEditing: true,
    mode: 'Dialog'
  };
  const toolbarItems = ['Add', 'Edit', 'Delete', 'Update', 'Cancel', 'ExpandAll', 'CollapseAll'];
 
//...
 
 <GanttComponent dataSource={dataSource} taskFields={taskFields} height="400px"
        editSettings={editSettings}
        toolbar={toolbarItems}
        enableContextMenu={true}
        allowSelection={true}
      >
        <Inject services={[Edit, Toolbar, ContextMenu, Selection]} />
 </GanttComponent>
```

![Managing tasks in React Gantt Chart.](https://www.syncfusion.com/blogs/wp-content/uploads/2019/11/Managing-tasks-in-React-Gantt-Chart.png)<figcaption>Managing tasks in React Gantt Chart</figcaption>

## GitHub sample

You can get the final application from this [GitHub repository](https://github.com/SyncfusionExamples/ReactGantt).

## Conclusion

In this article, we have learned how to integrate the [Syncfusion React Gantt Chart](https://www.syncfusion.com/react-ui-components/react-gantt-chart) component in a React application, learned about some important features available in Gantt, and how to use these features in an application. The Gantt Chart control has some other features, like resource allocation, baseline, unscheduled task, Excel export, indicators, column reorder, and column resizing. To learn more about the Syncfusion Gantt Chart component, refer to this [sample browser](https://ej2.syncfusion.com/react/demos/#/material/gantt/default) and [documentation](https://ej2.syncfusion.com/react/documentation/gantt/getting-started/?no-cache=1).

If you have any questions, please let us know in the comments section. You can also contact us through our [support forum](https://www.syncfusion.com/forums) or [Direct-Trac](https://www.syncfusion.com/support/directtrac/incidents). We are happy to assist you!

The post [Overview of Syncfusion React Gantt Chart Component](https://www.syncfusion.com/blogs/post/overview-syncfusion-react-gantt-chart.aspx) appeared first on [Syncfusion Blogs](https://www.syncfusion.com/blogs).