UI Widgets TagBox

A widget that allows you to select multiple items from a dropdown list.

Included in: dx.phonejs.js, dx.webappjs.js, dx.all.js

The widget is similar to the dxSelectBox widget. Unlike dxSelectBox, the dxTagBox widget enables an end-user to select multiple items. The selected items are displayed as tags. To select an item, a user should click the widget and choose the required item from the drop-down list. To unselect an item, click the "X" button on the corresponding tag.

You can create a widget using one of the following approaches.

  • jQuery
    Use the dxTagBox jQuery plug-in.

    HTML
    <div id="tagBox"></div>
    JavaScript
    var tagBoxData = [
        { "name": "Alabama", "capital": "Montgomery" },
        { "name": "Alaska", "capital": "Juneau" },
        { "name": "Arizona", "capital": "Phoenix" }
        . . .
    ]
    $("#tagBox").dxTagBox({
        dataSource: tagBoxData,
        valueExpr: 'capital',
        displayExpr: 'name'
    });
  • Knockout
    Add a div element and apply the dxSelectBox binding to this element.

    HTML
    <div data-bind="dxTagBox: {
        dataSource: tagBoxData,
        valueExpr: 'capital',
        displayExpr: 'name'
    }"></div>
  • Angular
    Add a div element and apply the dx-tag-box directive to this element.

    HTML
    <div dx-tag-box="{
        dataSource: tagBoxData,
        valueExpr: 'capital',
        displayExpr: 'name'
    }"></div>

Note that DevExtreme widgets require you to link the jQuery and Globalize libraries to your application. If you use the Knockout or Angular approach, the Knockout or Angular library is also required.

See Also

The dxTagBox widget supports common Collection Container and Editor widget functionality. You can find detailed information on the principles of working with the widget in the dxTagBox section of the Editor Widgets article. For information on using the Collection Container functionality, refer to the Collection Container Widgets guide.

View Demo

Watch Video

Show Example:
AngularJS
Knockout
jQuery
<div ng-controller="demoController">
    <div class="tagBox" dx-tag-box="{
        dataSource: tagBoxData,
        placeholder: 'Select states',
        displayExpr: 'name',
        valueExpr: 'capital',
        bindingOptions: {
            values: 'capitals'
        }
    }"></div>
    <div>
        <p><b>Selected state capitals:</b></p>
        <ul ng-repeat="capital in capitals">
            <li>
                <p>"{{capital}}"</p>
            </li>
        </ul>
    </div>
</div>
var myApp = angular.module('myApp', ['dx']);
myApp.controller("demoController", function ($scope) {
    $scope.capitals = [];
    $scope.tagBoxData = new DevExpress.data.DataSource({ store: [], paginate: false });
    $.get("/Content/data/states.txt", function (data) {
        for (var i = 0; i < data.length; i++) {
            $scope.tagBoxData.store().insert(data[i]);
        }
        $scope.tagBoxData.load();
    }, "json");
});
angular.element(document).ready(function () {
    angular.bootstrap(document, ['myApp']);
});
body {
    text-align: center;
}
.tagBox {
    margin: 10px;
}
<div class="tagBox" data-bind="dxTagBox:{
    dataSource: tagBoxData,
    placeholder: 'Select states',
    displayExpr: 'name',
    valueExpr: 'capital',
    values: capitals
}"></div>
<div>
    <p><b>Selected state capitals:</b></p>
    <ul data-bind="foreach: capitals">
        <li>
            <p>"<span data-bind="text: $data"></span>"</p>
        </li>
    </ul>
</div>
var myViewModel = {
    capitals: ko.observableArray([]),
    tagBoxData: new DevExpress.data.DataSource({ store: [], paginate: false })
}
$.get("/Content/data/states.txt", function (data) {
    for (var i = 0; i < data.length; i++) {
        myViewModel.tagBoxData.store().insert(data[i]);
    }
    myViewModel.tagBoxData.load();
}, "json");
ko.applyBindings(myViewModel);
body {
    text-align: center;
}
.tagBox {
    margin: 10px;
}
<div class="tagBox" id="myTagBox"></div>
<div>
    <p><b>Selected state capitals:</b></p>
    <ul id="capitals"></ul>
</div>
var tagBoxData = new DevExpress.data.DataSource({ store: [], paginate: false });
$("#myTagBox").dxTagBox({
    dataSource: tagBoxData,
    placeholder: 'Select states',
    displayExpr: 'name',
    valueExpr: 'capital',
    onValueChanged: function (e) {
        $("#capitals").empty();
        for (var i = 0; i < e.values.length; i++)
            $("#capitals").append("<li><p>" + e.values[i] + "</p></li>");
    }
});
$.get("/Content/data/states.txt", function (data) {
    for (var i = 0; i < data.length; i++) {
        tagBoxData.store().insert(data[i]);
    }
    tagBoxData.load();
}, "json")
body {
    text-align: center;
}
.tagBox {
    margin: 10px;
}

Configuration

An object defining configuration options for the dxTagBox widget.

Methods

This section describes members used to manipulate the widget.

Events

This section describes events exposed by this widget.

Default Item Template

This section lists the data source fields that are used in a default item template.

By default, a predefined item template is applied to display the items of this widget. This template is based on certain fields of the data source provided for this widget. Below is the list of these fields. If the default item template is not appropriate for your task, implement a custom item template based on these or other fields of your data source.

See Also