Search results

Sorting in React Kanban component

09 Jun 2021 / 7 minutes to read

The Kanban provides built-in support to arrange the cards in their columns based on the JSON data order and drop the cards in the columns based on the dropped clone. Initially, users can change the arrangement of cards in the columns and position of the dropped card by using the sortBy property. The sortBy property contains three enumeration values as follows.

  • Index
  • DataSourceOrder
  • Custom

Index

SortBy Index property can be used with or without field mapping.

Index without field mapping

By default, SortBy Index property support without any field mapping. In this behavior, cards are loaded based on the JSON data order and cards are dropped based on the dropped clone.

Source
Preview
index.jsx
index.tsx
index.html
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { extend } from '@syncfusion/ej2-base';
import { KanbanComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-react-kanban";
import { kanbanData } from './datasource';
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.data = extend([], kanbanData, null, true);
    }
    render() {
        return <KanbanComponent id="kanban" keyField="Status" dataSource={this.data} cardSettings={{ contentField: "Summary", headerField: "Id" }}>
            <ColumnsDirective>
              <ColumnDirective headerText="To Do" keyField="Open"/>
              <ColumnDirective headerText="In Progress" keyField="InProgress"/>
              <ColumnDirective headerText="Testing" keyField="Testing"/>
              <ColumnDirective headerText="Done" keyField="Close"/>
            </ColumnsDirective>
        </KanbanComponent>;
    }
}
;
ReactDOM.render(<App />, document.getElementById('kanban'));
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { extend } from '@syncfusion/ej2-base';
import { KanbanComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-react-kanban";
import { kanbanData } from './datasource';

class App extends React.Component<{}, {}>{
   constructor() {
    super(...arguments);
    this.data = extend([], kanbanData, null, true);
}
  render() {
return <KanbanComponent id="kanban" keyField="Status" dataSource={this.data} cardSettings={{ contentField: "Summary", headerField: "Id" }}>
            <ColumnsDirective>
              <ColumnDirective headerText="To Do" keyField="Open" />
              <ColumnDirective headerText="In Progress" keyField="InProgress" />
              <ColumnDirective headerText="Testing" keyField="Testing" />
              <ColumnDirective headerText="Done" keyField="Close" />
            </ColumnsDirective>
        </KanbanComponent>
  }
};
ReactDOM.render(<App />, document.getElementById('kanban'));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Kanban Single Key Columns</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Kanban single key columns" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-layouts/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-navigations/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-kanban/styles/material.css" rel="stylesheet" />
    <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>
</head>

<body>
        <div id='kanban'>
            <div id='loader'>Loading....</div>
        </div>
</body>

</html>

Index with field mapping

SortBy Index property also supports with field mapping. In this behavior, cards are loaded based on mapping field values, and cards are dropped based on the dropped clone.

Cards are placed in a particular position in the columns where you can drop the cards by specifying the field property, which is mapped from the data source. This property allows the users to drop the cards in the Kanban board where the dropped clone is created exactly. It is also helpful to render the cards based on the field property value.

The field property mapping key value must be in number format.

The following cases will dynamically change their field value when dropping the cards.

  • If the cell has no cards, the dropped card field value does not change.
  • If the cell has one card and dropped a card to the last position or previous/next cards that do not have continuous order, then the dropped card field value will be changed based on their previous card value.
  • If the cell has one card and dropped a card on the previous position, then it will compare both the values, and the dropped card field value will be changed if the cards have continuous order otherwise values will not be changed.
  • When the previous and next cards do not have continuous order, the dropped card field value will be changed based on the previous card value.
  • When the previous and next cards have continuous order or odd/even value, then the field value of the dropped card and the cards followed by the dropped card will be changed based on the previous card value with continuous order.

For Example, Continuous Order - Consider, Column A has Card A with priority value 1, Card B with priority value 2, and Card C with priority value 3. and Column B has Card D with priority value 5, then the dropped Card D will be placed between Card A and Card B. Now, the Cards D, B, and C will be dynamically changed to the priority values as 2, 3, and 4 respectively.

Odd/Even order - Consider, Column A has Card A with priority value 1, Card B with priority value 3, and Card C with priority value 5. and Column B has Card D with priority value 5, then the Dropped Card D will be placed between Card A and Card B. Now, the Cards D, B, and C will be dynamically changed to the priority values as 2, 3, and 5 respectively.

Source
Preview
index.jsx
index.tsx
index.html
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { extend } from '@syncfusion/ej2-base';
import { KanbanComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-react-kanban";
import { kanbanData } from './datasource';
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.data = extend([], kanbanData, null, true);
    }
    render() {
        return <KanbanComponent id="kanban" keyField="Status" dataSource={this.data} cardSettings={{ contentField: "Summary", headerField: "Id" }} sortSettings={{ sortBy: "Index", field: "RankId" }}>
            <ColumnsDirective>
              <ColumnDirective headerText="To Do" keyField="Open"/>
              <ColumnDirective headerText="In Progress" keyField="InProgress"/>
              <ColumnDirective headerText="Testing" keyField="Testing"/>
              <ColumnDirective headerText="Done" keyField="Close"/>
            </ColumnsDirective>
        </KanbanComponent>;
    }
}
;
ReactDOM.render(<App />, document.getElementById('kanban'));
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { extend } from '@syncfusion/ej2-base';
import { KanbanComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-react-kanban";
import { kanbanData } from './datasource';

class App extends React.Component<{}, {}>{
   constructor() {
    super(...arguments);
    this.data = extend([], kanbanData, null, true);
}
  render() {
return <KanbanComponent id="kanban" keyField="Status" dataSource={this.data} cardSettings={{ contentField: "Summary", headerField: "Id" }} sortSettings={{ sortBy: "Index", field: "RankId" }}>
            <ColumnsDirective>
              <ColumnDirective headerText="To Do" keyField="Open" />
              <ColumnDirective headerText="In Progress" keyField="InProgress" />
              <ColumnDirective headerText="Testing" keyField="Testing" />
              <ColumnDirective headerText="Done" keyField="Close" />
            </ColumnsDirective>
        </KanbanComponent>
  }
};
ReactDOM.render(<App />, document.getElementById('kanban'));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Kanban Single Key Columns</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Kanban single key columns" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-layouts/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-navigations/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-kanban/styles/material.css" rel="stylesheet" />
    <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>
</head>

<body>
        <div id='kanban'>
            <div id='loader'>Loading....</div>
        </div>
</body>

</html>

DataSource Order

The SortBy DataSourceOrder property does not require any field mapping. In this behavior, cards are loaded based on the JSON data order, and also cards are dropped based on the JSON data order.

Source
Preview
index.jsx
index.tsx
index.html
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { extend } from '@syncfusion/ej2-base';
import { KanbanComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-react-kanban";
import { kanbanData } from './datasource';
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.data = extend([], kanbanData, null, true);
    }
    render() {
        return <KanbanComponent id="kanban" keyField="Status" dataSource={this.data} cardSettings={{ contentField: "Summary", headerField: "Id" }} sortSettings={{ sortBy: "DataSourceOrder" }}>
            <ColumnsDirective>
              <ColumnDirective headerText="To Do" keyField="Open"/>
              <ColumnDirective headerText="In Progress" keyField="InProgress"/>
              <ColumnDirective headerText="Testing" keyField="Testing"/>
              <ColumnDirective headerText="Done" keyField="Close"/>
            </ColumnsDirective>
        </KanbanComponent>;
    }
}
;
ReactDOM.render(<App />, document.getElementById('kanban'));
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { extend } from '@syncfusion/ej2-base';
import { KanbanComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-react-kanban";
import { kanbanData } from './datasource';

class App extends React.Component<{}, {}>{
   constructor() {
    super(...arguments);
    this.data = extend([], kanbanData, null, true);
}
  render() {
return <KanbanComponent id="kanban" keyField="Status" dataSource={this.data} cardSettings={{ contentField: "Summary", headerField: "Id" }} sortSettings={{ sortBy: "DataSourceOrder" }}>
            <ColumnsDirective>
              <ColumnDirective headerText="To Do" keyField="Open" />
              <ColumnDirective headerText="In Progress" keyField="InProgress" />
              <ColumnDirective headerText="Testing" keyField="Testing" />
              <ColumnDirective headerText="Done" keyField="Close" />
            </ColumnsDirective>
        </KanbanComponent>
  }
};
ReactDOM.render(<App />, document.getElementById('kanban'));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Kanban Single Key Columns</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Kanban single key columns" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-layouts/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-navigations/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-kanban/styles/material.css" rel="stylesheet" />
    <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>
</head>

<body>
        <div id='kanban'>
            <div id='loader'>Loading....</div>
        </div>
</body>

</html>

Custom

Custom with field mapping

The SortBy Custom property must require datasource field mapping. In this behavior, cards are loaded based on the field mapping value and also cards are dropped based on the field mapping value.

Source
Preview
index.jsx
index.tsx
index.html
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { extend } from '@syncfusion/ej2-base';
import { KanbanComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-react-kanban";
import { kanbanData } from './datasource';
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.data = extend([], kanbanData, null, true);
    }
    render() {
        return <KanbanComponent id="kanban" keyField="Status" dataSource={this.data} cardSettings={{ contentField: "Summary", headerField: "Id" }} sortSettings={{ sortBy: "Custom", field: "Summary" }}>
            <ColumnsDirective>
              <ColumnDirective headerText="To Do" keyField="Open"/>
              <ColumnDirective headerText="In Progress" keyField="InProgress"/>
              <ColumnDirective headerText="Testing" keyField="Testing"/>
              <ColumnDirective headerText="Done" keyField="Close"/>
            </ColumnsDirective>
        </KanbanComponent>;
    }
}
;
ReactDOM.render(<App />, document.getElementById('kanban'));
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { extend } from '@syncfusion/ej2-base';
import { KanbanComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-react-kanban";
import { kanbanData } from './datasource';

class App extends React.Component<{}, {}>{
   constructor() {
    super(...arguments);
    this.data = extend([], kanbanData, null, true);
}
  render() {
return <KanbanComponent id="kanban" keyField="Status" dataSource={this.data} cardSettings={{ contentField: "Summary", headerField: "Id" }} sortSettings={{ sortBy: "Custom", field: "Summary" }}>
            <ColumnsDirective>
              <ColumnDirective headerText="To Do" keyField="Open" />
              <ColumnDirective headerText="In Progress" keyField="InProgress" />
              <ColumnDirective headerText="Testing" keyField="Testing" />
              <ColumnDirective headerText="Done" keyField="Close" />
            </ColumnsDirective>
        </KanbanComponent>
  }
};
ReactDOM.render(<App />, document.getElementById('kanban'));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Kanban Single Key Columns</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Kanban single key columns" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-layouts/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-navigations/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-kanban/styles/material.css" rel="stylesheet" />
    <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>
</head>

<body>
        <div id='kanban'>
            <div id='loader'>Loading....</div>
        </div>
</body>

</html>

Change the direction

Kanban board also provides support for aligning the cards in the columns using the direction property inside the sortSettings property. Based on this, cards can be aligned in the columns either in Ascending or Descending order. Sorting direction will be performed based on sortBy property.

By default, cards are aligned in the columns based on Ascending order.

In the following sample, cards are aligned in Descending order.

Source
Preview
index.jsx
index.tsx
index.html
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { extend } from '@syncfusion/ej2-base';
import { KanbanComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-react-kanban";
import { kanbanData } from './datasource';
class App extends React.Component {
    constructor() {
        super(...arguments);
        this.data = extend([], kanbanData, null, true);
    }
    render() {
        return <KanbanComponent id="kanban" keyField="Status" dataSource={this.data} cardSettings={{ contentField: "Summary", headerField: "Id" }} sortSettings={{ sortBy: "Custom", field: "Summary", direction: "Descending" }}>
            <ColumnsDirective>
              <ColumnDirective headerText="To Do" keyField="Open"/>
              <ColumnDirective headerText="In Progress" keyField="InProgress"/>
              <ColumnDirective headerText="Testing" keyField="Testing"/>
              <ColumnDirective headerText="Done" keyField="Close"/>
            </ColumnsDirective>
        </KanbanComponent>;
    }
}
;
ReactDOM.render(<App />, document.getElementById('kanban'));
Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { extend } from '@syncfusion/ej2-base';
import { KanbanComponent, ColumnsDirective, ColumnDirective } from "@syncfusion/ej2-react-kanban";
import { kanbanData } from './datasource';

class App extends React.Component<{}, {}>{
   constructor() {
    super(...arguments);
    this.data = extend([], kanbanData, null, true);
}
  render() {
return <KanbanComponent id="kanban" keyField="Status" dataSource={this.data} cardSettings={{ contentField: "Summary", headerField: "Id" }} sortSettings={{ sortBy: "Custom", field: "Summary", direction: "Descending" }}>
            <ColumnsDirective>
              <ColumnDirective headerText="To Do" keyField="Open" />
              <ColumnDirective headerText="In Progress" keyField="InProgress" />
              <ColumnDirective headerText="Testing" keyField="Testing" />
              <ColumnDirective headerText="Done" keyField="Close" />
            </ColumnsDirective>
        </KanbanComponent>
  }
};
ReactDOM.render(<App />, document.getElementById('kanban'));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Kanban Single Key Columns</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Kanban single key columns" />
    <meta name="author" content="Syncfusion" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-layouts/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-navigations/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-dropdowns/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-inputs/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-kanban/styles/material.css" rel="stylesheet" />
    <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>
</head>

<body>
        <div id='kanban'>
            <div id='loader'>Loading....</div>
        </div>
</body>

</html>