Column Widths

By default, the KendoReact TreeList is responsive and has no fix width—the component behaves like an HTML table and expands to the width of the parent element.

Getting Started

By default, the TreeList will equally divide its width between its columns and it will responsively expand or shrink them when the width of its parent container is changed.

  • To set the column widths of the TreeList, use the width property of the TreeListColumnProps. The width values will be passed to the HTML col elements of the underlying table element as they are.
  • To set the width of the TreeList wrapper element, use the TreeList style property.
  • To set the width and any other property of the underlying HTML table, use the tableProps property of the TreeList which allows you to quickly resize the TreeList in the desired units.

Setting Column Widths in Percentage

To set the TreeList column widths in percentage, set the width values through the width property of the TreeListColumnProps. The width of the wrapper and table HTML block elements of the TreeList defaults to auto and the browser will expand them according to the available space. If your project requires you to limit the TreeList width, set the wrapper width through the TreeList style property.

import React from 'react';
import ReactDOM from 'react-dom';

import {
    TreeList,
    createDataTree,
    mapTree,
    extendDataItem,
} from '@progress/kendo-react-treelist';

import employees from './data';

const expandField = 'expanded';
const subItemsField = 'employees';

class App extends React.Component {
    state = {
        data: [ ...employees ],
        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 ]
        });
    }

    render() {
        const { data, expanded } = this.state;
        const callback = item =>
            expanded.includes(item.id) ? extendDataItem(item, subItemsField, { [expandField]: true }) : item;

        return (
            <TreeList
                style={{ maxHeight: '510px', overflow: 'auto', width: '70%' }}
                data={mapTree(data, subItemsField, callback)}
                expandField={expandField}
                subItemsField={subItemsField}
                onExpandChange={this.onExpandChange}
                columns={[
                    { field: 'name', title: 'Name', expandable: true, width: '40%' },
                    { field: 'position', title: 'Position', width: '40%' },
                    { field: 'hireDate', title: 'Hire Date', format: '{0:d}', width: '20%' }
                ]}
            />
        );
    }
}

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

Setting Fixed Column Width

To set the TreeList column widths in pixels, set the width values through the width property of the TreeListColumnProps, and the wrapper and table HTML widths which will be the sum of the widths of all columns.

import React from 'react';
import ReactDOM from 'react-dom';

import {
    TreeList,
    createDataTree,
    mapTree,
    extendDataItem,
} from '@progress/kendo-react-treelist';

import employees from './data';

const expandField = 'expanded';
const subItemsField = 'employees';

class App extends React.Component {
    state = {
        data: [ ...employees ],
        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 ]
        });
    }

    render() {
        const { data, expanded } = this.state;
        const callback = item =>
            expanded.includes(item.id) ? extendDataItem(item, subItemsField, { [expandField]: true }) : item;

        return (
            <TreeList
                style={{ maxHeight: '510px', overflow: 'auto', width: '820px' }}
                tableProps={{ style: { width: '800px' } }}
                data={mapTree(data, subItemsField, callback)}
                expandField={expandField}
                subItemsField={subItemsField}
                onExpandChange={this.onExpandChange}
                columns={[
                    { field: 'name', title: 'Name', expandable: true, width: '300px' },
                    { field: 'position', title: 'Position', width: '300px' },
                    { field: 'hireDate', title: 'Hire Date', format: '{0:d}', width: '200px' }
                ]}
            />
        );
    }
}

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