Contents
- Reorder Events
- Reorder multiple columns
Having trouble getting help?
Contact Support
Contact Support
Column reordering in React Gantt component
2 Feb 202317 minutes to read
The column reordering can be done by dragging a column header from one index to another index within the TreeGrid. To enable reordering, set the allowReordering
property to true.
To use the column reordering feature, inject the Reorder
module to the Gantt component.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GanttComponent, Inject, Reorder } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App (){
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'ParentID'
};
const splitterSettings = {
columnIndex : 5
};
return <GanttComponent dataSource={data} taskFields={taskFields} splitterSettings={splitterSettings}
allowReordering={true} height = '450px'>
<Inject services={[Reorder]} />
</GanttComponent>
};
ReactDOM.render(<App />, document.getElementById('root'));
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GanttComponent, Inject, Reorder } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App (){
const taskFields: any = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'ParentID'
};
const splitterSettings: any = {
columnIndex : 5
};
return <GanttComponent dataSource={data} taskFields={taskFields} splitterSettings={splitterSettings}
allowReordering={true} height = '450px'>
<Inject services={[Reorder]} />
</GanttComponent>
};
ReactDOM.render(<App />, document.getElementById('root'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/material.css" rel="stylesheet" type="text/css"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='root'>
<div id='loader'>Loading....</div>
</div>
</body>
</html>
You can disable the reordering of a particular column by setting the
columns.allowReordering
property tofalse
.
Reorder Events
During the reorder action, the gantt component triggers the below three events.
- The
columnDragStart
event triggers when column header element drag (move) starts. - The
columnDrag
event triggers when column header element is dragged (moved) continuously. - The
columnDrop
event triggers when a column header element is dropped on the target column.
import { createElement } from '@syncfusion/ej2-base';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GanttComponent, Inject, Reorder } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App (){
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'ParentID'
};
let ganttInstance;
const splitterSettings = {
columnIndex : 5
};
function columnDrop(){
alert('columnDrop event is Triggered');
}
function columnDragStart(){
alert('columnDragStart event is Triggered');
}
function columnDrag(){
alert('columnDrag event is Triggered');
}
return (<div>
<GanttComponent dataSource={data} taskFields={taskFields} allowReordering={true}
columnDragStart= { columnDragStart } columnDrag= { columnDrag } columnDrop= { columnDrop }
splitterSettings={splitterSettings} height = '450px' ref={gantt => ganttInstance = gantt}>
<Inject services={[Reorder]} />
</GanttComponent></div>)
};
ReactDOM.render(<App />, document.getElementById('root'));
import { createElement } from '@syncfusion/ej2-base';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { GanttComponent, Inject, Reorder } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App (){
const taskFields: any = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'ParentID'
};
let ganttInstance:any;
const splitterSettings: any = {
columnIndex : 5
};
function columnDrop(){
alert('columnDrop event is Triggered');
}
function columnDragStart(){
alert('columnDragStart event is Triggered');
}
function columnDrag(){
alert('columnDrag event is Triggered');
}
return (<div>
<GanttComponent dataSource={data} taskFields={taskFields} allowReordering={true}
columnDragStart= { columnDragStart } columnDrag= { columnDrag } columnDrop= { columnDrop }
splitterSettings={splitterSettings} height = '450px' ref={gantt => ganttInstance = gantt}>
<Inject services={[Reorder]} />
</GanttComponent></div>)
};
ReactDOM.render(<App />, document.getElementById('root'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/material.css" rel="stylesheet" type="text/css"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='root'>
<div id='loader'>Loading....</div>
</div>
</body>
</html>
Reorder multiple columns
Multiple columns can be reordered at a time by using the reorderColumns
method.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { GanttComponent, Inject, Reorder } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App(){
let ganttInstance;
const taskFields = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'ParentID'
};
const splitterSettings = {
position : '90%'
};
function clickHandler(){
ganttInstance.reorderColumns(['TaskID','TaskName'],'Progress');
}
return (<div>
<ButtonComponent onClick= {clickHandler}>Reorder Task ID and Task Name to Last</ButtonComponent>
<GanttComponent dataSource={data} taskFields={taskFields}
splitterSettings={splitterSettings} allowReordering={true} height = '450px' ref={gantt => ganttInstance = gantt}>
<Inject services={[Reorder]} />
</GanttComponent></div>)
};
ReactDOM.render(<App />, document.getElementById('root'));
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { GanttComponent, Inject, Reorder } from '@syncfusion/ej2-react-gantt';
import { data } from './datasource';
function App(){
let ganttInstance: any;
const taskFields: any = {
id: 'TaskID',
name: 'TaskName',
startDate: 'StartDate',
duration: 'Duration',
progress: 'Progress',
parentID: 'ParentID'
};
const splitterSettings: any = {
position : '90%'
};
function clickHandler(){
ganttInstance.reorderColumns(['TaskID','TaskName'],'Progress');
}
return (<div>
<ButtonComponent onClick= {clickHandler}>Reorder Task ID and Task Name to Last</ButtonComponent>
<GanttComponent dataSource={data} taskFields={taskFields}
splitterSettings={splitterSettings} allowReordering={true} height = '450px' ref={gantt => ganttInstance = gantt}>
<Inject services={[Reorder]} />
</GanttComponent></div>)
};
ReactDOM.render(<App />, document.getElementById('root'));
<!DOCTYPE html>
<html lang="en">
<head>
<title>Syncfusion React Gantt</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Essential JS 2 for React Components" />
<meta name="author" content="Syncfusion" />
<link href="https://cdn.syncfusion.com/ej2/29.1.33/material.css" rel="stylesheet" type="text/css"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<style>
#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
</style>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='root'>
<div id='loader'>Loading....</div>
</div>
</body>
</html>