Action buttons in EJ2 TypeScript Toast control

7 May 20253 minutes to read

You can include action buttons to the toast control by adding the buttons property. The collection of Essential® JS 2 button models can be bound to the model property inside the buttons property. You can also include the click event callback function for each button.

import {Toast} from '@syncfusion/ej2-notifications';
import { enableRipple, closest} from '@syncfusion/ej2-base';

enableRipple(true);
let toast: Toast = new Toast({
    title: 'Anjolie Stokes',
    content: 'Thanks for the update!',
    icon: 'e-laura',
    position: { X: "Right", Y: "Bottom" },
    width: 280,
    height: 120,
        buttons : [{
        model: { content: "Ignore" }, click: btnClick
    }, {
      model: { content: "reply" }
    }]
});
toast.appendTo('#elementToastTime');
toast.show();

document.getElementById('show_toast').onclick = () => {
  toast.show();
}

function btnClick(e: Event) {
 let toastEle = closest(e.target, '.e-toast');
 toast.hide(toastEle);
}
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Essential JS 2 Toast</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript Toolbar Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="https://cdn.syncfusion.com/ej2/29.2.4/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<style>
.e-toast-icon.e-laura.e-icons {
    border-radius: 50%;
    background-repeat: no-repeat;
    background-size: cover;
    background-image: url(https://ej2.syncfusion.com/vue/demos/src/toast/resource/laura.png);
    height: 44px !important;
    margin: 0;
    width: 60px;
}
#elementToastTime .e-toast-message {
    padding: 10px;
}
</style>
<body>
    <div id='loader'>LOADING....</div>
    <div id='container'>
        <div class='row'> <button class="e-btn" id="show_toast"> Show Toast</button> </div>
        <div id='element'></div>
        <div id="elementToastTime"></div>
        <br/><br/>
        <div id='result'></div>
    </div>
</body>

</html>

See Also