We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Dropdown for custom command in grid

Hi, 
Is there a way to render command buttons as a dropdown button for asp .net core?
Thank you

3 Replies

PK Prasanna Kumar Viswanathan Syncfusion Team January 21, 2020 05:03 AM

Hi Muhamad, 
 
Thanks for contacting Syncfusion support. 
 
Query: “Is there a way to render command buttons as a dropdown button for asp .net core? 
 
To render the dropdown button we have used template property of EJ2 Grid Column. Please refer the below code example and sample to achieve your requirement. 
 
 
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" queryCellInfo="template" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })"> 
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog"></e-grid-editSettings> 
   <e-grid-columns> 
        .  .  .  .  .  .  . 
        <e-grid-column headerText="Dropdown Button" template="#columnTemplate" width="150"></e-grid-column> 
        .  .  .  .  .  .  . 
   </e-grid-columns> 
</ejs-grid> 
 
<script type="text/x-jsrender" id="columnTemplate"> 
 
    <button class="List">Ações</button> 
 
</script> 
 
<script type="text/javascript"> 
    var data = [ 
        { text: "Visualizar", iconCss: "fa fa-eye" }, 
        { text: "Editar", iconCss: "fa fa-edit" }, 
        { text: "Excluir", iconCss: "fa fa-trash" }, 
        { text: "Liberar p/ Gerência", iconCss: "fa fa-user" }, 
        { text: "Baixar", iconCss: "fa fa-check" }, 
        { text: "Estornar", iconCss: "fa fa-mail-reply" }, 
        { text: "Pagto Parcelado", iconCss: "fa fa-list-ol" } 
    ]; 
    function template(args) { 
        var ele = args.cell.querySelector('.List'); 
        var drop = new ej.splitbuttons.DropDownButton({ 
            popupHeight: 150, 
            popupWidth: 200, 
            items: data 
        }); 
 
        drop.appendTo(ele); 
    } 
 
</script> 
 
 

 
 
 
Regards, 
Prasanna Kumar N.S.V 



MA Muhamad Adam Fakhrullah Nik Mohamad January 22, 2020 03:42 AM

And can i know how to make child grid appear  when we click the item from dropdown ? for example like this picture 



DR Dhivya Rajendran Syncfusion Team January 23, 2020 08:28 AM

Hi Muhamad, 

Thanks for your update. 
 
Query: “how to make child grid appear  when we click the item from dropdown” 

As per your requirement, we have created a sample. In the below sample, we have rendered dialog component in dataBound event and set visibility false for dialog at initial rendering and shown the dialog whenever we click the dropdown button in grid. Please refer to the below code and modified sample link. 

  var flag = true; 
    var dialogObj; 
    function dataBound(args) { 
        if (flag) { 
            dialogObj = new ej.popups.Dialog({ 
                showCloseIcon: true, 
                target: document.getElementById('e-content'), 
                . . . . 
                visible: false, 
                header: 'Trip Details', 
                content: '<div id="Grid2"></div>', 
                created: function (args) { 
                    var grid = new ej.grids.Grid({ 
                        dataSource: data1, 
                    }); 
                    grid.appendTo('#Grid2'); 
                } 
 
            }); 
            dialogObj.appendTo('#wrapper'); 
            flag = false; 
        } 
    } 
    var data1 = @Html.Raw(Json.Serialize(ViewBag.DataSource));  
     
    function template(args) { 
        var ele = args.cell.querySelector('.List'); 
        var drop = new ej.splitbuttons.DropDownButton({ 
            popupHeight: 150, 
            popupWidth: 200, 
            items: data, 
            select: function (args) { 
                dialogObj.show(); 
            } 
        }); 
        drop.appendTo(ele); 
    } 

Please get back to us, if you need any further assistance. 

Regards, 
R.Dhivya 


Loader.
Live Chat Icon For mobile
Up arrow icon