Your search did not match any results.
Data Grid

Batch Update Request

With the DevExtreme DataGrid, users can modify multiple records and submit all changes simultaneously (when editing.mode is set to "batch"). Batch editing allows you to optimize your app, address performance related issues, and deliver the best possible user experience across a variety of usage scenarios.

If data is stored on a server, our DataGrid sends multiple requests to save edited objects - one request per object (this is because most servers only process one edit operation at a time). If your server supports batch update, you can configure the DataGrid to save all changes with a single request.

To incorporate this functionality into your web app, implement the DataGrid's onSaving function. This function accepts an e object that contains fields used for batch update. The following is a summary of the steps you must follow to enable batch update:

  1. Disable default save logic
    Set the e.cancel field to true.

  2. Send pending changes to the server
    Pending changes are contained in the e.changes array. Ensure it is not empty and send the changes to the server.

  3. Update data in the widget
    Once changes are saved, call the refresh(changesOnly) method.

  4. Reset edit state
    Use the cancelEditData() method to clear pending changes.

Copy to CodePen
Apply
Reset
$(function () { var URL = "https://js.devexpress.com/Demos/Mvc/api/DataGridBatchUpdateWebApi"; $("#gridContainer").dxDataGrid({ dataSource: DevExpress.data.AspNet.createStore({ key: "OrderID", loadUrl: URL + "/Orders", onBeforeSend: function (method, ajaxOptions) { ajaxOptions.xhrFields = { withCredentials: true }; }, }), showBorders: true, editing: { mode: "batch", allowAdding: true, allowUpdating: true, allowDeleting: true }, remoteOperations: true, repaintChangesOnly: true, onSaving: function (e) { e.cancel = true; if (e.changes.length) { e.promise = sendBatchRequest(URL + "/Batch", e.changes).done(() => { e.component.refresh(true).done(() => { e.component.cancelEditData(); }); }); } }, columns: [{ dataField: "OrderID", allowEditing: false }, { dataField: "ShipName" }, { dataField: "ShipCountry" }, { dataField: "ShipCity" }, { dataField: "ShipAddress" }, { dataField: "OrderDate", dataType: "date" }, { dataField: "Freight" }] }); function sendBatchRequest(url, changes) { var d = $.Deferred(); $.ajax(url, { method: "POST", data: JSON.stringify(changes), cache: false, contentType: "application/json", xhrFields: { withCredentials: true } }).done(d.resolve).fail(function (xhr) { d.reject(xhr.responseJSON ? xhr.responseJSON.Message : xhr.statusText); }); return d.promise(); } });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <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="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></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="https://cdn3.devexpress.com/jslib/20.2.3/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/20.2.3/css/dx.light.css" /> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="https://cdn3.devexpress.com/jslib/20.2.3/js/dx.all.js"></script> <script src="https://unpkg.com/devextreme-aspnet-data@2.7.1/js/dx.aspnet.data.js"></script> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="gridContainer"></div> </div> </body> </html>
#gridContainer { height: 440px; }