Your search did not match any results.
Data Grid

Web API Service

Documentation

This example demonstrates the DataGrid widget communicating with a Web API service. All data editing and data processing operations are delegated to the server. The DevExtreme.AspNet.Data extension’s DevExpress.data.AspNet.createStore method configures access to the server from the client. The server implementation is available under the DataGridWebApiController tab in the ASP.NET MVC version of this demo.

Copy to CodeSandBox
Apply
Reset
<template> <DxDataGrid :show-borders="true" :data-source="dataSource" :remote-operations="true" :height="600" > <DxColumn data-field="CustomerID" caption="Customer" > <DxLookup :data-source="customersData" value-expr="Value" display-expr="Text" /> <DxStringLengthRule :max="5" message="The field Customer must be a string with a maximum length of 5." /> </DxColumn> <DxColumn data-field="OrderDate" data-type="date" > <DxRequiredRule message="The OrderDate field is required."/> </DxColumn> <DxColumn data-field="Freight"> <DxHeaderFilter :group-interval="100"/> <DxRangeRule :min="0" :max="2000" message="The field Freight must be between 0 and 2000." /> </DxColumn> <DxColumn data-field="ShipCountry"> <DxStringLengthRule :max="15" message="The field ShipCountry must be a string with a maximum length of 15." /> </DxColumn> <DxColumn data-field="ShipVia" caption="Shipping Company" data-type="number" > <DxLookup :data-source="shippersData" value-expr="Value" display-expr="Text" /> </DxColumn> <DxMasterDetail :enabled="true" template="masterDetailTemplate" /> <template #masterDetailTemplate="{ data: order }"> <MasterDetailGrid :id="order.key" :url="url" /> </template> <DxFilterRow :visible="true"/> <DxHeaderFilter :visible="true"/> <DxGroupPanel :visible="true"/> <DxScrolling mode="virtual"/> <DxEditing :allow-adding="true" :allow-updating="true" :allow-deleting="true" mode="row" /> <DxGrouping :auto-expand-all="false"/> <DxSummary> <DxTotalItem column="Freight" summary-type="sum" > <DxValueFormat :precision="2" type="decimal" /> </DxTotalItem> <DxGroupItem column="Freight" summary-type="sum" > <DxValueFormat :precision="2" type="decimal" /> </DxGroupItem> <DxGroupItem summary-type="count"/> </DxSummary> </DxDataGrid> </template> <script> import { DxDataGrid, DxColumn, DxEditing, DxFilterRow, DxHeaderFilter, DxGroupPanel, DxGrouping, DxScrolling, DxSummary, DxLookup, DxTotalItem, DxGroupItem, DxMasterDetail, DxStringLengthRule, DxRequiredRule, DxRangeRule, DxValueFormat } from 'devextreme-vue/data-grid'; import MasterDetailGrid from 'MasterDetailGrid.vue'; import { createStore } from 'devextreme-aspnet-data-nojquery'; const url = 'https://js.devexpress.com/Demos/Mvc/api/DataGridWebApi'; const dataSource = createStore({ key: 'OrderID', loadUrl: `${url}/Orders`, insertUrl: `${url}/InsertOrder`, updateUrl: `${url}/UpdateOrder`, deleteUrl: `${url}/DeleteOrder`, onBeforeSend: (method, ajaxOptions) => { ajaxOptions.xhrFields = { withCredentials: true }; } }); const customersData = createStore({ key: 'Value', loadUrl: `${url}/CustomersLookup`, onBeforeSend: (method, ajaxOptions) => { ajaxOptions.xhrFields = { withCredentials: true }; } }); const shippersData = createStore({ key: 'Value', loadUrl: `${url}/ShippersLookup`, onBeforeSend: (method, ajaxOptions) => { ajaxOptions.xhrFields = { withCredentials: true }; } }); export default { components: { DxDataGrid, DxColumn, DxEditing, DxFilterRow, DxHeaderFilter, DxGroupPanel, DxGrouping, DxScrolling, DxSummary, DxLookup, DxTotalItem, DxGroupItem, DxMasterDetail, DxStringLengthRule, DxRangeRule, DxRequiredRule, DxValueFormat, MasterDetailGrid }, data() { return { url, customersData, shippersData, dataSource }; } }; </script>
<template> <DxDataGrid :data-source="dataSource" :show-borders="true" /> </template> <script> import DxDataGrid from 'devextreme-vue/data-grid'; import { createStore } from 'devextreme-aspnet-data-nojquery'; const getMasterDetailGridDataSource = (id, url) => { return { store: createStore({ loadUrl: `${url}/OrderDetails`, loadParams: { orderID: id }, onBeforeSend: (method, ajaxOptions) => { ajaxOptions.xhrFields = { withCredentials: true }; } }) }; }; export default { components: { DxDataGrid }, props: { id: { type: Number, default: () => 0 }, url: { type: String, default: () => '' } }, data() { return { dataSource: getMasterDetailGridDataSource(this.id, this.url) }; } }; </script>
import Vue from 'vue'; import App from './App.vue'; new Vue({ el: '#app', components: { App }, template: '<App/>' });
<!DOCTYPE html> <html> <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" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/20.1.3/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/20.1.3/css/dx.light.css" /> <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <script src="https://unpkg.com/systemjs@0.21.3/dist/system.js"></script> <script type="text/javascript" src="config.js"></script> <script type="text/javascript"> System.import('./index.js'); </script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"/> </div> </body> </html>
System.config({ transpiler: 'plugin-babel', meta: { '*.vue': { loader: 'vue-loader' }, 'devextreme-aspnet-data-nojquery': { "esModule": true }, }, paths: { 'npm:': 'https://unpkg.com/' }, map: { 'vue': 'npm:vue@2.6.3/dist/vue.esm.browser.js', 'vue-loader': 'npm:dx-systemjs-vue-browser@latest/index.js', 'devextreme-aspnet-data-nojquery': 'npm:devextreme-aspnet-data-nojquery@2.6.1', 'devextreme': 'npm:devextreme@20.1', 'devextreme-vue': 'npm:devextreme-vue@20.1', 'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.7/dist/quill.js', 'devexpress-diagram': 'npm:devexpress-diagram@1.0.0', 'devexpress-gantt': 'npm:devexpress-gantt@1.0.0', 'plugin-babel': 'npm:systemjs-plugin-babel@0/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0/systemjs-babel-browser.js' }, packages: { 'devextreme-vue': { main: 'index.js' }, 'devextreme': { defaultExtension: 'js' }, 'devextreme/events/utils': { main: 'index' }, 'devextreme/events': { main: 'index' }, }, babelOptions: { sourceMaps: false, stage0: true } });