Your search did not match any results.
Data Grid

Advanced Master-Detail View

This demo illustrates an advanced master-detail view in the DataGrid widget. Master rows represent suppliers. Detail sections contain TabPanel widgets with two tabs: Orders and Address. In the Orders tab, you can choose a supplier's product from the SelectBox, and the DataGrid under it will show orders placed on this product. The Address tab displays the supplier's address.

Copy to CodeSandBox
Apply
Reset
<template> <dx-form :form-data="data" :items="items" :col-count="2" :customize-item="customizeItem" class="address-form form-container" > <template #form-item="{ data: item }"> <span> {{ item.editorOptions.value }} </span> </template> </dx-form> </template> <script> import { DxForm } from 'devextreme-vue/form'; export default { components: { DxForm }, props: { data: { type: Object, default: () => ({}) } }, data() { return { items: ['Address', 'City', 'Region', 'PostalCode', 'Country', 'Phone'] }; }, methods: { customizeItem(item) { item.template = 'form-item'; } } }; </script>
<template> <dx-data-grid id="gridContainer" :data-source="suppliersData" :remote-operations="true" :show-borders="true" > <dx-paging :page-size="15"/> <dx-column data-field="ContactName"/> <dx-column data-field="ContactTitle"/> <dx-column data-field="CompanyName"/> <dx-column data-field="City"/> <dx-column data-field="Country"/> <dx-master-detail :enabled="true" template="master-detail" /> <template #master-detail="{ data }"> <master-detail :master-detail-data="data"/> </template> </dx-data-grid> </template> <script> import { DxDataGrid, DxColumn, DxPaging, DxMasterDetail, } from 'devextreme-vue/data-grid'; import MasterDetail from './MasterDetail.vue'; import { createStore } from 'devextreme-aspnet-data-nojquery'; const url = 'https://js.devexpress.com/Demos/Mvc/api/DataGridAdvancedMasterDetailView'; export default { components: { DxDataGrid, DxColumn, DxPaging, DxMasterDetail, MasterDetail }, data() { return { suppliersData: createStore({ key: 'SupplierID', loadUrl: `${url}/GetSuppliers` }) }; } }; </script>
<template> <dx-tab-panel> <dx-item title="Orders" template="orders-tab" /> <orders-tab slot="orders-tab" :supplier-id="masterDetailData.key" /> <dx-item title="Address" template="address-tab" /> <address-tab slot="address-tab" :data="masterDetailData.data" /> </dx-tab-panel> </template> <script> import { DxTabPanel, DxItem } from 'devextreme-vue/tab-panel'; import OrdersTab from './OrdersTab.vue'; import AddressTab from './AddressTab.vue'; export default { components: { DxTabPanel, DxItem, OrdersTab, AddressTab }, props: { masterDetailData: { type: Object, default: () => ({}) } } }; </script>
<template> <div> <dx-data-grid :data-source="orderHistoryStore" :show-borders="true" > <dx-paging :page-size="5"/> <dx-column data-field="OrderID"/> <dx-column data-field="OrderDate" data-type="date" /> <dx-column data-field="ShipCountry"/> <dx-column data-field="ShipCity"/> <dx-column data-field="UnitPrice" format="currency" /> <dx-column data-field="Quantity"/> <dx-column data-field="Discount" format="percent" /> <dx-summary> <dx-total-item column="UnitPrice" summary-type="sum" > <dx-value-format :precision="2" format="currency" /> </dx-total-item> <dx-total-item column="Quantity" summary-type="count" /> </dx-summary> </dx-data-grid> </div> </template> <script> import { DxDataGrid, DxColumn, DxPaging, DxSummary, DxTotalItem, DxValueFormat } from 'devextreme-vue/data-grid'; import { createStore } from 'devextreme-aspnet-data-nojquery'; const url = 'https://js.devexpress.com/Demos/Mvc/api/DataGridAdvancedMasterDetailView'; export default { components: { DxDataGrid, DxColumn, DxPaging, DxSummary, DxTotalItem, DxValueFormat }, props: { productId: { type: Number, default: null } }, computed: { orderHistoryStore() { return this.productId === null ? null : { store: createStore({ key: 'OrderID', loadParams: { ProductID: this.productId }, loadUrl: `${url}/GetOrdersByProduct` }) }; } } }; </script>
<template> <dx-form label-location="top" class="form-container" > <dx-item template="select-box"> <dx-label text="Product"/> </dx-item> <product-select-box slot="select-box" :supplier-id="supplierId" @product-changed="chosenProductId = $event" /> <dx-item template="order-history"> <dx-label text="Order History"/> </dx-item> <template #order-history="{ data }"> <order-history :product-id="chosenProductId" /> </template> </dx-form> </template> <script> import { DxForm, DxItem, DxLabel } from 'devextreme-vue/form'; import ProductSelectBox from './ProductSelectBox.vue'; import OrderHistory from './OrderHistory.vue'; export default { components: { DxForm, DxItem, DxLabel, ProductSelectBox, OrderHistory }, props: { supplierId: { type: Number, default: null } }, data() { return { chosenProductId: null }; } }; </script>
<template> <dx-select-box :defer-rendering="false" :data-source="dataSource" :value="value" value-expr="ProductID" display-expr="ProductName" @valueChanged="$emit('product-changed', $event.value)" /> </template> <script> import { DxSelectBox } from 'devextreme-vue'; import { createStore } from 'devextreme-aspnet-data-nojquery'; const url = 'https://js.devexpress.com/Demos/Mvc/api/DataGridAdvancedMasterDetailView'; export default { components: { DxSelectBox }, props: { supplierId: { type: Number, default: null } }, data() { return { dataSource: createStore({ key: 'ProductID', loadParams: { SupplierID: this.supplierId }, loadUrl: `${url}/GetProductsBySupplier`, onLoaded: this.setDefaultValue }), value: null }; }, methods: { setDefaultValue(items) { let firstItem = items[0]; if(firstItem && this.value === null) { this.value = firstItem.ProductID; } } } }; </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/19.1.7/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.1.7/css/dx.light.css" /> <link rel="stylesheet" type="text/css" href="styles.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>
#gridContainer { height: 620px; } .dx-datagrid-rowsview .dx-master-detail-row:not(.dx-datagrid-edit-form) > .dx-datagrid-group-space, .dx-datagrid-rowsview .dx-master-detail-row:not(.dx-datagrid-edit-form) .dx-master-detail-cell { background-color: transparent; } .form-container { padding: 20px; } .address-form label { font-weight: bold; }
System.config({ transpiler: 'plugin-babel', 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': 'npm:devextreme@19.2', 'devextreme-vue': 'npm:devextreme-vue@19.2', jszip: 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.7/dist/quill.js', 'devexpress-diagram': 'npm:devexpress-diagram', 'devexpress-gantt': 'npm:devexpress-gantt', 'devextreme-aspnet-data-nojquery': 'npm:devextreme-aspnet-data-nojquery@2.5.1', 'plugin-babel': 'npm:systemjs-plugin-babel@0/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0/systemjs-babel-browser.js' }, meta: { '*.vue': { loader: 'vue-loader' }, 'devextreme-aspnet-data-nojquery': { 'esModule': true } }, packages: { 'devextreme-vue': { main: 'index.js' }, 'devextreme': { defaultExtension: 'js' } }, babelOptions: { sourceMaps: false, stage0: true } });