Drawer

The Drawer is a dismissible or permanently visible panel used for navigation in responsive web application layouts.

Module: ui/drawer
Export: default

DevExtreme widgets are integrated with many popular libraries and frameworks. See the Installation section (for JavaScript libraries) or the Prerequisites and Installation section (for ASP.NET MVC framework) to find details on setting up DevExtreme with a particular library or framework.

The following code shows how to create the Drawer widget using every supported library and framework. For more details on working with widgets in these libraries and frameworks, see the Widget Basics topic for jQuery, Angular, AngularJS, Knockout or ASP.NET MVC.

jQuery
JavaScript
HTML
$(function() {
    var drawer = $("#drawer").dxDrawer({
        openedStateMode: "shrink",
        revealMode: "expand",
        opened: true,
        maxSize: 200,
        minSize: 50,
        template: function($content) {
            var $list = $("<div/>");
            $list.dxList({
                dataSource: [
                    { id: 1, text: "Inbox"},
                    { id: 2, text: "Sent Mail"},
                    { id: 3, text: "Trash"},
                    { id: 4, text: "Spam"}
                ],
                width: 200
            });
            return $list;
        }
    }).dxDrawer("instance"); 
    var button = $("#button").dxButton({
        text: "Close Drawer",
        onClick: function(e) {
            var opened = drawer.option("opened");
            var text = opened ? "Open Drawer" : "Close Drawer";
            button.option("text", text);
            drawer.toggle(!opened);
        }
    }).dxButton("instance");
});
<div id="button"></div>
<div id="drawer"><span>Here is the view content.</span></div>
Angular
HTML
TypeScript
<dx-button
    [(text)]="text"
    (onClick)="clickHandler()">
</dx-button>
<dx-drawer
    openedStateMode="shrink"
    revealMode="expand"
    [maxSize]="200"
    [minSize]="50"
    [(opened)]="isOpened"
    template="drawerTemplate">
    <span>Here is the view content.</span>
    <div *dxTemplate="let data of 'drawerTemplate'">
        <dx-list 
            [dataSource]="navigation"
            [width]="200">
        </dx-list>
    </div>
</dx-drawer>
import { DxDrawerModule, DxListModule, DxButtonModule } from "devextreme-angular";
// ...
export class AppComponent {
    navigation = [
        { id: 1, text: "Inbox"},
        { id: 2, text: "Sent Mail"},
        { id: 3, text: "Trash"},
        { id: 4, text: "Spam"}
    ];
    text = "Close Drawer";
    isOpened: boolean = true;
    clickHandler() {
        this.text = this.isOpened ? "Open Drawer" : "Close Drawer";
        this.isOpened = !this.isOpened;
    }
}
@NgModule({
    imports: [
        // ...
        DxDrawerModule, 
        DxListModule, 
        DxButtonModule
    ],
    // ...
})
AngularJS
HTML
JavaScript
<div ng-controller="DemoController">
    <div dx-button="{
        onClick: clickHandler,
        bindingOptions: { text: 'text' }
    }"></div>
    <div dx-drawer="{
        openedStateMode: 'shrink',
        revealMode: 'expand',
        maxSize: 200,
        minSize: 50,
        template: 'drawerTemplate',
        bindingOptions: { opened: 'isOpened' }
    }">
        <span>Here is the view content.</span>
        <div data-options="dxTemplate: { name: 'drawerTemplate' }">
            <div dx-list="{
                dataSource: navigation,
                width: 200
            }"></div>
        </div>
    </div>
</div>
angular.module("DemoApp", ["dx"])
    .controller("DemoController", function ($scope) {
        $scope.text = "Close Drawer";
        $scope.isOpened = true;
        $scope.navigation = [
            { id: 1, text: "Inbox"},
            { id: 2, text: "Sent Mail"},
            { id: 3, text: "Trash"},
            { id: 4, text: "Spam"}
        ];
        $scope.clickHandler = function() {
            $scope.text = $scope.isOpened ? "Open Drawer" : "Close Drawer";
            $scope.isOpened = !$scope.isOpened;
        }
    });
Knockout
HTML
JavaScript
<div data-bind="dxButton: {
    text: text,
    onClick: clickHandler
}"></div>
<div data-bind="dxDrawer: {
    maxSize: 200,
    minSize: 50,
    opened: isOpened,
    openedStateMode: 'shrink',
    revealMode: 'expand',
    template: 'drawerTemplate'
}">
    <span>Here is the view content.</span>
    <div data-options="dxTemplate: { name: 'drawerTemplate' }">
        <div data-bind="dxList: {
            dataSource: navigation
        }"></div>
    </div>
