Show multiple toasts in various positions in EJ2 TypeScript Toast control

10 May 20233 minutes to read

By default, the positions of the new toasts are only updated after the visible toasts have been destroyed. If You need to display multiple toasts with different positions, initiate another toasts.

The following sample demonstrates adding multiple toasts in different positions.

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

enableRipple(true);

let toast: Toast = new Toast({
    title: 'Warning !',
    content: 'There was a problem with your network connection.'
    position: { X: 'Right', Y: 'Bottom' }
    click: onClick
});
toast.appendTo('#element');
toast.show();

let toast1: Toast = new Toast({
    title: 'Success !',
    content: 'Your message has been sent successfully.'
    position: { X: 'Left', Y: 'Bottom' }
    click: onClick
});
toast1.appendTo('#element1');
toast1.show();

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

document.getElementById('show_toast1').onclick = () => {
  toast1.show();
}

function onClick(e: ToastClickEventArgs ): void {
  e.clickToClose = true;
}
<!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/27.2.2/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>

<body>
    <div id='loader'>LOADING....</div>
    <div id='container'>
        <div class='row'> <button class="e-btn" id="show_toast">Show Right Position Toast</button> </div>
        <div class='row'> <button style="margin-left: 10px;" class="e-btn" id="show_toast1">Show Left Position Toast</button> </div>
        <div id='element'></div>
        <div id='element1'></div>
    </div>
</body>

</html>