Editing Basics

You can create, update, and delete the data records of the TreeList.


Getting Started

  1. Set the editField property of the TreeList—editField will indicate the editable data items and is part of the temporary data items that are used during editing. For the data items in the edit mode, set the edit state in their editField. In the following example, the id of the edited item is stored in the application state.

        <TreeList
            editField="inEdit"
        dataItem.inEdit = true;
  2. Create a new data tree which has the edit state of each data item by using the mapTree function.

        <TreeList
            editField="inEdit"
            data={
                mapTree(data, subItemsField, item =>
                    extendDataItem(item, subItemsField, {
                        inEdit: item.id === this.state.editId
                    })
                )
            }
  3. Set the editCell property per column. The built-in editor components are the TreeListTextEditor, TreeListNumericEditor, TreeListDateEditor, and TreeListBooleanEditor. The usage of each component for each column depends on the type of the edited data.

        <TreeList
            columns={[
                { field: 'name', editCell: TreeListTextEditor, ... },
                { field: 'position', editCell: TreeListTextEditor, ... },
                { field: 'hireDate', editCell: TreeListDateEditor, ... },
                { field: 'timeInPosition', editCell: TreeListNumericEditor, ... },
                { field: 'fullTime', editCell: TreeListBooleanEditor, ... }
            ]}
  4. Define a function for the onItemChange event which will handle the data changes during editing. Inside the event, all relevant data, such as the edited data item, the newly entered value, or the edited field will be available as onItemChange parameters.

         <TreeList onItemChange={this.onItemChange}>
        onItemChange = (event) => {
            this.setState({
                data: mapTree(
                    this.state.data,
                    subItemsField,
                    item => item.id === event.dataItem.id ?
                        extendDataItem(item, subItemsField, { [event.field]: event.value }) : item
                )
            });
        }

The following example demonstrates how to set the TreeList in edit mode.

Example
View Source
Change Theme:

Edit Modes

In this article

Not finding the help you need?