Vue 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.
jQuery
$(function() { $("#actionSheetContainer").dxActionSheet({ dataSource: [ { text: "Reply" }, { text: "Reply All", disabled: true }, { text: "Delete", type: 'danger' } ] }); });
Angular
<dx-action-sheet [dataSource]="actionSheetData" </dx-action-sheet>
import { DxActionSheetModule } from "devextreme-angular"; // ... export class AppComponent { actionSheetData = [ { text: "Reply" }, { text: "Reply All", disabled: true }, { text: "Delete", type: 'danger' } ] } @NgModule({ imports: [ // ... DxActionSheetModule ], // ... })
Vue
<template> <DxActionSheet :data-source="actionSheetData" </DxActionSheet> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxActionSheet from 'devextreme-vue/action-sheet'; export default { components: { DxActionSheet }, data() { return { actionSheetData: [ { text: "Reply" }, { text: "Reply All", disabled: true }, { text: "Delete", type: 'danger' } ] }; } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { ActionSheet } from 'devextreme-react/action-sheet'; class App extends React.Component { constructor(props) { super(props); this.actionSheetData = [ { text: "Reply" }, { text: "Reply All", disabled: true }, { text: "Delete", type: 'danger' } ]; } render() { return ( <ActionSheet dataSource={this.actionSheetData} /> ); } } export default App;
If you need a more flexible solution, define an itemTemplate.
jQuery
$(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; }
Angular
<dx-action-sheet [dataSource]="actionSheetData" [visible]="isActionSheetVisible" itemTemplate="link"> <div *dxTemplate="let item of 'link'"> <div class="action-sheet-button"> <a href="#">{{item.text}}</a> </div> </div> </dx-action-sheet>
import { DxActionSheetModule } from "devextreme-angular"; // ... export class AppComponent { actionSheetData = [ { text: "Reply" }, { text: "Reply All" }, { text: "Forward" }, { text: "Delete" } ]; isActionSheetVisible: Boolean = true; } @NgModule({ imports: [ // ... DxActionSheetModule ], // ... })
.action-sheet-button { margin: 5px; padding: 10px; border: 1px dotted #080; background-color: white; }
Vue
<template> <DxActionSheet v-model:visible="isActionSheetVisible" :data-source="actionSheetData" item-template="link"> <template #link="{ data }"> <div class="action-sheet-button"> <a href="#">{{data.text}}</a> </div> </template> </DxActionSheet> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxActionSheet from 'devextreme-vue/action-sheet'; export default { components: { DxActionSheet }, data() { return { isActionSheetVisible: true, actionSheetData: [ { text: "Reply" }, { text: "Reply All" }, { text: "Forward" }, { text: "Delete" } ] }; } } </script> <style> .action-sheet-button { margin: 5px; padding: 10px; border: 1px dotted #080; background-color: white; } </style>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { ActionSheet } from 'devextreme-react/action-sheet'; class App extends React.Component { constructor(props) { super(props); this.state = { isActionSheetVisible: true }; this.actionSheetData = [ { text: "Reply" }, { text: "Reply All" }, { text: "Forward" }, { text: "Delete" } ]; this.renderActionSheetItem = (itemData) => { return ( <div class="action-sheet-button"> <a href="#">{itemData.text}</a> </div> ); }; } render() { return ( <ActionSheet visible={this.state.isActionSheetVisible} dataSource={this.actionSheetData} itemRender={this.renderActionSheetItem} /> ); } } export default App;
.action-sheet-button { margin: 5px; padding: 10px; border: 1px dotted #080; background-color: white; }
jQuery
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.
<script id="individualTemplate" type="text/html"> <!-- ... --> </script>
const actionSheetData = [ { text: "Reply", template: $('#individualTemplate') }, { text: "Reply All" }, // ... ];
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.