Your search did not match any results.
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.

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.

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.

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.

  3. 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.

  4. 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.

Backend API
Copy to CodePen
$(function () { var URL = ""; var loadPanel = $("#loadPanel").dxLoadPanel({ position: { of: "#gridContainer" }, visible: false }).dxLoadPanel("instance");; sendRequest(URL + "/Orders?skip=700") .always(function() { loadPanel.hide(); }) .then(function(data) { dataGrid.option("dataSource", data); }); var dataGrid = $("#gridContainer").dxDataGrid({ keyExpr: "OrderID", showBorders: true, dataSource: [], editing: { mode: "row", allowAdding: true, allowUpdating: true, allowDeleting: true }, repaintChangesOnly: true, onOptionChanged: function(e) { if( === "editing") { var editRowKey = e.component.option("editing.editRowKey"), changes = e.component.option("editing.changes"); $("#editRowKey").text(editRowKey === null ? "null" : editRowKey); changes = { return { type: change.type, key: change.type !== "insert" ? change.key : undefined, data: }; }); $("#changes").text(JSON.stringify(changes, null, " ")); } }, onSaving: function(e) { var change = e.changes[0]; if (change) { e.cancel = true;; e.promise = saveChange(URL, change) .always(function() { loadPanel.hide(); }) .then(function(data) { var orders = e.component.option("dataSource"); if(change.type === "insert") { = data; } orders =, [change], { keyExpr: "OrderID" }); e.component.option({ dataSource: orders, editing: { editRowKey: null, changes: [] } }); }); } }, columns: [{ dataField: "OrderID", allowEditing: false }, { dataField: "ShipName" }, { dataField: "ShipCountry" }, { dataField: "ShipCity" }, { dataField: "ShipAddress" }, { dataField: "OrderDate", dataType: "date" }, { dataField: "Freight" }] }).dxDataGrid("instance"); function saveChange(url, change) { switch (change.type) { case "insert": return sendRequest(url + "/InsertOrder", "POST", { values: JSON.stringify( }); case "update": return sendRequest(url + "/UpdateOrder", "PUT", { key: change.key, values: JSON.stringify( }); case "remove": return sendRequest(url + "/DeleteOrder", "DELETE", { key: change.key }); } } function sendRequest(url, method, data) { var d = $.Deferred(); method = method || "GET"; $.ajax(url, { method: method, data: data, cache: false, xhrFields: { withCredentials: true } }).then(function (result) { d.resolve(method === "GET" ? : result); }, function (xhr) { d.reject(xhr.responseJSON ? xhr.responseJSON.Message : xhr.statusText); }); return d.promise(); } });
<!DOCTYPE html> <html xmlns=""> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <script src=""></script> <script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script> <link rel="stylesheet" type="text/css" href="" /> <link rel="stylesheet" type="text/css" href="" /> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src=""></script> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="loadPanel"></div> <div id="gridContainer"></div> <div class="options"> <div class="caption">Options</div> <div class="option"> <span>Edit Row Key:</span> <div id="editRowKey">null</div> </div> <div class="option"> <span>Changes:</span> <div id="changes">[]</div> </div> </div> </div> </body> </html>
#gridContainer { height: 440px; } .options { padding: 20px; margin-top: 20px; background-color: rgba(191, 191, 191, 0.15); } .caption { margin-bottom: 10px; font-weight: 500; font-size: 18px; } .option { margin-bottom: 10px; } .option > span { position: relative; margin-right: 10px; } .option > div { display: inline-block; font-weight: bold; }