DevExtreme Vue - Customize Item Appearance

For a minor customization of NavBar items, you can use the default item template. This template defines the appearance of an item depending on whether specific fields are present or absent from the item's data object. For example, the following code generates three items. Each of them has an icon. In addition, the second item is disabled, and the third item has a badge.

JavaScript
$(function() {
    $("#navBarContainer").dxNavBar({
        items: [
            { text: "User", icon: "user" },
            { text: "Find", icon: "find", disabled: true },
            { text: "Favorites", icon: "favorites", badge: "New" }
        ]
    });
});

Using the default item template is the easiest way to customize an item, but it lacks flexibility. Instead, you can define a custom template. For AngularJS and Knockout apps, DevExtreme provides a markup component called dxTemplate. The following code gives a simple example of how you can use dxTemplate to customize items in the NavBar.

AngularJS
HTML
JavaScript
<div ng-controller="DemoController">
    <div dx-nav-bar="{
        items: navItems,
        itemTemplate: 'customTemplate'
    }" dx-item-alias="itemObj">
        <div data-options="dxTemplate: { name: 'customTemplate' }">
            <div class="dx-icon-{{ itemObj.icon }}"></div>
            <p style="font-size:12px; margin-top:10px">{{ itemObj.text }}</p>
        </div>
    </div>
</div>
angular.module('DemoApp', ['dx'])
    .controller('DemoController', function ($scope) {
        $scope.navItems = [
            { text: "User", icon: "user" },
            { text: "Find", icon: "find" },
            { text: "Favorites", icon: "favorites" },
            { text: "About", icon: "info" },
            { text: "Home", icon: "home" },
            { text: "URI", icon: "tips" }
        ];
    });
NOTE
The dx-item-alias directive specifies the variable that is used to access the item object.
Knockout
HTML
JavaScript
<div data-bind="dxNavBar:{
    items: navItems,
    itemTemplate: 'customTemplate'
}">
    <div data-options="dxTemplate: { name: 'customTemplate' }">
        <div data-bind="css: 'dx-icon-' + icon"></div>
        <p style="font-size:12px; margin-top:10px" data-bind="text: text"></p>
    </div>
</div>
var viewModel = {
    navItems: [
        { text: "User", icon: "user" },
        { text: "Find", icon: "find" },
        { text: "Favorites", icon: "favorites" },
        { text: "About", icon: "info" },
        { text: "Home", icon: "home" },
        { text: "URI", icon: "tips" }
    ]
};

ko.applyBindings(viewModel);

If you use jQuery alone, combine the HTML markup for items manually with jQuery DOM manipulation methods. To apply this markup, use the itemTemplate callback function as shown in the following code.

JavaScript
$(function() {
    $("#navBarContainer").dxNavBar({
        items: [
            { text: "User", icon: "user" },
            { text: "Find", icon: "find" },
            // . . .
        ],
        itemTemplate: function (itemData, itemIndex, itemElement) {
            var icon = $("<div />").addClass('dx-icon-' + itemData.icon);
            var label = $("<p />").attr("style", "font-size:12px; margin-top:10px")
                                  .text(itemData.text)
            itemElement.append(icon, label);
        }
    });
});

You can also customize an individual navigation item. For this purpose, declare a template for this item as a script and pass its id to the template field.

HTML
JavaScript
<script id="individualTemplate" type="text/html">
    <!-- ... -->
</script>
var navItems = [
    { text: "User" },
    { text: "Find" },
    { text: "About", template: $("#individualTemplate") },
    // . . .
];

In addition, you can use a 3rd-party template engine to customize widget appearance. For more information, see the 3rd-Party Template Engines article.

See Also