DevExtreme v24.2 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

React Data Grid - Edit State Management

Our DataGrid component manages its edit state automatically. If your use case requires full control over the editing process, you can use the API members below to manage state manually. In this demo, we manage state with a help of the useReducer React hook.

To give you the ability to edit code on the fly, the demo uses SystemJS. For this reason, launching the demo takes some time. We strongly recommend that you do not use this approach in real projects.
Backend API

Component Properties

  • editing.editRowKey
    The key for the row being edited.

  • editing.editColumnName
    The name or data field of the column being edited.

  • editing.changes
    Pending row changes.

Bind these properties to state props and set the props to change edit state at runtime. In this demo, we bind the editRowKey and changes properties and use the corresponding on_OptionName_Change event handlers to set the bound props.

Utility Method

Event Handlers

  • onSaving / onSaved
    Functions that are called before / after pending row changes are saved via the UI or programmatically.

  • onEditCanceling / onEditCanceled
    Functions that are called before / after editing is canceled and pending row changes are discarded.

Use these functions to perform custom actions. In this demo, the onSaving function sends pending changes to a server. The function's parameter e contains fields for this capability. To implement the same in your application, follow these steps:

  1. Disable built-in edit state management
    Set the e.cancel field to true.

  2. Send a request to the server
    Pending changes are stored in the e.changes array. This array has only a single element in all edit modes, except for batch. Check if this element is not empty and send it to the server (see the saveChange action in actions.js).

  3. Apply the same changes to the DataGrid's data source and reset edit state
    If the server successfully saves changes, call the applyChanges method to save the same changes in the DataGrid's data source. Assign null to the editRowKey and an empty array to the changes property. This resets edit state (see the SAVING_SUCCESS handler in reducer.js).