UI Widgets Button

A button widget.

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

The main purpose of the Button widget is to perform a specified action when the button is clicked.

You can create a 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 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.

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

View Demo

Show Example:
AngularJS
Knockout
jQuery
<div ng-controller="demoController">
    <div class="button" dx-button="{ text: buttonText, onClick: buttonClicked }"></div>
</div>
var myApp = angular.module('myApp', ['dx']);
myApp.controller("demoController", function ($scope) {
    $scope.buttonText = "Click me";
    $scope.buttonClicked = function () {
        DevExpress.ui.notify("The button is clicked", "success", 1000);
    };
});
angular.element(document).ready(function () {
    angular.bootstrap(document, ['myApp']);
});
body {
    text-align: center;
}
.button{
    margin-top: 25px;
}
<div class="button" data-bind="dxButton:{ text:buttonText, onClick: buttonClicked }"></div>
var myViewModel = {
    buttonText: 'Click me',
    buttonClicked: function () {
        DevExpress.ui.notify("The button is clicked", "success", 1000);
    }
}
ko.applyBindings(myViewModel);
body {
    text-align: center;
}
.button{
    margin-top: 25px;
}
<div class="button" id="myButton"></div>
$("#myButton").dxButton({
    text: 'Click me',
    onClick: function () {
        DevExpress.ui.notify("The button is clicked", "success", 1000);
    }
});
body {
    text-align: center;
}
.button{
    margin-top: 25px;
}

Configuration

An object defining configuration options for the Button widget.

Methods

This section describes members used to manipulate the widget.

Events

This section describes events fired by this widget.

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