Asp.Net Core Syncfusion grid search bar should search in both parent & child grid

Hello.

I'm developing a small application in Asp.Net Core and using Syncfusion grids.

I have a grid (of Products) with child grid (of product UOM). I have search bar on parent grid which is working fine (on parent grid only). 

But i want the search to be perform on both grids. Means if user type a keyword it should search in child grid's datamanager


Also is it possible that if user type a UOM / Price (which exists in child grid) the parent grid 

Also is it possible to filter parent grid's rows when user type UOM/Price (which exists in child grid). I mean parent grid datamanager should filtered on behalf of child grid datamanager.


Hope you understand what i mean.


I'm using ODataV4Adapter for both grids.

Here is my Parent Grid:

<ejs-grid id="Grid" load="loadUOM"
                                  allowPaging="true"
                                  allowSorting="true"
                                  allowResizing="true"
                                  allowFiltering="true"
                                  query="new ej.data.Query().expand('Manufacturer($select=Title),Category($select=Title),Group($select=Title)')"
                                    toolbar="@(new List<string>() {"Search" })">
                            <e-data-manager url="/API/ProductApi" adaptor="ODataV4Adaptor" crossdomain="true"></e-data-manager>
                            <e-grid-filtersettings type="Menu" columns="filterColumns"></e-grid-filtersettings>
                            <e-grid-pagesettings pageSize="15"></e-grid-pagesettings>
                            <e-grid-columns>
                                <e-grid-column field="Title" headerText="Name/Title" type="string" width="120"></e-grid-column>
                                <e-grid-column field="Manufacturer.Title" headerText="Manufacturer" type="string" width="140"></e-grid-column>
                                <e-grid-column field="Group.Title" headerText="Group" width="120" type="string"></e-grid-column>
                                <e-grid-column field="Category.Title" headerText="Category" width="140" type="string"></e-grid-column>
                                <e-grid-column field="Size" headerText="Size" type="string" width="80"></e-grid-column>
                                <e-grid-column field="Color" headerText="Color" type="string" width="80"></e-grid-column>
                                <e-grid-column headerText="Action" allowFiltering="false" allowSorting="false" allowSearching="false" textAlign="Center" width="50" template="#actionColumnTemplate"></e-grid-column>
                            </e-grid-columns>
                        </ejs-grid>


Here is my Child Grid Code:

<script>
        function loadUOM(args) {
            this.setProperties({
                childGrid: {
                    dataSource: new ej.data.DataManager({
                        url: "/API/ProductUomApi",
                        adaptor: new ej.data.ODataV4Adaptor(),
                        crossDomain: true
                    }),
                    queryString: 'ProductId', //queryString value will be same in both parent and child grid dataSource
                    allowPaging: false,
                    allowSorting:true,
                    columns: [
                        //{ field: 'ProductUOMId', headerText: 'ID', width: 120 },
                        { field: 'Code', headerText: 'Code', width: 150 },
                        { field: 'Barcode', headerText: 'Barcode', width: 150 },
                        { field: 'QtyPerUOM', headerText: 'Qty', textAlign: 'Right', width: 150 },
                        { field: 'SalePrice', headerText: 'Sale Price', textAlign: 'Right', width: 150 },
                        { field: 'PurchasePrice', headerText: 'Purchase Price', textAlign: 'Right', width: 150 }
                    ],
                }
            }, true);

        }

    </script>

here is my Grid Output:




3 Replies

SK Sujith Kumar Rajkumar Syncfusion Team March 11, 2022 01:04 PM UTC

Hi Anjum, 
 
Greetings from Syncfusion support. 
 
The Grid’s search functionality works on basis of comparing the searched key value with the underlying data source bound to the grid for local data and for remote data sends request to the defined server url to fetch and update the Grid data. The child Grids are individually initialized Grid controls(on parent row expand) with its own data and actions. So for performing search on the child Grid we need to define the search toolbar in the child Grid separately. This is the default behavior of this case based on the Grid’s current architecture and so it is not feasible to achieve your requirement. 
 
Let us know if you have any concerns. 
 
Regards, 
Sujith R 



AH Anjum Habib March 15, 2022 11:55 AM UTC

Thanks for your time.

so if parent grid can't be filtered with child grid data.

then can we render both Parent & Child grids with same data source? I mean grid data source return relational data with list of Product and each product having its UOM(s). 

Also when we perform a search it will query both parent & child entities 

Kindly share some example code (if any).



JC Joseph Christ Nithin Issack Syncfusion Team March 16, 2022 04:53 PM UTC

Hi Anjum, 

   Thanks for your update. 

   Based on your requirement, you want to search both the parent and the child grid using the search key word of the parent grid. You requirement can be achieved by getting the search keyword of the parent grid in the `dataBound` event of the child grid and then you can search the child grid with the keyword using the `search` method of the child grid. 

Please refer the below code example:  

var grid = new ej.grids.Grid({ 
  --------------------------- 
  --------------------------- 
  childGrid: { 
    dataSource: dataManger, 
    dataBound: function (args) { 
      var parentGrid = document.getElementById(this.parentDetails.parentID) 
        .ej2_instances[0]; 
      this.searchSettings = { key: parentGrid.searchSettings.key }; 
    }, 
    allowSearching: true, 
    queryString: 'EmployeeID', 
    allowPaging: true, 
    toolbar: ['Search'], 
    ---------------------------------- 
    ---------------------------------- 
  }, 
}); 
grid.appendTo('#Grid'); 




Please get back to us for further details. 

Regards, 
Joseph I. 


Loader.
Up arrow icon