Getting Started with KendoReact TreeList

The KendoReact TreeList enables the display of self-referencing tabular data and allows sorting, filtering, and data editing.

The KendoReact TreeList component is part of the KendoReact library of React UI components. It is distributed through NPM under the kendo-react-treelist package.

Basic Usage

The following example demonstrates the TreeList in action.

import React from 'react';
import ReactDOM from 'react-dom';
import {
    TreeList, orderBy, filterBy, mapTree, extendDataItem,
    TreeListTextFilter, TreeListNumericFilter, TreeListDateFilter, TreeListBooleanFilter
} from '@progress/kendo-react-treelist';
import employees from './data';

const subItemsField = 'employees';
const expandField = 'expanded';
const columns = [
    { field: 'name', title: 'Name', width: 250, filter: TreeListTextFilter, expandable: true },
    { field: 'hireDate', title: 'Hire Date', width: 200, format: '{0:d}', filter: TreeListDateFilter },
    { field: 'timeInPosition', title: 'Year(s) in Position', width: 200, filter: TreeListNumericFilter },
    { field: 'fullTime', title: 'Full Time', width: 100, filter: TreeListBooleanFilter }
];

class App extends React.Component {
    state = {
        data: [ ...employees ],
        dataState: {
            sort: [
                { field: 'name', dir: 'asc' }
            ],
            filter: []
        },
        expanded: [1, 2, 32]
    }

    onExpandChange = (e) => {
        this.setState({
            expanded: e.value ?
                this.state.expanded.filter(id => id !== e.dataItem.id) :
                [ ...this.state.expanded, e.dataItem.id ]
        });
    }

    handleDataStateChange = (event) => {
        this.setState({
            dataState: event.data
        })
    }

    addExpandField = (dataTree) => {
        const expanded = this.state.expanded;
        return mapTree(dataTree, subItemsField, (item) =>
            extendDataItem(item, subItemsField, {
                [expandField]: expanded.includes(item.id)
            })
        );
    }

    processData = () => {
        let { data, dataState } = this.state;
        let filteredData = filterBy(data, dataState.filter, subItemsField)
        let sortedData = orderBy(filteredData, dataState.sort, subItemsField)
        return this.addExpandField(sortedData);
    }

    render() {
        return (
            <TreeList
                style={{ maxHeight: '510px', overflow: 'auto' }}
                expandField={expandField}
                subItemsField={subItemsField}
                onExpandChange={this.onExpandChange}
                sortable={{ mode: 'multiple' }}
                {...this.state.dataState}
                data={this.processData()}
                onDataStateChange={this.handleDataStateChange}
                columns={columns}
            />
        );
    }
}

ReactDOM.render(
    <App />,
    document.querySelector('my-app')
);

Functionality and Features

Installation

  1. Download and install the package. Use Node.js v5.0.0 or later.

    npm install --save @progress/kendo-react-treelist @progress/kendo-data-query @progress/kendo-react-inputs @progress/kendo-react-intl @progress/kendo-react-dropdowns @progress/kendo-react-dateinputs
  2. Once installed, import the package module.

    // ES2015 module syntax
    import { TreeList } from '@progress/kendo-react-treelist';
    // CommonJS format
    const { TreeList } = require('@progress/kendo-react-treelist');
  3. You are required to install one of the Kendo UI themes to style your components. For more information on how to add the styles, refer to the article on getting started.

Dependencies

The TreeList package requires the following peer dependencies that have to be installed by your application:

  • react 16.8.2*
  • react-dom
  • @progress/kendo-data-query
  • @progress/kendo-react-dateinputs
  • @progress/kendo-react-dropdowns
  • @progress/kendo-react-inputs
  • @progress/kendo-react-intl
 /