Button

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

Included in: dx.phonejs.js, dx.webappjs.js, dx.all.js
Button interactive configuration
Copy Code
Copy to Codepen
$("#button").dxButton({
});

                    

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

  • jQuery
    Use the dxButton jQuery plug-in.

    HTML
    <div id="button"></div>
    JavaScript
    $("#button").dxButton({
        text: 'Click me',
        onClick: function() {
            alert('Button clicked');
        }
    });
  • Knockout
    Add a div element and apply the dxButton binding to this element.

    JavaScript
    var myViewModel = {
        buttonClicked: function() {
            alert('Button clicked');
        }
    }
    ko.applyBindings(myViewModel);
    HTML
    <div data-bind="dxButton: {
        text: 'Click me',
        onClick: buttonClicked
    }"></div>
  • AngularJS
    Add a div element and apply the dx-button directive to this element.

    JavaScript
    var myApp = angular.module('myApp', ['dx']);
    myApp.controller("demoController", function ($scope) {
        $scope.buttonClicked = function () {
            alert('Button clicked');
        };
    });
    angular.element(document).ready(function () {
        angular.bootstrap(document, ['myApp']);
    });
    HTML
    <div dx-button="{
        text: 'Click me',
        onClick: buttonClicked
    }"></div>

Note that DevExtreme widgets require you to link the jQuery and Globalize libraries 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.

You can find the detailed information on principles of working with the widget in the dxButton section of the Individual Widgets article.

View Demo

Configuration

An object defining configuration options for the dxButton 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.

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.

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 dxButton widget.

text

The text displayed on the button.

type

Specifies the button type.

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 methods that can be used to manipulate a 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

Fires when 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