DataGrid Row Template with dropdown menu not working all of the time

I'm using a template row to include a column that has a dropdown menu with multiple actions. Each one of the options will open a different bootstrap modal. The partial view loads in a placeholder div. 

It works when the grid doesn't have scroll bars. However when I do a search, scrollbars are displayed and my modal will not open. 

Is there a reason why the bootstrap modal will not open when there are scrollbars?

Here is my code:

<div id="modal-placeholder"></div>
    <script id="rowtemplate" type="text/x-template">
        <tr>
            <td>
                ${firstName}
            </td>
            <td>
                ${lastName}
            </td>
            <td>
                ${email}
            </td>
            <td>
                ${homePhone}
            </td>
            <td>
                ${cellPhone}
            </td>
            <td>
                ${workPhone}
            </td>
            <td>
                ${currentStatus}
            </td>
            <td>
                <ul class="navbar-nav align-items-center d-none d-md-flex">
                    <li class="nav-item dropdown">
                        <a class="nav-link pr-0" rel='nofollow' href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            <div class="media align-items-center">
                                <div class="media-body ml-2 d-none d-lg-block">
                                    <img src="../images/3dotsicon_36x14.svg" />
                                </div>
                            </div>
                        </a>
                        <div class="dropdown-menu dropdown-menu-arrow dropdown-menu-right">
                            <div class=" dropdown-header">
                            </div>
                            <button type="button" class="dropdown-item" data-toggle="ajax-modal" data-target="#edit-client" data-url="/Home/EditClient/${id}" title="Edit">Edit</button>
                            <button type="button" class="dropdown-item" data-toggle="ajax-modal" data-target="#inactivateClient" data-url="/Home/Inactivate/${id}" title="Inactivate Client">Inactivate</button>
                            <button type="button" class="dropdown-item" data-toggle="ajax-modal" data-target="#add-comment" data-url="/Home/AddComment/${id}" title="Add Comment">Add Comment</button>
                            <button type="button" class="dropdown-item" data-toggle="ajax-modal" data-target="#send-message" data-url="/Home/SendMessage/${id}" title="Send Message">Send Message</button>
                        </div>
                    </li>
                </ul>
            </td>
        </tr>
    </script>

<ejs-grid id="Grid" class="table table-striped" dataSource="@Model" rowTemplate="#rowtemplate" allowPaging="true" allowSorting="true" allowExcelExport="true" toolbarClick="toolbarClick" toolbar="@(new List<string>() {"ExcelExport", "Search" })">
        <e-grid-searchSettings fields="@(new string[] { "lastName"})" operator="contains" ignoreCase="true"></e-grid-searchSettings>
        <e-grid-editSettings allowAdding="false" allowDeleting="false" allowEditing="false" mode="Normal"></e-grid-editSettings>
        <e-grid-columns>
            <e-grid-column headerText="First Name" width="125"></e-grid-column>
            <e-grid-column headerText="Last Name" width="120"></e-grid-column>
            <e-grid-column headerText="Email" width="120"></e-grid-column>
            <e-grid-column headerText="Home Phone" width="120"></e-grid-column>
            <e-grid-column headerText="Cell Phone" width="120"></e-grid-column>
            <e-grid-column headerText="Work Phone" width="120"></e-grid-column>
            <e-grid-column headerText="Status" width="120"></e-grid-column>
            <e-grid-column headerText="" width="50"></e-grid-column>
        </e-grid-columns>
    </ejs-grid>

<script>

$(function () {
    var placeholderElement = $('#modal-placeholder');

    /// Check if Follow-Up is checked
    var isFollowUp = $('#isFollowUp');

    $('button[data-toggle="ajax-modal"]').click(function (event) {
        var url = $(this).data('url');
        $.get(url).done(function (data) {
            placeholderElement.html(data);
            placeholderElement.find('.modal').modal('show');
        });
    });

    placeholderElement.on('click', '[data-save="modal"]', function (event) {
        event.preventDefault();

        var form = $(this).parents('.modal').find('form');
        var actionUrl = form.attr('action');
        var dataToSend = new FormData(form.get(0));

        
        $.ajax({ url: actionUrl, method: 'post', data: dataToSend, processData: false, contentType: false }).done(function (data) {
            var newBody = $('.modal-body', data);
            placeholderElement.find('.modal-body').replaceWith(newBody);

            var html = $($.parseHTML(data));
            var isValid = html.find('[name="IsValid"]').val() == 'True';
            if (isValid) {
                placeholderElement.find('.modal').modal('hide');
                location.reload();
                //Change from reload to update the section of code
            }
            else {
                /// Check if Follow-Up is checked
                var isFollowUp = $('#isFollowUp');

                if ($(isFollowUp).is(":checked")) {
                    $("#followUpInfo").show();
                } else {
                    $("#followUpInfo").hide();
                }
            }
        });
    });
});

