Your search did not match any results.
TreeView

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 CodePen
Apply
Reset
var DemoApp = angular.module('DemoApp', ['dx']); DemoApp.controller('DemoController', function DemoController($scope) { $scope.checkedItems = []; function isProduct(data) { return !data.items.length; } function processProduct(product) { var itemIndex = -1; $.each($scope.checkedItems, function (index, item) { if (item.key === product.key) { itemIndex = index; return false; } }); if(product.selected && itemIndex === -1) { $scope.checkedItems.push(product); } else if (!product.selected){ $scope.checkedItems.splice(itemIndex, 1); } } $scope.treeViewOptions = { items: products, width: 320, showCheckBoxesMode: "normal", onItemSelectionChanged: function(e) { var item = e.node; if(isProduct(item)) { processProduct($.extend({ category: item.parent.text }, item)); } else { $.each(item.items, function(index, product) { processProduct($.extend({ category: item.text }, product)); }); } } }; $scope.listOptions = { width: 400, bindingOptions: { items: "checkedItems" } }; });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" > <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" /> <script src="js/jquery-3.1.0.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/17.2.3/css/dx.spa.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/17.2.3/css/dx.common.css" /> <link rel="dx-theme" data-theme="generic.light" href="https://cdn3.devexpress.com/jslib/17.2.3/css/dx.light.css" /> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script> <script>window.angular || document.write(decodeURIComponent('%3Cscript src="js/angular.min.js"%3E%3C\/script%3E'))</script> <script src="https://cdn3.devexpress.com/jslib/17.2.3/js/dx.all.js"></script> <script src="data.js"></script> <link rel="stylesheet" type ="text/css" href ="styles.css" /> <script src="index.js"></script> </head> <body class="dx-viewport"> <div class="demo-container" ng-app="DemoApp" ng-controller="DemoController"> <div class="form"> <h4>Store: Super Mart of the West</h4> <div dx-tree-view="treeViewOptions" dx-item-alias="data"> <div data-options="dxTemplate: {name: 'item'}"> <div> {{data.text}} {{(data.price) ? (" ($" + data.price + ")") : ""}} </div> </div> </div> <div class="selected-data"> Selected Products <div id="checked-items" dx-list="listOptions" dx-item-alias="data"> <div data-options="dxTemplate: {name: 'item'}"> <div> {{data.text + " (" + data.category + ") - $" + data.itemData.price}} </div> </div> </div> </div> </div> </div> </body> </html>
.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; }
var 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 }] }];