Editing BasicsPremium
You can create, update, and delete the data records of the TreeList.
Getting Started
-
Set the
editFieldproperty of the TreeList—editFieldwill 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 theireditField. In the following example, the id of the edited item is stored in the application state.jsx<TreeList editField="inEdit"jsxdataItem.inEdit = true; -
Create a new data tree which has the edit state of each data item by using the
mapTreefunction.jsx<TreeList editField="inEdit" data={ mapTree(data, subItemsField, item => extendDataItem(item, subItemsField, { inEdit: item.id === this.state.editId }) ) } -
Set the
editCellproperty per column. The built-in editor components are theTreeListTextEditor,TreeListNumericEditor,TreeListDateEditor, andTreeListBooleanEditor. The usage of each component for each column depends on the type of the edited data.jsx<TreeList columns={[ { field: 'name', editCell: TreeListTextEditor, ... }, { field: 'position', editCell: TreeListTextEditor, ... }, { field: 'hireDate', editCell: TreeListDateEditor, ... }, { field: 'timeInPosition', editCell: TreeListNumericEditor, ... }, { field: 'fullTime', editCell: TreeListBooleanEditor, ... } ]} -
Define a function for the
onItemChangeevent 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 asonItemChangeparameters.jsx<TreeList onItemChange={this.onItemChange}>jsxonItemChange = (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.