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.
The key for the row being edited.
The name or data field of the column being edited.
Pending row changes.
You can get and set these properties at runtime to access and change edit state. In this demo, the onOptionChanged function gets editRowKey and changes property values and displays them under the DataGrid.
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:
Disable built-in edit state management
e.cancel field to true.
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.
Apply the same changes to a local array
If the server successfully saves changes, call the applyChanges method to save the same changes in a local array.
Update the DataGrid's data source and reset edit state
Assign the local array to the dataSource, null to the editRowKey, and an empty array to the changes property.