Customize Item Appearance

For a minor customization of ActionSheet buttons, you can use the default item template. This template defines the appearance of a button depending on whether specific fields are present or absent from the button's data object. For example, the following code generates three buttons, the first is not customized, the second is disabled, the type of the third button is danger.

JavaScript
$(function() {
    $("#actionSheetContainer").dxActionSheet({
        dataSource: [
            { text: "Reply" },
            { text: "Reply All", disabled: true },
            { text: "Delete", type: 'danger' }
        ]
    });
});

Using the default item template is the easiest way to customize an item, but it lacks flexibility. Instead, you can define a custom template. For AngularJS and Knockout apps, DevExtreme provides a markup component called dxTemplate. The following code shows how you can use dxTemplate to define a template for the ActionSheet buttons.

AngularJS

HTML
<div ng-controller="DemoController">
    <div dx-action-sheet="{ 
        dataSource: actionSheetData,
        itemTemplate: 'links',
        bindingOptions: {
            visible: 'isActionSheetVisible'
        }
    }" dx-item-alias="itemObj">
        <div data-options="dxTemplate: { name: 'links' }">
            <div style="margin:5px; padding:10px; border:1px dotted #080; background-color:white;">
                <a href="#">{{ itemObj.text }}</a>
            </div>
        </div>
</div>
JavaScript
angular.module('DemoApp', ['dx'])
    .controller('DemoController', function ($scope) {
        $scope.isActionSheetVisible = false;
        $scope.actionSheetData = [
            { text: "Reply" },
            { text: "Reply All" },
            { text: "Forward" },
            { text: "Delete" }
        ];
        $scope.showActionSheet = function () {
            $scope.isActionSheetVisible = true;
        };
    });

NOTE: The dx-item-alias directive specifies the variable that is used to access the item object.

Knockout

HTML
<div data-bind="dxActionSheet: { 
    dataSource: actionSheetData,
    visible: isActionSheetVisible,
    itemTemplate: 'links' 
}">
    <div data-options="dxTemplate: { name: 'links' }">
        <div style="margin:5px; padding:10px; border:1px dotted #080; background-color:white;">
            <a href="#" data-bind="text: text"></a>
        </div>
    </div>
</div>
JavaScript
var viewModel = {
    isActionSheetVisible: ko.observable(false),
    actionSheetData: [
        { text: "Reply" },
        { text: "Reply All" },
        { text: "Forward" },
        { text: "Delete" }
    ],
    showActionSheet: function () {
        viewModel.isActionSheetVisible(true);
    }
};

ko.applyBindings(viewModel);

If you use jQuery alone, combine the HTML markup for items manually with jQuery DOM manipulation methods. To apply this markup, use the itemTemplate callback function as shown in the following code.

JavaScript
$(function() {
    $("#actionSheetContainer").dxActionSheet({
        dataSource: [
            { text: "Reply", icon: 'arrowleft' },
            { text: "Reply All", icon: 'arrowleft' },
            { text: "Forward", icon: 'arrowright' },
            { text: "Delete", icon: 'close' }
        ],
        itemTemplate: function (itemData, itemIndex, itemElement) {
            var linkContainer = $("<div style='margin:5px; padding:10px; border:1px dotted #080; background-color:white;'>");
            linkContainer.append("<a href='#'>" + itemData.text + "</a>");
            itemElement.append(linkContainer);
        }
    });
});

You can also customize an individual ActionSheet button. For this purpose, declare a template for this button as a script and pass its id to the template field.

HTML
<script id="individualTemplate" type="text/html">
    <!-- ... -->
</script>
JavaScript
var actionSheetData = [
    { text: "Reply", template: $('#individualTemplate') },
    { text: "Reply All" },
    // ...
];

In addition, you can use a 3rd-party template engine to customize widget appearance. For more information, see the Use an Alternative Template Engine article.

See Also