show toast when toolbar grid button clicked

I've added toast function when button on the grid toolbar is clicked.
but it quickly disappear
I've followed the instruction on the documentation of toast, it works when I create button(outside toolbar grid)
, but when I call toast on the grid toolbar it quickly disappear..
here some of my initialized toast for toolbar button, with 'wizardAdd' as button toolbar grid id

-------------------------

-------------------



1 Reply

NS Nithya Sivaprakasam Syncfusion Team July 26, 2022 01:00 PM UTC

Hi Bernadus,


Greetings from Syncfusion support.


Query:” Show toast when toolbar grid button clicked”


Based on your query we suspect that you want to show a toast when the toolbar button was clicked. To achieve your query, kindly check the below code for reference.


Example code:


[Index.cshtml]

 

@{

    List<object> toolbarItems = new List<object>();

    toolbarItems.Add("PdfExport");

    toolbarItems.Add("ExcelExport");

    toolbarItems.Add(new { text: 'WizAdd',

      tooltipText: 'Wizard Add',

      prefixIcon: 'e-export',

      id: 'WizardAdd',});

}

 

@Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.DataSource).ToolbarClick("toolbarClick").Columns(col =>

{

   col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();

   col.Field("Freight").HeaderText("Freight").Width("120").EditType("numericedit").Format("C2").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();

   col.Field("ShipName").HeaderText("Ship Name").Width("150").Add();

   col.Field("ShipCountry").HeaderText("Ship Country").Width("150").EditType("dropdownedit").Add();

 

}).AllowPaging().PageSettings(page => page.PageCount(2)).Toolbar(toolbarItems).Render()

 

<script>

var toasts = [

  {

    title: 'Information !',

    content: 'Please read the comments carefully.',

    cssClass: 'e-toast-info',

    click: onClick,

  },

];

let toast = new Toast({

  position: { X: 'Right', Y: 'Bottom' },

});

toast.appendTo('#element');

function onClick(e) {

  e.clickToClose = true;

}

    function toolbarClick(args) {

   if (args.item.id === 'WizardAdd') {

      toast.show(toasts[0]);

    }    }

</script>


For your reference, we have attached the video demonstration. Kindly check the video demo.


Please get back to us if you need further assistance on this.


Regards,

Nithya Sivaprakasam.


Attachment: Toast_68eaade.zip

Loader.
Up arrow icon