|
| 1 | +--- |
| 2 | +title: Filter both Parent and Child Grids in Hierarchy |
| 3 | +description: An example on how to apply filters on both parent and child Grids in Hierarchy. |
| 4 | +type: how-to |
| 5 | +page_title: Update Adjacent Cells in Rows in Inline Edit Mode | Kendo UI Grid for jQuery |
| 6 | +slug: grid-apply-filter-parent-child |
| 7 | +tags: grid, filter, parent, child, hierarchy, detail |
| 8 | +ticketid: 1573560 |
| 9 | +res_type: kb |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +<table> |
| 15 | + <tr> |
| 16 | + <td>Product</td> |
| 17 | + <td>Progress Kendo UI Grid</td> |
| 18 | + </tr> |
| 19 | + <tr> |
| 20 | + <td>Operating System</td> |
| 21 | + <td>All</td> |
| 22 | + </tr> |
| 23 | + <tr> |
| 24 | + <td>Browser</td> |
| 25 | + <td>All</td> |
| 26 | + </tr> |
| 27 | + <tr> |
| 28 | + <td>Browser Version</td> |
| 29 | + <td>All</td> |
| 30 | + </tr> |
| 31 | +</table> |
| 32 | + |
| 33 | +## Description |
| 34 | + |
| 35 | +How can I apply filter to both the parent and child Grids in Hierarchy? |
| 36 | + |
| 37 | +## Solution |
| 38 | + |
| 39 | +It is possible to perform filtering over the parent Grid and the child Grid by ensuring the fetching of the filtered data for the parent Grid has finished. This is done by applying the filter to the child Grid in the [`dataBound`](/api/javascript/ui/grid/events/databound) event handler of the parent one. |
| 40 | + |
| 41 | +```dojo |
| 42 | + <button class="k-button k-button-solid-base k-button-solid k-button-md k-rounded-md" onclick="filter()">Filter Parent and Child</button> |
| 43 | + <div id="grid"></div> |
| 44 | +
|
| 45 | + <script type="text/x-kendo-template" id="template"> |
| 46 | + <div class="orders"></div> |
| 47 | + </script> |
| 48 | +
|
| 49 | + <script> |
| 50 | + $(document).ready(function() { |
| 51 | + var element = $("#grid").kendoGrid({ |
| 52 | + dataSource: { |
| 53 | + type: "odata", |
| 54 | + transport: { |
| 55 | + read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Employees" |
| 56 | + }, |
| 57 | + pageSize: 20, |
| 58 | + serverPaging: true, |
| 59 | + serverSorting: true |
| 60 | + }, |
| 61 | + height: 400, |
| 62 | + filterable: true, |
| 63 | + sortable: true, |
| 64 | + pageable: false, |
| 65 | + detailTemplate: kendo.template($("#template").html()), |
| 66 | + detailInit: detailInit, |
| 67 | + dataBound: function() { |
| 68 | + this.expandRow(this.tbody.find("tr.k-master-row").first()); |
| 69 | + }, |
| 70 | + columns: [ |
| 71 | + { |
| 72 | + field: "FirstName", |
| 73 | + title: "First Name", |
| 74 | + width: "120px" |
| 75 | + }, |
| 76 | + { |
| 77 | + field: "LastName", |
| 78 | + title: "Last Name", |
| 79 | + width: "120px" |
| 80 | + }, |
| 81 | + { |
| 82 | + field: "Country", |
| 83 | + width: "120px" |
| 84 | + }, |
| 85 | + { |
| 86 | + field: "City", |
| 87 | + width: "120px" |
| 88 | + }, |
| 89 | + { |
| 90 | + field: "Title" |
| 91 | + } |
| 92 | + ] |
| 93 | + }); |
| 94 | + }); |
| 95 | +
|
| 96 | + function detailInit(e) { |
| 97 | + var detailRow = e.detailRow; |
| 98 | +
|
| 99 | + detailRow.find(".detailTabstrip").kendoTabStrip({ |
| 100 | + animation: { |
| 101 | + open: { effects: "fadeIn" } |
| 102 | + } |
| 103 | + }); |
| 104 | +
|
| 105 | + detailRow.find(".orders").kendoGrid({ |
| 106 | + dataSource: { |
| 107 | + type: "odata", |
| 108 | + transport: { |
| 109 | + read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders" |
| 110 | + }, |
| 111 | + serverPaging: true, |
| 112 | + serverSorting: true, |
| 113 | + serverFiltering: true, |
| 114 | + pageSize: 7, |
| 115 | + filter: { field: "EmployeeID", operator: "eq", value: e.data.EmployeeID } |
| 116 | + }, |
| 117 | + scrollable: false, |
| 118 | + filterable: true, |
| 119 | + sortable: true, |
| 120 | + pageable: true, |
| 121 | + columns: [ |
| 122 | + { field: "OrderID", title:"ID", width: "70px" }, |
| 123 | + { field: "ShipCountry", title:"Ship Country", width: "110px" }, |
| 124 | + { field: "ShipAddress", title:"Ship Address" }, |
| 125 | + { field: "ShipName", title: "Ship Name", width: "300px" } |
| 126 | + ] |
| 127 | + }); |
| 128 | + } |
| 129 | +
|
| 130 | + function filter() { |
| 131 | + var mainGrid = $("#grid").data("kendoGrid"); |
| 132 | + mainGrid.dataSource.filter({ field: "City", operator: "eq", value: "Seattle" }) |
| 133 | + mainGrid.bind("dataBound", function() { |
| 134 | + var detailGrid = $(".orders").data("kendoGrid"); |
| 135 | + detailGrid.dataSource.filter({ field: "ShipCountry", operator: "eq", value: "Italy" }) |
| 136 | + }) |
| 137 | + } |
| 138 | + </script> |
| 139 | +``` |
| 140 | + |
| 141 | +## See Also |
| 142 | + |
| 143 | +* [API Reference of the Grid](/api/javascript/ui/grid) |
| 144 | +* [The dataBound Event of the Grid](https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/events/databound) |
0 commit comments