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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Add DropDownButton to cell in Grid with rowTemplate

Thread ID:

Created:

Updated:

Platform:

Replies:

142415 Feb 1,2019 01:30 PM UTC Feb 6,2019 08:58 AM UTC JavaScript - EJ 2 5
loading
Tags: Grid
Pieter-Jan
Asked On February 1, 2019 01:30 PM UTC

Hi,

I'm trying to add a DropDownButton to te first cell of all rows in a Grid. The problem is that the DropDownButton does not want to load, even if I place it in the "created" event.
I'm using a rowTemplate. How can I add a dropdownbutton (with custom actions) to this template?

Alternative solution would be to open the context menu of the grid when clicking on a button in my grid.

<script>
        $(function() {
            var grid = new ejs.grids.Grid({
                dataSource: @Html.Raw(ViewBag.employees),
                allowPaging: true,
                allowSorting: true,
                rowTemplate: '#rowTemplate',
                columns: [
                    { columnName: 'Id', field: 'Id', visible: false },
                    { columnName: 'FirstName', field: 'FirstName', visible: false },
                    { columnName: 'LastName', field: 'LastName', visible: false },
                    { columnName: 'Email', field: 'Email', visible: false }
                ],
                created: function() {
                    var items = [
                        {
                            text: 'Detail'
                        },
                        {
                            text: 'Send Message'
                        },
                        {
                            text: 'Delete'
                        }];

                    // initialize DropDownButton control
                    var drpDownBtn = new ejs.splitbuttons.DropDownButton({items: items});

                    // Render initialized DropDownButton.
                    drpDownBtn.appendTo('.employee-button');
                }
            });
            grid.appendTo('#employee-grid');

            //var gridObj = document.getElementById("employee-grid").ej2_instances[0];
            //gridObj.sortColumn('Id', 'ascending'):
        });
       
    </script>
   
    <script id="rowTemplate" type="text/x-template">
    <tr class="">
        <td>
            <div class="col-sm-2">
                <button class="employee-button">Options</button>
            </div>
            <div class="col-sm-3">
                ${FirstName}
            </div>
            <div class="col-sm-3">
                ${LastName}
            </div>
            <div class="col-sm-3">
                ${Email}
            </div>
        </td>       
    </tr>
   
    </script>

Madhu Sudhanan P [Syncfusion]
Replied On February 4, 2019 06:08 AM UTC

Hi Pieter, 

Thanks for contacting Syncfusion support. 

You can render the template element to custom component inside the dataBound event as follows. 


new ejs.grids.Grid({ 
        .... 
        dataBound: function() { 
            var items = [ 
                { 
                    text: 'Detail' 
                }, 
                { 
                    text: 'Send Message' 
                }, 
                { 
                    text: 'Delete' 
                }]; 
 
            // initialize DropDownButton control 
            var drpDownBtn = new ejs.splitbuttons.DropDownButton({items: items}); 
 
            // Render initialized DropDownButton. 
            drpDownBtn.appendTo('.employee-button'); 
        } 
    }); 
    grid.appendTo('#Grid'); 
 

Regards, 
Madhu Sudhanan P 


Pieter-Jan
Replied On February 5, 2019 09:50 AM UTC

Hi Madhu,

Thanks for the quick reply. Your solution works, but only for the first element. The dropdown menu is rendered on the first button in the first row, but not in the following rows.
As you can see in the attached screenshot, the second and third button are not dropdowns.

As a follow-up question, is it possible to attach events to the dropdown menu? Or do I register these events after the rendering?

Thanks!

Madhu Sudhanan P [Syncfusion]
Replied On February 6, 2019 06:14 AM UTC

Hi Pieter, 

Thanks for the update. 

We have modified the solution using dataBound event as follow to render all row dropdowns and also registered selected event to the DropDownButton list item. 


var grid = new ejs.grids.Grid({ 
       .... 
        dataBound: function () { 
            var items = [ 
                { 
                    text: 'Detail' 
                }, 
                { 
                    text: 'Send Message' 
                }, 
                { 
                    text: 'Delete' 
                }]; 
            var btns = this.element.querySelectorAll('.employee-button'); 
            for (var i = 0; i < btns.length; i++) { 
                var drpDownBtn = new ejs.splitbuttons.DropDownButton({ 
                    items: items, 
                    select: function (e) { 
                        alert(e.item.text) 
                    } 
                }); 
 
                drpDownBtn.appendTo(btns[i]); 
            } 
        } 
    }); 




Regards, 
Madhu Sudhanan P 


Pieter-Jan
Replied On February 6, 2019 08:52 AM UTC

Perfect! It works!
Thanks for the help.

Madhu Sudhanan P [Syncfusion]
Replied On February 6, 2019 08:58 AM UTC

Hi Pieter, 
Thanks for the update. Please get back to us if you need any assistance. 
Regards, 
Madhu Sudhanan P 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon