Open a dialog on popup item click

28 Feb 20222 minutes to read

This section explains about how to open a dialog on SplitButton popup item click. This can be achieved by handling dialog open in select event of the SplitButton.

In the following example, Dialog will open while selecting Update... item:

@Html.EJS().Dialog("dialog").Header("Software Update").Content("Are you sure want to update?").Width("250px").Visible(false).Buttons(ViewBag.button).Render()
@Html.EJS().SplitButton("element").Content("Help").Items((IEnumerable<object>)ViewBag.items).Select("onSelect").Render()


<script>
    function onSelect(args) {
        if (args.item.text === 'Update...') {
            ej.base.getComponent(document.getElementById('dialog'), "dialog").show();
        }
    }

    function okBtnClick() {
        ej.base.getComponent(document.getElementById('dialog'), "dialog").hide();
    }

    function cancelBtnClick() {
        ej.base.getComponent(document.getElementById('dialog'), "dialog").hide();
    }
</script>

<style>
    .e-split-btn-wrapper{
        margin: 20px 20px 5px 5px;
    }
</style>
public ActionResult DialogButton()
{
    List<object> buttons = new List<object>() { };
    buttons.Add(new
    {
        isPrimary = true,
        cssClass = "e-flat",
        content = "ok",
        click = "okBtnClick"
    });
    buttons.Add(new
    {
        isPrimary = true,
        cssClass = "e-flat",
        content = "cancel",
        click = "cancelBtnClick"
    });
    ViewBag.DialogButtons = buttons;
    return View();
}