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> <DxForm :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> </DxForm> </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> <DxDataGrid id="gridContainer" :data-source="suppliersData" :remote-operations="true" :show-borders="true" > <DxPaging :page-size="15"/> <DxColumn data-field="ContactName"/> <DxColumn data-field="ContactTitle"/> <DxColumn data-field="CompanyName"/> <DxColumn data-field="City"/> <DxColumn data-field="Country"/> <DxMasterDetail :enabled="true" template="master-detail" /> <template #master-detail="{ data }"> <MasterDetail :master-detail-data="data"/> </template> </DxDataGrid> </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> <DxTabPanel> <DxItem title="Orders" template="orders-tab" /> <OrdersTab slot="orders-tab" :supplier-id="masterDetailData.key" /> <DxItem title="Address" template="address-tab" /> <AddressTab slot="address-tab" :data="masterDetailData.data" /> </DxTabPanel> </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> <DxDataGrid :data-source="orderHistoryStore" :show-borders="true" > <DxPaging :page-size="5"/> <DxColumn data-field="OrderID"/> <DxColumn data-field="OrderDate" data-type="date" /> <DxColumn data-field="ShipCountry"/> <DxColumn data-field="ShipCity"/> <DxColumn data-field="UnitPrice" format="currency" /> <DxColumn data-field="Quantity"/> <DxColumn data-field="Discount" format="percent" /> <DxSummary> <DxTotalItem column="UnitPrice" summary-type="sum" > <DxValueFormat :precision="2" format="currency" /> </DxTotalItem> <DxTotalItem column="Quantity" summary-type="count" /> </DxSummary> </DxDataGrid> </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> <DxForm label-location="top" class="form-container" > <DxItem template="select-box"> <DxLabel text="Product"/> </DxItem> <ProductSelectBox slot="select-box" :supplier-id="supplierId" @product-changed="chosenProductId = $event" /> <DxItem template="order-history"> <DxLabel text="Order History"/> </DxItem> <template #order-history="{ data }"> <OrderHistory :product-id="chosenProductId" /> </template> </DxForm> </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> <DxSelectBox :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/select-box'; 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/20.1.7/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/20.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', 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.14', 'devexpress-gantt': 'npm:devexpress-gantt@1.0.7', '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 } });