DevExtreme v26.1 is now available.

Explore our newest features/capabilities and share your thoughts with us.

Your search did not match any results.

Vue Data Grid - Advanced Master-Detail View

This demo illustrates an advanced master-detail view in the DataGrid component. Master rows represent suppliers. Detail sections contain TabPanel components 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.

Backend API
<template> <DxDataGrid id="gridContainer" :data-source="suppliersData" :remote-operations="true" :show-borders="true" > <DxPaging :page-size="15"/> <DxPager :visible="true"/> <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 setup lang="ts"> import { DxDataGrid, DxColumn, DxPaging, DxPager, DxMasterDetail, } from 'devextreme-vue/data-grid'; import { createStore } from 'devextreme-aspnet-data-nojquery'; import MasterDetail from './MasterDetail.vue'; const url = 'https://js.devexpress.com/Demos/NetCore/api/DataGridAdvancedMasterDetailView'; const suppliersData = createStore({ key: 'SupplierID', loadUrl: `${url}/GetSuppliers`, }); </script>
<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 setup lang="ts"> import { DxForm, type DxFormTypes } from 'devextreme-vue/form'; import { type Supplier } from './data.ts'; defineProps<{ data: Supplier }>(); const items = [ { dataField: 'Address' }, { dataField: 'City' }, { dataField: 'Region' }, { dataField: 'PostalCode' }, { dataField: 'Country' }, { dataField: 'Phone' }, ]; const customizeItem = (item: DxFormTypes.SimpleItem) => { item.template = 'form-item'; }; </script>
<template> <DxTabPanel> <DxItem title="Orders" template="orders-tab" /> <template #orders-tab> <OrdersTab :supplier-id="masterDetailData.key" /> </template> <DxItem title="Address" template="address-tab" /> <template #address-tab> <AddressTab :data="masterDetailData.data" /> </template> </DxTabPanel> </template> <script setup lang="ts"> import { DxTabPanel, DxItem } from 'devextreme-vue/tab-panel'; import OrdersTab from './OrdersTab.vue'; import AddressTab from './AddressTab.vue'; import { type Supplier } from './data.ts'; defineProps<{ masterDetailData: { key: number, data: Supplier } }>(); </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 setup lang="ts"> import { DxDataGrid, DxColumn, DxPaging, DxSummary, DxTotalItem, DxValueFormat, } from 'devextreme-vue/data-grid'; import { createStore } from 'devextreme-aspnet-data-nojquery'; import { computed } from 'vue'; const props = defineProps<{ productId: number | null }>(); const url = 'https://js.devexpress.com/Demos/NetCore/api/DataGridAdvancedMasterDetailView'; const orderHistoryStore = computed(() => (props.productId === null ? undefined : { store: createStore({ key: 'OrderID', loadParams: { ProductID: props.productId }, loadUrl: `${url}/GetOrdersByProduct`, }), })); </script>
<template> <DxForm label-location="top" class="form-container" > <DxItem template="select-box"> <DxLabel text="Product"/> </DxItem> <template #select-box> <ProductSelectBox :supplier-id="supplierId" @product-changed="chosenProductId = $event" /> </template> <DxItem template="order-history"> <DxLabel text="Order History"/> </DxItem> <template #order-history> <OrderHistory :product-id="chosenProductId" /> </template> </DxForm> </template> <script setup lang="ts"> import { ref } from 'vue'; import { DxForm, DxItem, DxLabel } from 'devextreme-vue/form'; import ProductSelectBox from './ProductSelectBox.vue'; import OrderHistory from './OrderHistory.vue'; defineProps<{ supplierId: number }>(); const chosenProductId = ref<null | number>(null); </script>
<template> <DxSelectBox :defer-rendering="false" :data-source="dataSource" :input-attr="{ 'aria-label': 'Product' }" :value="productId" value-expr="ProductID" display-expr="ProductName" @valueChanged="$emit('product-changed', $event.value)" /> </template> <script setup lang="ts"> import { ref } from 'vue'; import DxSelectBox from 'devextreme-vue/select-box'; import { createStore } from 'devextreme-aspnet-data-nojquery'; import { type Product } from './data.ts'; defineEmits(['product-changed']); const props = defineProps<{ supplierId: number }>(); const url = 'https://js.devexpress.com/Demos/NetCore/api/DataGridAdvancedMasterDetailView'; const dataSource = createStore({ key: 'ProductID', loadParams: { SupplierID: props.supplierId }, loadUrl: `${url}/GetProductsBySupplier`, onLoaded: setDefaultValue, }); const productId = ref<number>(); function setDefaultValue(items: Product[]) { const firstItem = items[0]; if (firstItem && productId.value === undefined) { productId.value = firstItem.ProductID; } } </script>
export type Supplier = { SupplierID: number; CompanyName: string; ContactName: string; ContactTitle: string; Address: string; City: string; Region: string | null; PostalCode: string; Country: string; Phone: string; Fax: string | null; HomePage: string | null; }; export type Product = { ProductID: number; ProductName: string SupplierID: number; CategoryID: number; QuantityPerUnit: string UnitPrice: number UnitsInStock: number UnitsOnOrder: number ReorderLevel: number Discontinued: boolean; }; export type Order = { OrderID: number; OrderDate: Date; ShipCountry: string; ShipCity: string; UnitPrice: number; Quantity: number; Discount: number; };
import { createApp } from 'vue'; import App from './App.vue'; createApp(App).mount('#app');
#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; }
<!DOCTYPE html> <html lang="en"> <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=5.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" /> <link rel="stylesheet" type="text/css" href="./bundle.css" /> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app" /> </div> <script src="bundles/vendor/vue.vendor.js"></script> <script src="./bundle.js"></script> </body> </html>