Your search did not match any results.
DataGrid

CRUD Operations

Documentation

This demo shows how to implement remote CRUD operations in the CustomStore. You can view the server implementation under the DataGridWebApiController tab in the ASP.NET MVC version of this demo. The requests sent to the server are displayed under the DataGrid.

After a cell is edited, the DataGrid can behave differently depending on the selected refresh mode: reload data from the server (the refreshMode is full), reapply data processing operations (reshape), or merely rerender the changed cells (repaint).

Copy to CodePen
Apply
Reset
$(function(){ var URL = "https://js.devexpress.com/Demos/Mvc/api/DataGridWebApi"; var ordersStore = new DevExpress.data.CustomStore({ key: "OrderID", load: function() { return sendRequest(URL + "/Orders"); }, insert: function(values) { return sendRequest(URL + "/InsertOrder", "POST", { values: JSON.stringify(values) }); }, update: function(key, values) { return sendRequest(URL + "/UpdateOrder", "PUT", { key: key, values: JSON.stringify(values) }); }, remove: function(key) { return sendRequest(URL + "/DeleteOrder", "DELETE", { key: key }); } }); var dataGrid = $("#grid").dxDataGrid({ dataSource: ordersStore, repaintChangesOnly: true, showBorders: true, editing: { refreshMode: "reshape", mode: "cell", allowAdding: true, allowUpdating: true, allowDeleting: true }, scrolling: { mode: "virtual" }, columns: [{ dataField: "CustomerID", caption: "Customer", lookup: { dataSource: { paginate: true, store: new DevExpress.data.CustomStore({ key: "Value", loadMode: "raw", load: function() { return sendRequest(URL + "/CustomersLookup"); } }) }, valueExpr: "Value", displayExpr: "Text" } }, { dataField: "OrderDate", dataType: "date" }, { dataField: "Freight" }, { dataField: "ShipCountry" }, { dataField: "ShipVia", caption: "Shipping Company", dataType: "number", lookup: { dataSource: new DevExpress.data.CustomStore({ key: "Value", loadMode: "raw", load: function() { return sendRequest(URL + "/ShippersLookup"); } }), valueExpr: "Value", displayExpr: "Text" } } ], summary: { totalItems: [{ column: "CustomerID", summaryType: "count" }, { column: "Freight", valueFormat: "#0.00", summaryType: "sum" }] } }).dxDataGrid("instance"); $("#refresh-mode").dxSelectBox({ items: ["full", "reshape", "repaint"], value: "reshape", onValueChanged: function(e) { dataGrid.option("editing.refreshMode", e.value); } }); $("#clear").dxButton({ text: "Clear", onClick: function() { $("#requests ul").empty(); } }); function sendRequest(url, method, data) { var d = $.Deferred(); method = method || "GET"; logRequest(method, url, data); $.ajax(url, { method: method || "GET", data: data, cache: false, xhrFields: { withCredentials: true } }).done(function(result) { d.resolve(method === "GET" ? result.data : result); }).fail(function(xhr) { d.reject(xhr.responseJSON ? xhr.responseJSON.Message : xhr.statusText); }); return d.promise(); } function logRequest(method, url, data) { var args = Object.keys(data || {}).map(function(key) { return key + "=" + data[key]; }).join(" "); var logList = $("#requests ul"), time = DevExpress.localization.formatDate(new Date(), "HH:mm:ss"), newItem = $("<li>").text([time, method, url.slice(URL.length), args].join(" ")); logList.prepend(newItem); } });
<!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.1.0/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/18.2.3/css/dx.common.css" /> <link rel="dx-theme" data-theme="generic.light" href="https://cdn3.devexpress.com/jslib/18.2.3/css/dx.light.css" /> <script src="https://cdn3.devexpress.com/jslib/18.2.3/js/dx.all.js"></script> <link rel="stylesheet" type ="text/css" href ="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="grid"></div> <div class="options"> <div class="caption">Options</div> <div class="option"> <span>Refresh Mode:</span> <div id="refresh-mode"></div> </div> <div id="requests"> <div> <div class="caption">Network Requests</div> <div id="clear"></div> </div> <ul></ul> </div> </div> </div> </body> </html>
#grid { 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; top: 2px; margin-right: 10px; } .option > .dx-widget { display: inline-block; vertical-align: middle; } #requests .caption { float: left; padding-top: 7px; } #requests > div { padding-bottom: 5px; } #requests > div:after { content: ""; display: table; clear: both; } #requests #clear { float: right; } #requests ul { list-style: none; max-height: 100px; overflow: auto; margin: 0; } #requests ul li { padding: 7px 0; border-bottom: 1px solid #dddddd; } #requests ul li:last-child { border-bottom: none; }