</div>
var viewModel = {
    isOpened: ko.observable(true),
    navigation: [
        { id: 1, text: "Inbox"},
        { id: 2, text: "Sent Mail"},
        { id: 3, text: "Trash"},
        { id: 4, text: "Spam"}
    ],
    maxSize: 200,
    minSize: 50,
    text: ko.observable("Close Drawer"),
    clickHandler: function() {
        viewModel.text(viewModel.isOpened() ? "Open Drawer" : "Close Drawer");
        viewModel.isOpened(!viewModel.isOpened());
    }
};
ko.applyBindings(viewModel);
ASP.NET MVC Controls
Razor C#
Razor VB
@(Html.DevExtreme().Button()
    .ID("button")
    .Text("Close Drawer")
    .onClick("button_clickHandler")
)
@(Html.DevExtreme().Drawer()
    .ID("drawer")
    .OpenedStateMode(DrawerOpenedStateMode.Shrink)
    .RevealMode(DrawerRevealMode.Expand)
    .Opened(true)
    .MaxSize(200)
    .MinSize(100)
    .Template(@<text>
        @(Html.DevExtreme().List()
            .DataSource(new JS("navigation"))
            .Width(200)
        )
    </text>)
    .ContentTemplate(@<text>
        <span>Here is the view content</span>
    </text>)
)

<script>
    var navigation = [
        { id: 1, text: "Inbox"},
        { id: 2, text: "Sent Mail"},
        { id: 3, text: "Trash"},
        { id: 4, text: "Spam"}
    ];
    function button_clickHandler() {
        var drawer = $("#drawer").dxDrawer("instance");
        var opened = drawer.option("opened");
        var text = opened ? "Open Drawer" : "Close Drawer";
        button.option("text", text);
        drawer.toggle(!opened);
    }
</script>
@Code
    Html.DevExtreme().Button() _
        .ID("button") _
        .Text("Close Drawer") _
        .onClick("button_clickHandler")
End Code
@Code
    Html.DevExtreme().DropDownBox() _
        .ID("drawer") _
        .OpenedStateMode(DrawerOpenedStateMode.Shrink) _
        .RevealMode(DrawerRevealMode.Expand) _
        .Opened(True) _
        .MaxSize(200) _
        .MinSize(100) _
        .Template(Sub()
            @<text>
                @Html.DevExtreme().List() _
                    .DataSource(New JS("navigation")) _
                    .Width(200)
            </text>
        End Sub).Render()
        .ContentTemplate(Sub()
            @<text>
                <span>Here is the view content</span>
            </text>
        End Sub).Render()
End Code

<script>
    var navigation = [
        { id: 1, text: "Inbox"},
        { id: 2, text: "Sent Mail"},
        { id: 3, text: "Trash"},
        { id: 4, text: "Spam"}
    ];
    function button_clickHandler() {
        var drawer = $("#drawer").dxDrawer("instance");
        var opened = drawer.option("opened");
        var text = drawer.option("opened") ? "Open Drawer" : "Close Drawer";
        button.option("text", text);
        drawer.toggle(!opened);
    }
</script>
Vue
HTML
JavaScript
<div>
    <dx-button
      :text="text"
      @click="clickHandler" />
    <dx-drawer
        opened-state-mode="shrink"
        reveal-mode="expand"
        :max-size="200"
        :min-size="50"
        :opened="isOpened"
        template="drawerTemplate">
        <div slot="drawerTemplate" slot-scope="data">
            <dx-list
                :data-source="navigation"
                :width="200">
            </dx-list>
        </div>
        <span>Here is the view content.</span>
    </dx-drawer>
</div>
import DxDrawer from "devextreme-vue/drawer";
import DxButton from "devextreme-vue/button";
import DxList from "devextreme-vue/list";

