UI Widgets TabPanel

A widget used to display a view and to switch between several views by clicking the appropriate tabs.

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

The dxTabPanel widget consists of the dxTabs and dxMultiView widgets. It automatically synchronizes the selected tab and the currently displayed view. If a user switches a tab, the widget displays the appropriate view and when a user switches a view by swiping, the widget selects the appropriate tab. Each view and each tab displayed by the widget corresponds to a data source item. The widget uses a template specified by the itemTemplate option to render a view. The titleTemplate option specifies the template used to render a tab.

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

  • jQuery
    Use the dxTabPanel jQuery plug-in.

    HTML
    <div id="tabPanel"></div>
    JavaScript
    $("#tabPanel").dxTabPanel({
        dataSource: tabPanelData,
        swipeEnabled: true,
        loop: true,
        animationEnabled: false
    });
  • Knockout
    Add a div element and apply the dxTabPanel binding to this element.

    HTML
    <div data-bind="dxTabPanel: {
        dataSource: tabPanelData,
        swipeEnabled: true,
        loop: true,
        animationEnabled: false
    }"></div>
  • Angular
    Add a div element and apply the dx-tab-panel directive to this element.

    HTML
    <div dx-tab-panel="{
        dataSource: tabPanelData,
        swipeEnabled: true,
        loop: true,
        animationEnabled: false
    }"></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

Since the dxTabPanel widget is used to display multiple items, it supports common the Collection Container widget functionality. You can find detailed information on the principles of working with the widget in the dxTabPanel section of the Collection Container Widgets article.

View Demo

Watch Video

Show Example:
AngularJS
Knockout
jQuery
<div ng-controller="demoController" style="height: 100%;">
    <div dx-tab-panel="{
        dataSource: tabPanelItems,
        titleTemplate: 'title',
        itemTemplate: 'tab',
        height: 300
    }">
        <div data-options="dxTemplate : { name: 'title' } ">
            <p>{{title}}</p>
        </div>
        <div data-options="dxTemplate : { name: 'tab' } ">
            <div style="margin:25px;">
                <h1>{{title}}</h1>
                <p>&nbsp;</p>
                <div style="text-align:left;" ng-repeat="item in dataArray">
                    <p>{{item.propertyKey}}: <b>{{item.propertyValue}}</b></p>
                </div>
            </div>
        </div>
    </div>
</div>
var dataItems = [
        {
            title: "Info",
            data: {
                firstName: "John",
                lastName: "Smith",
                birthYear: 1986,
            }
        },
        {
            title: "Contacts",
            data: {
                phone: "(555)555-5555",
                email: "John.Smith@example.com",
            }
        },
        {
            title: "Address",
            data: {
                state: "CA",
                city: "San Francisco",
                street: "Stanford Ave",
            }
        }
];

var myApp = angular.module('myApp', ['dx']);
myApp.controller("demoController", function ($scope) {
    $scope.tabPanelItems = new DevExpress.data.DataSource({
        store: dataItems,
        map: function (itemData) {
            itemData.text = itemData.title;
            itemData.dataArray = $.map(itemData.data, function (value, key) {
                return {
                    propertyKey: key,
                    propertyValue: value
                }
            });
            return itemData;
        }
    });
});
angular.element(document).ready(function () {
    angular.bootstrap(document, ['myApp']);
});
body{
    text-align:center;
}
<div data-bind="dxTabPanel: {
    dataSource: tabPanelItems,
    titleTemplate: 'title',
    itemTemplate: 'tab',
    height: 300
}">
    <div data-options="dxTemplate : { name: 'title' } ">
        <p data-bind="text: title"></p>
    </div>
    <div data-options="dxTemplate : { name: 'tab' } ">
        <div style="margin:25px;">
            <h1 data-bind="text: title"></h1>
            <p>&nbsp;</p>
            <div style="text-align:left;" data-bind="foreach: dataArray">
                <p><span data-bind="text: propertyKey"></span>: <b data-bind="text: propertyValue"></b></p>
            </div>
        </div>
    </div>
</div>
var dataItems = [
        {
            title: "Info",
            data: {
                firstName: "John",
                lastName: "Smith",
                birthYear: 1986,
            }
        },
        {
            title: "Contacts",
            data: {
                phone: "(555)555-5555",
                email: "John.Smith@example.com",
            }
        },
        {
            title: "Address",
            data: {
                state: "CA",
                city: "San Francisco",
                street: "Stanford Ave",
            }
        }
];

var myViewModel = {
    tabPanelItems: new DevExpress.data.DataSource({
        store: dataItems,
        map: function (itemData) {
            itemData.text = itemData.title;
            itemData.dataArray = $.map(itemData.data, function (value, key) {
                return {
                    propertyKey: key,
                    propertyValue: value
                }
            });
            return itemData;
        }
    })
}
ko.applyBindings(myViewModel);
body{
    text-align:center;
}
<div id="myTabPanel"></div>
var dataItems = [
        {
            title: "Info",
            data: {
                firstName: "John",
                lastName: "Smith",
                birthYear: 1986,
            }
        },
        {
            title: "Contacts",
            data: {
                phone: "(555)555-5555",
                email: "John.Smith@example.com",
            }
        },
        {
            title: "Address",
            data: {
                state: "CA",
                city: "San Francisco",
                street: "Stanford Ave",
            }
        }
];

$("#myTabPanel").dxTabPanel({
    dataSource: dataItems,
    titleTemplate: 'title',
    itemTemplate: 'tab',
    height: 300,
    titleTemplate: function (itemData, itemIndex, itemElement) {
        itemElement.append("<p>" + itemData.title + "</p>");
    },
    itemTemplate: function (itemData, itemIndex, itemElement) {
        var wrapper = $('<div style="margin: 25px;">');
        wrapper.append("<h1>" + itemData.title + "</h1>");
        wrapper.append("<p>&nbsp;</p>");
        itemElement.append(wrapper);
        var innerWrapper = $('<div style="text-align: left;">');
        wrapper.append(innerWrapper);
        for (var field in itemData.data)
            innerWrapper.append("<p>" + field + ": <b>" + itemData.data[field] + "</b></p>");
    }
});
body{
    text-align:center;
}

Configuration

An object defining configuration options for the dxTabPanel 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 template for tab panel items.

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 a 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