JavaScript/jQuery ActionSheet - Customize Item Appearance

For a minor customization of ActionSheet buttons, you can define specific fields in button data objects. 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.

If you need a more flexible solution, define an itemTemplate. In Angular and Vue, you can declare it in the markup. In React, you can use a rendering function (shown in the code below) or component:

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

JavaScript
CSS
  • $(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) {
  • const linkContainer = $("<div class='action-sheet-button'>");
  • linkContainer.append("<a href='#'>" + itemData.text + "</a>");
  • itemElement.append(linkContainer);
  • }
  • });
  • });
  • .action-sheet-button {
  • margin: 5px;
  • padding: 10px;
  • border: 1px dotted #080;
  • background-color: white;
  • }

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
JavaScript
  • <script id="individualTemplate" type="text/html">
  • <!-- ... -->
  • </script>
  • const actionSheetData = [
  • { text: "Reply", template: $('#individualTemplate') },
  • { text: "Reply All" },
  • // ...
  • ];

In addition, you can use a 3rd-party template engine to customize UI component appearance. For more information, see the 3rd-Party Template Engines article.

See Also