export default {
    components: {
        DxDrawer,
        DxButton,
        DxList
    },
    methods: {
        clickHandler: function() {
            this.text = this.isOpened ? "Open Drawer" : "Close Drawer";
            this.isOpened = !this.isOpened;
        }
    },
    data() {
        return {
            isOpened: true,
            text: "Close Drawer",
            navigation: [
                { id: 1, text: "Inbox"},
                { id: 2, text: "Sent Mail"},
                { id: 3, text: "Trash"},
                { id: 4, text: "Spam"}
            ]
        };
    }
}
React
JavaScript
import React from "react";
import Drawer from "devextreme-react/drawer";
import Button from "devextreme-react/button";
import List from "devextreme-react/list";
// ...
const navigation = [
    { id: 1, text: "Inbox"},
    { id: 2, text: "Sent Mail"},
    { id: 3, text: "Trash"},
    { id: 4, text: "Spam"}
];
function renderDrawer() {
    return <List dataSource={navigation} width={200} />;
}
class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            isOpened: true,
            text: "Close Drawer"
        };
        this.clickHandler = this.clickHandler.bind(this);
    }
    clickHandler() {
        this.setState({
            text: this.state.isOpened ? "Open Drawer" : "Close Drawer",
            isOpened: !this.state.isOpened
        });
    }
    render() {
        return (
            <div>
                <Button 
                    text={this.state.text} 
                    onClick={this.clickHandler} />
                <Drawer
                    openedStateMode={"shrink"}
                    revealMode={"expand"}
                    maxSize={200}
                    minSize={50}
                    opened={this.state.isOpened}
                    render={renderDrawer}>
                    <span>Here is the view content.</span>
                </Drawer>
            </div>
        );
    }
}
export default App;

View Demo

See Also

Configuration

This section describes options that configure the Drawer widget's contents, behavior and appearance.

Name Description
activeStateEnabled

Specifies whether or not the widget changes its state when interacting with a user.

animationDuration

Specifies the duration of the drawer's opening and closing animation (in milliseconds). Applies only if animationEnabled is true.

animationEnabled

Specifies whether to use an opening and closing animation.

closeOnOutsideClick

Specifies whether to close the drawer if a user clicks or taps the view area.

disabled

Specifies whether the widget responds to user interaction.

elementAttr

Specifies the attributes to be attached to the widget's root element.

height

Specifies the view's height.

hint

Specifies text for a hint that appears when a user pauses on the widget.

hoverStateEnabled

Specifies whether the widget changes its state when a user pauses on it.

maxSize

Specifies the drawer's width or height (depending on the drawer's position) in the opened state.

minSize

Specifies the drawer's width or height (depending on the drawer's position) in the closed state.

onDisposing

A function that is executed before the widget is disposed of.

onInitialized

A function that is executed only once, after the widget is initialized.

onOptionChanged

A function that is executed after a widget option is changed.

opened

Specifies whether the drawer is opened.

openedStateMode

Specifies how the drawer interacts with the view in the opened state.

position

Specifies the drawer's position in relation to the view.

revealMode

Specifies the drawer's reveal mode.

rtlEnabled

Switches the widget to a right-to-left representation.

shading

Specifies whether to shade the view when the drawer is opened.

target

Specifies the target element associated with the drawer. Applies only when the openedStateMode is "overlap".

template

Specifies the drawer's content.

visible

Specifies whether the Drawer widget (including the view) is visible.

width

Specifies the view's width.

See Also

Methods

This section describes the methods that control the Drawer widget.

Name Description
beginUpdate()

Prevents the widget from refreshing until the endUpdate() method is called.

content()

Gets the drawer's content.

defaultOptions(rule)

Specifies the device-dependent default configuration options for this component.

dispose()

Disposes of all the resources allocated to the Drawer instance.

element()

Gets the root widget element.

endUpdate()

Refreshes the widget after a call of the beginUpdate() method.

getInstance(element)

Gets the instance of a widget found using its DOM node.

hide()

Closes the drawer.

instance()

Gets the widget's instance. Use it to access other methods of the widget.

off(eventName)

Detaches all event handlers from a single event.

off(eventName, eventHandler)

Detaches a particular event handler from a single event.

on(eventName, eventHandler)

Subscribes to an event.

on(events)

Subscribes to events.

option()

Gets all widget options.

option(optionName)

Gets the value of a single option.

option(optionName, optionValue)

Updates the value of a single option.

option(options)

Updates the values of several options.

repaint()

Repaints the widget. Call it if you made modifications that changed the widget's state to invalid.

show()

Opens the drawer.

toggle()

Opens or closes the drawer, reversing the current state.

See Also

Events

This section describes events that the Drawer widget raises.

Name Description
disposing

Raised before the widget is disposed of.

initialized

Raised only once, after the widget is initialized.

optionChanged

Raised after a widget option is changed.

See Also