</script> 

5 Replies 1 reply marked as answer

SK Sujith Kumar Rajkumar Syncfusion Team August 28, 2020 01:07 PM UTC

Hi Stephen, 

Greetings from Syncfusion support. 

We checked your query and could understand that you have rendered row template in the Grid and the problem you are facing is occurring on performing the search in the Grid. We would like to let you know that the searching functionality of the Grid is not supported with the row template. 

If we misunderstood you query or if you require any further assistance, then please get back to us. 

Regards, 
Sujith R 



SH Stephen Hall August 28, 2020 01:28 PM UTC

When I do a search in the DataGrid. My template row displays. However, the JQuery doesn't work on the column that has a custom button that is to trigger a modal. The JQuery works when the DataGrid first renders. 

Here is a screenshot of the rowtemplate. It renders the row, my dropdown works, but when I click on the item in the dropdown the modal doesn't open.




RS Rajapandiyan Settu Syncfusion Team September 1, 2020 03:01 PM UTC

Hi Stephen, 

Thanks for your update. 

By default in EJ2 Grid, the rowTemplate feature does not support Search action. i.e. element rendering and event firing of the row template elements is not working properly after performing the search action in Grid, since the rowTemplate does not support the Searching feature. 

Please get back to us if you need further assistance. 

Regards, 
Rajapandiyan S 



SH Stephen Hall September 9, 2020 10:25 AM UTC

I removed search from my DataGrid and my issue still exists. My template row still doesn't fire my function when I click on my buttons in the column.

The button in the rowTemplate is 

<button type="button" class="dropdown-item" data-toggle="ajax-modal" data-target="#inactivateClient" data-url="/Home/Inactivate/${id}" title="Inactivate Client">Inactivate</button>

When clicking on this button, it should open a Bootstrap Modal to confirm the action.

Here is the JavaScript to open the modal:

$(function () {
    var placeholderElement = $('#modal-placeholder');

    /// Check if Follow-Up is checked
    var isFollowUp = $('#isFollowUp');

    $('button[data-toggle="ajax-modal"]').click(function (event) {
        var url = $(this).data('url');
        $.get(url).done(function (data) {
            placeholderElement.html(data);
            placeholderElement.find('.modal').modal('show');
        });
    });

    placeholderElement.on('click', '[data-save="modal"]', function (event) {
        event.preventDefault();

        var form = $(this).parents('.modal').find('form');
        var actionUrl = form.attr('action');
        //var dataToSend = form.serialize();
        var dataToSend = new FormData(form.get(0));

        
        //$.post(actionUrl, dataToSend).done(function (data) {
        $.ajax({ url: actionUrl, method: 'post', data: dataToSend, processData: false, contentType: false }).done(function (data) {
            var newBody = $('.modal-body', data);
            placeholderElement.find('.modal-body').replaceWith(newBody);

            var html = $($.parseHTML(data));
            var isValid = html.find('[name="IsValid"]').val() == 'True';
            if (isValid) {
                placeholderElement.find('.modal').modal('hide');
                location.reload();
                //Change from reload to update the section of code
            }
            else {
                /// Check if Follow-Up is checked
                var isFollowUp = $('#isFollowUp');

                if ($(isFollowUp).is(":checked")) {
                    $("#followUpInfo").show();
                } else {
                    $("#followUpInfo").hide();
                }
            }
        });
    });
});




VS Vignesh Sivagnanam Syncfusion Team September 10, 2020 01:14 PM UTC

Hi Stephen 

Thanks for the update. 

Based on your query we found that the button element does not fire the click event in the rowTemplate. To fire the click event we suggest you to define the onclick event within the button element like below code example 

Please refer the Sample, Documentation and code Example for your reference  

Code Example :  
<button type="button" class="dropdown-item" onclick="myFunction()"  title="Edit">Edit</button><br /> 

 

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

Regards, 
Vignesh Sivagnanam 


Marked as answer
Loader.
Up arrow icon