UI Widgets MultiView

A widget used to display a view and to switch between several views.

Included in: dx.mobile.js, dx.web.js, dx.viz-web.js, dx.all.js
Module: ui/multi_view
MultiView interactive configuration
Copy code
$("#multiview").dxMultiView({
});

The MultiView widget includes several items (views). These items are placed horizontally next to one another and navigated by panning to the left or right. The widget is often used together with the Tabs widget to display tab contents.

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

  • jQuery
    Use the dxMultiView jQuery plug-in.

    HTML
    <div id="multiView"></div>
    JavaScript
    $("#multiView").dxMultiView({
        dataSource: multiViewData,
        selectedIndex: 0
    });
  • Knockout
    Add a div element and apply the dxMultiView binding to this element.

    HTML
    <div data-bind="dxMultiView: {
        dataSource: multiViewData,
        selectedIndex: 0
    }"></div>
  • AngularJS
    Add a div element and apply the dx-multi-view directive to this element.

    HTML
    <div dx-multi-view="{
        dataSource: multiViewData,
        selectedIndex: 0
    }"></div>

Note that DevExtreme widgets require you to link the jQuery library to your application. If you use the Knockout or AngularJS approach, the Knockout or AngularJS library is also required. For detailed information on linking these libraries to your project, refer to the Installation article.

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

View Demo

Show Example:
AngularJS
Knockout
jQuery
<div ng-controller="demoController" style="height: 100%;">
    <div dx-button="{ text: '<< prev', onClick: goBack }"></div>
    <div dx-button="{ text: 'next >>', onClick: goForward }"></div>
    <div dx-multi-view="{
        dataSource: multiViewItems,
        height: 160,
        bindingOptions: {
            selectedIndex: 'currentIndex'
        }
    }" dx-item-alias="itemObj">
        <div data-options="dxTemplate: { name: 'item' }">
            <div style="margin:25px;">
                <h1>{{itemObj.title}}</h1>
                <p>&nbsp;</p>
                <div style="text-align:left;" ng-repeat="(key, value) in itemObj.data">
                    <p>{{key}}: <b>{{value}}</b></p>
                </div>
            </div>
        </div>
    </div>
</div>
var myApp = angular.module('myApp', ['dx']);
myApp.controller("demoController", function ($scope) {
    $scope.currentIndex = 0;
    $scope.goForward = function () {
        if ($scope.currentIndex == $scope.multiViewItems.items().length - 1)
            $scope.currentIndex = 0;
        else
            $scope.currentIndex++;
    }
    $scope.goBack = function () {
        if ($scope.currentIndex == 0)
            $scope.currentIndex = $scope.multiViewItems.items().length - 1;
        else
            $scope.currentIndex--;
    }
    $scope.multiViewItems = new DevExpress.data.DataSource({
        store: [
            {
                title: "Personal Data",
                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",
                }
            }
        ]
    })
});
angular.element(document).ready(function () {
    angular.bootstrap(document, ['myApp']);
});
body{
    text-align:center;
}
.dx-button{
    margin: 10px;
}
<div data-bind="dxButton: { text: '<< prev', onClick: goBack }"></div>
<div data-bind="dxButton: { text: 'next >>', onClick: goForward }"></div>
<div data-bind="dxMultiView: {
    dataSource: multiViewItems,
    selectedIndex: currentIndex,
    height: 160
}">
    <div data-options="dxTemplate : { name: 'item' } ">
        <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 myViewModel = {
    currentIndex: ko.observable(0),
    goForward: function () {
        if (this.currentIndex() == this.multiViewItems.items().length - 1)
            this.currentIndex(0);
        else
            this.currentIndex(this.currentIndex() + 1);
    },
    goBack: function () {
        if (this.currentIndex() == 0)
            this.currentIndex(this.multiViewItems.items().length - 1);
        else
            this.currentIndex(this.currentIndex() - 1);
    },
    multiViewItems: new DevExpress.data.DataSource({
        store: [
            {
                title: "Personal Data",
                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",
                }
            }
        ],
        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;
}
.dx-button{
    margin: 10px;
}
<div id="backButton"></div>
<div id="forwardButton"></div>
<div id="myMultiView">
var multiViewItems = new DevExpress.data.DataSource({
    store: [
        {
            title: "Personal Data",
            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",
            }
        }
    ]
});
$("#myMultiView").dxMultiView({
    dataSource: multiViewItems,
    itemTemplate: function (itemData, itemIndex, itemElement) {
        wrapper = $("<div style='margin:25px;'>");
        wrapper.append("<h1>" + itemData.title + "</h1>");
        wrapper.append("<p>&nbsp;</p>");
        var innerWrapper = $("<div style='text-align:left;'>");
        for (var field in itemData.data)
            innerWrapper.append("<p>" + field + ": <b>" + itemData.data[field] + "</b></p>");
        wrapper.append(innerWrapper);
        itemElement.append(wrapper);
    }
});
$("#backButton").dxButton({
    text: '<< prev',
    onClick: function () {
        var multiView = $("#myMultiView").dxMultiView("instance");
        if (multiView.option("selectedIndex") == 0)
            multiView.option("selectedIndex", multiViewItems.items().length - 1);
        else
            multiView.option("selectedIndex", multiView.option("selectedIndex") - 1);
    }
});
$("#forwardButton").dxButton({
    text: 'next >>',
    onClick: function () {
        var multiView = $("#myMultiView").dxMultiView("instance");
        if (multiView.option("selectedIndex") == multiViewItems.items().length - 1)
            multiView.option("selectedIndex", 0);
        else
            multiView.option("selectedIndex", multiView.option("selectedIndex") + 1);
    }
});
body{
    text-align:center;
}
.dx-button{
    margin: 10px;
}

Configuration

An object defining configuration options for the MultiView widget.

Methods

This section describes members used to manipulate the widget.

Events

This section describes events fired by this widget.

Default Item Template

This section lists the data source fields that are used in a default template for multi-view 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 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