Getting Started with the KendoReact Sortable
Premium

This guide provides essential information about using the KendoReact Sortable package—you will learn how to install the Sortable package, add a Sortable component to your project, style the component, and activate your license.

ninja-iconThe Sortable is part of KendoReact premium, an enterprise-grade UI library with 120+ free and premium components for building polished, performant apps. Test-drive all features with a free 30-day trial.Start Free Trial

After completing this guide, you will be able to reproduce the following example.

Change Theme
Theme
Loading ...

Before You Begin

sh
npm create vite@latest my-app -- --template react

This guide requires that you have basic knowledge of React and TypeScript, and that you have already created a blank React project.

You can speed up the development of your KendoReact application with the Kendo UI Template Wizard for Visual Studio Code.

Install the Component

sh
npm i @progress/kendo-react-sortable

Importing the Component

After installing the package, import the Sortable component in the React App.

In the src/App.js file of your React project, import the Sortable component from the Sortable package.

jsx
// ES2015 module syntax
import { Sortable } from "@progress/kendo-react-sortable";
jsx
// CommonJS format
const { Sortable } = require('@progress/kendo-react-sortable');

Using the Component

  1. Create a state variable for the sortable items.

    jsx
    const [data, setData] = React.useState([
        {
            id: 1,
            text: 'item1'
        },
        {
            id: 2,
            text: 'item2'
        },
        {
            id: 3,
            text: 'item3'
        }
    ]);
  2. Create a component that you will use for each of the items in the Sortable.

    jsx
    const SortableItemUI = (props) => {
        const { attributes, dataItem, forwardRef, isActive, style } = props;
    
        return (
            <div ref={forwardRef} {...attributes} style={{ ...getBaseItemStyle(isActive), ...style }}>
                {dataItem.text}
            </div>
        );
    };
  3. Add styles for the item based on its isActive status.

    jsx
    const getBaseItemStyle = (isActive) => ({
        height: 70,
        lineHeight: '68px',
        fontSize: '16px',
        textAlign: 'center',
        outline: 'none',
        border: '1px solid',
        cursor: 'move',
        display: 'block',
        width: 200,
        background: isActive ? '#27aceb' : '#bfe7f9',
        color: isActive ? '#fff' : '#1494d0',
        borderColor: isActive ? '#27aceb' : '#fff'
    });
  4. Handle the onDragOver) event of the Sortable. Use that event to get the new order of the item after sorting.

    jsx
    const onDragOver = (event) => {
        setData(event.newState);
    };
  5. To style the Sortable, install and import the Default theme, which is one of the three beautiful themes for KendoReact.

    5.1. Install the Default theme package.

    sh
    npm i @progress/kendo-theme-default

    5.2. Import the CSS file from the package in src/App.js. Add this import before your existing App.css import.

    jsx
    import '@progress/kendo-theme-default/dist/all.css';
  6. Build and run the application by typing the following command in the root folder of your project:

    sh
    npm start
  7. Navigate to http://localhost:3000 to see the KendoReact Sortable component on the page.

Activating Your License Key

Using any of the UI components in the KendoReact library requires either a commercial license key or an active trial license key.

Follow the instructions on the KendoReact My License page to activate your trial or commercial license. You can skip this step if your application already contains a KendoReact license file.

Dependencies

The Sortable package requires you to install the following peer dependencies in your application:

Package NameDescription
react 16.8.2*Contains the functionality necessary to define React components.
react-domContains the React renderer for the web.
@progress/kendo-licensingContains the internal infrastructure related to licensing.

Learning Resources