Your search did not match any results.
Tree View

Item Selection and Customization

Documentation

The TreeView widget supports multi-selection. In this demo, the showCheckBoxesMode option is set to «normal» allowing multiple items to be marked as selected. In addition, a custom item template is utilized to display price per item in brackets.

Copy to CodeSandBox
Apply
Reset
<template> <div class="form"> <h4>Store: Super Mart of the West</h4> <dx-tree-view id="simple-treeview" :items="products" :width="320" show-check-boxes-mode="normal" @item-selection-changed="selectionChanged" > <template #item="{ data: value }"> {{ value.text + (value.price ? ' ($' + value.price + ')' : '') }} </template> </dx-tree-view> <div class="selected-data">Selected Products <dx-list id="checked-items" :width="400" :items="checkedItems" > <template #item="{ data: item }"> {{ item.text + " (" + item.category + ") - $" + item.itemData.price }} </template> </dx-list> </div> </div> </template> <script> import { DxTreeView, DxList } from 'devextreme-vue'; import { products } from './data.js'; export default { components: { DxTreeView, DxList }, data() { return { products, checkedItems: [] }; }, methods: { selectionChanged(e) { const value = e.node; if (this.isProduct(value)) { this.processProduct({ id: value.key, text: value.text, itemData: value.itemData, selected: value.selected, category: value.parent.text }); } else { value.items.forEach(product => { this.processProduct({ id: product.key, text: product.text, itemData: product.itemData, selected: product.selected, category: value.text }); }); } }, isProduct(data) { return !data.items.length; }, processProduct(product) { let itemIndex = -1; this.checkedItems.forEach((item, index) => { if (item.id === product.id) { itemIndex = index; return false; } }); if (product.selected && itemIndex === -1) { this.checkedItems.push(product); } else if (!product.selected) { this.checkedItems.splice(itemIndex, 1); } } } }; </script> <style scoped> .form > h4 { margin-bottom: 20px; } .form > div, #selection-treeview { display: inline-block; vertical-align: top; } #checked-items { margin-top: 20px; } .selected-data { padding: 20px; background: #f5f5f5; font-size: 115%; font-weight: bold; } .dx-list-item-content { padding-left: 0; } </style>
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" /> <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"> <span v-if="false">Loading...</span> </div> </div> </body> </html>
export const products = [{ id: '1_1_1', text: 'Video Players', items: [{ id: '1_1_1_1', text: 'HD Video Player', price: 220 }, { id: '1_1_1_2', text: 'SuperHD Video Player', price: 270 }] }, { id: '1_1_2', text: 'Televisions', expanded: true, items: [{ id: '1_1_2_1', text: 'SuperLCD 42', price: 1200 }, { id: '1_1_2_2', text: 'SuperLED 42', price: 1450 }, { id: '1_1_2_3', text: 'SuperLED 50', price: 1600 }, { id: '1_1_2_4', text: 'SuperLCD 55', price: 1350 }, { id: '1_1_2_5', text: 'SuperLCD 70', price: 4000 }] }, { id: '1_1_4', text: 'Projectors', items: [{ id: '1_1_4_1', text: 'Projector Plus', price: 550 }, { id: '1_1_4_2', text: 'Projector PlusHD', price: 750 }] }];
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.1', 'devextreme-vue': 'npm:devextreme-vue@19.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', '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' } }, packages: { 'devextreme-vue': { main: 'index.js' }, 'devextreme': { defaultExtension: 'js' } }, babelOptions: { sourceMaps: false, stage0: true } });