Button

The Button widget is a simple button that performs specified commands when a user clicks it.

Included in: dx.mobile.js, dx.web.js, dx.viz-web.js, dx.all.js
Module: ui/button
Export: default
Button interactive configuration
Copy Code
Copy to Codepen
$("#button").dxButton({
});

                    

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

  • jQuery

    HTML
    JavaScript
    <div id="button"></div>
    $(function () {
        $("#button").dxButton({
            text: 'Click me',
            onClick: function() {
                alert("The Button was clicked");
            }
        });
    });
  • Angular

    HTML
    JavaScript
    <dx-button
        text="Click me"
        (onClick)="buttonClicked()">
    </dx-button>
    export class AppComponent {
        buttonClicked() {
            alert("The Button was clicked");
        }
    }
  • AngularJS

    HTML
    JavaScript
    <div ng-controller="DemoController">
        <div dx-button="{
            text: 'Click me',
            onClick: buttonClicked
        }"></div>
    </div>
    angular.module('DemoApp', ['dx'])
        .controller("DemoController", function ($scope) {
            $scope.buttonClicked = function () {
                alert("The Button was clicked");
            };
        });
  • Knockout

    HTML
    <div data-bind="dxButton: {
        text: 'Click me',
        onClick: function () {
            alert('The Button was clicked');
        }
    }"></div>
  • ASP.NET MVC Wrappers

    Razor C#
    Razor VB
    @(Html.DevExtreme().Button()
        .ID("button")
        .Text("Click me")
        .OnClick(@<text>
            function () {
                alert("The Button was clicked");
            }
        </text>)
    )
    @(Html.DevExtreme().Button() _
        .ID("button") _
        .Text("Click me") _
        .OnClick("button_click")
    )
    <script>
        function button_click() {
            alert("The Button was clicked");
        }
    </script>

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 topics in the Installation section.

View Demo

See Also

Configuration

An object defining configuration options for the Button widget.

Name Description
accessKey

Specifies a shortcut key that sets focus on the widget element.

activeStateEnabled

A Boolean value specifying whether or not the widget changes its state when interacting with a user.

disabled

A Boolean value specifying whether or not the widget can respond to user interaction.

elementAttr

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

focusStateEnabled

Specifies whether or not the widget can be focused.

height

Specifies the height of the widget.

hint

Specifies the text of the hint displayed for the widget.

hoverStateEnabled

A Boolean value specifying whether or not the widget changes its state when being hovered by an end user.

icon

Specifies the icon to be displayed on the button.

onClick

A handler for the click event.

onDisposing

A handler for the disposing event.

onInitialized

A handler for the initialized event. Executed only once, after the widget is initialized.

onOptionChanged

A handler for the optionChanged event.

rtlEnabled

Specifies whether or not the current component supports a right-to-left representation.

tabIndex

Specifies the widget tab index.

template

A template to be used for rendering the Button widget.

text

The text displayed on the button.

type

Specifies the button type.

useSubmitBehavior

Specifies whether or not the button must submit an HTML form.

validationGroup

Specifies the name of the validation group to be accessed in the click event handler.

visible

A Boolean value specifying whether or not the widget is visible.

width

Specifies the width of the widget.

Methods

This section describes members used to manipulate the widget.

Name Description
beginUpdate()

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

defaultOptions(rule)

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

element()

Returns the root HTML element of the widget.

endUpdate()

Enables the component to refresh after the beginUpdate() method call.

focus()

Sets focus on the widget.

instance()

Returns an instance of this component class.

off(eventName)

Detaches all event handlers from the specified event.

off(eventName, eventHandler)

Detaches a particular event handler from the specified event.

on(eventName, eventHandler)

Subscribes to a specified event.

on(events)

Subscribes to the specified events.

option()

Returns the configuration options of this component.

option(optionName)

Gets the value of the specified configuration option of this component.

option(optionName, optionValue)

Sets a value to the specified configuration option of this component.

option(options)

Sets one or more options of this component.

registerKeyHandler(key, handler)

Registers a handler when a specified key is pressed.

repaint()

Redraws the widget.

Events

This section describes events fired by this widget.

Name Description
click

Fires when the button is clicked.

disposing

Fires when the widget is being removed.

initialized

Raised only once, after the widget is initialized.

optionChanged

Fires after an option of the component is changed.

Default Template

This section lists the fields of a context object available in a button template.

By default, a predefined template is applied to display the widget. This template is based on the fields of the template context object. Below is the list of these fields. If the default item template is not appropriate for your task, implement a custom template based on these fields or fields of the view model.

See Also