Kendo UI (jquery): grid filters not working inside a bootstrap Modal

1 Answer 17 Views
Grid
Giovanni
Top achievements
Rank 1
Iron
Iron
Iron
Giovanni asked on 23 Apr 2025, 10:32 AM

I'm using Kendo UI for jquery to show a grid in a bootstrap modal window.

The grid has column header filters, but the user cannot input text in the filter.

You can test this issue using this example:

https://dojo.telerik.com/ESmbjbbT/4


The full example code is:

<!DOCTYPE html>
<html>
<head>
    <base href="https://demos.telerik.com/kendo-ui/grid/filter-row">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link href="https://kendo.cdn.telerik.com/themes/10.2.0/default/default-main.css" rel="stylesheet" />
    <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
    
    
    
    <script src="https://kendo.cdn.telerik.com/2025.1.227/js/kendo.all.min.js"></script>
  
  	<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.5/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-SgOJa3DmI69IUzQ2PVdRZhwQ+dy64/BUtbMJw1MZ8t5HZApcHrRKUc4W0kG879m7" crossorigin="anonymous">
	<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.5/dist/js/bootstrap.bundle.min.js" integrity="sha384-k6d4wzSIapyDyv1kpU366/PK5hCdSbCRGRCMv+eplOQJWyd1fbcAu9OCUj5zNLiq" crossorigin="anonymous"></script>
    
    
</head>
<body>
    <div id="example">


    
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModal" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        <div id="grid" />
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
      
    <script>
        $(document).ready(function() {
            $("#grid").kendoGrid({
                dataSource: {
                    type: "odata",
                    transport: {
                        read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
                    },
                    schema: {
                        model: {
                            fields: {
                                OrderID: { type: "number" },
                                Freight: { type: "number" },
                                ShipName: { type: "string" },
                                OrderDate: { type: "date" },
                                ShipCity: { type: "string" }
                            }
                        }
                    },
                    pageSize: 20,
                    serverPaging: true,
                    serverFiltering: true,
                },
                height: 550,
                filterable: true,
                pageable: true,
                columns: 
                [{
                    field: "OrderID",
                    width: 80,
                    filterable: {
                        cell: {
                            showOperators: false
                        }
                    }
                },
                {
                    field: "ShipName",
                    width: 180,
                    title: "Ship Name",
                    filterable: {
                        cell: {
                            operator: "contains",
                            suggestionOperator: "contains"
                        }
                    }
                },{
                    field: "Freight",
                    width: 80,
                    filterable: {
                        cell: {
                            operator: "gte"
                        }
                    }
                },{
                    field: "OrderDate",
                    width: 95,
                    title: "Order Date",
                    format: "{0:MM/dd/yyyy}"
                }]
            });

          
        });
    </script>
</div>



</body>
</html>

1 Answer, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 28 Apr 2025, 05:38 AM

Hello Giovanni,

In a scenario where the Grid is displayed in a Bootstrap Modal, the modal will steal the focus. 

- We have a knowledge base article that describes a possible approach to avoid this behavior. However, the approach is suitable when Bootstrap 3 is used: https://docs.telerik.com/kendo-ui/knowledge-base/kendo-grid-filter-input-focus-bootstrap-modal

- With Bootstrap 5.0.1 you can handle the filterMenuOpen event of the Grid as a workaround and you can remove the tabindex attribute from the Modal once the filter menu popup is shown. Once the filter menu is closed you can add the tabindex attribute back.

filterMenuOpen: function(e) {
            $("#myModal").removeAttr("tabindex");
            e.container.data("kendoPopup").one("close", function(e) {
              $("#myModal").attr("tabindex", -1);
            });
}

Here is such Dojo example: https://dojo.telerik.com/dfTbuIxE 

- However, I am afraid that with Bootstrap 5.2.x or 5.3.x  I could not suggest a workaround to overcome the issue with stealing the focus. As mentioned in the Known Limitation section linked here: Bootstrap modal dialogs prevent access to Kendo UI popups, which are opened by components placed inside the modal dialog. In such cases, use non-modal Bootstrap dialogs or modal Kendo UI Windows.

With the above said I would reccomend consider using Kendo UI modal Window - https://docs.telerik.com/kendo-ui/api/javascript/ui/window/configuration/modal 

I remain at your disposal in case you have further questions. 

 

Regards,
Neli
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Grid
Asked by
Giovanni
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Neli
Telerik team
Share this question
or