Nested grid header not visible and hide arrow if no child element

I have to show a nested grid. Where for few elements child data is there and for few it is not available.

Requirement :

  1. For child grid 'header text must be available'.
  2. If child grid is not available need to hide the expandable arrow.
Sample html code:

<ejs-grid #grid [dataSource]="data" [allowPaging]="true" [allowSorting]="true" [allowResizing]="true" [allowFiltering]="true" [filterSettings]="filterSettings" [pageSettings]="initialPage">
<e-columns>
<ng-template #detailTemplate let-data>
<div *ngIf="data.deviceAlertRules.length > 0">
<ejs-grid #grid [dataSource]="data.deviceAlertRules" [allowPaging]="false" [allowSorting]="true" [allowFiltering]="false" [filterSettings]="filterSettings" [pageSettings]="initialPage">
<e-columns>
<e-column field="alertType" textAlign="Left" width="50">
<ng-template #template let-deviceAlertRules>
<div>
<img class="info" alt="info" width="8" height="16" src="assets/images/CoMo/{{ deviceAlertRules.alertType.toLowerCase() }}-default-icon.svg" />
<span> {{ deviceAlertRules.alertType }}span>
div>
ng-template>
e-column>
<e-column field="severity" headerText="{{ 'dashboard.alert.severity' | translate }}" textAlign="Left" width="50">
<ng-template #template let-deviceAlertRules>
<div>
<img *ngIf="deviceAlertRules.severity === 'High'" class="info" alt="info" width="2" height="16" src="assets/images/CoMo/severity-high-icon.png" /><span> {{ deviceAlertRules.severity }}span>
div>
ng-template>
e-column>
<e-column field="threshold" headerText="{{ 'dashboard.alert.threshold' | translate }}" textAlign="Left" width="50">e-column>
e-columns>
ejs-grid>
div>
ng-template>
<e-column field="deviceId" headerText="{{ 'device.grid.deviceId' | translate }}" textAlign="Left" width="50">e-column>
e-columns>
ejs-grid>

10 Replies

RR Rajapandi Ravi Syncfusion Team June 29, 2021 10:19 AM UTC

Hi Neha, 

Greetings from syncfusion support 

Based on your shared information we suspect that you want render table in detail Template with separate child and parent dataSource. To achieve your requirement, we have loaded child Grid’s dataSource using detailDataBound event. 
 
Please refer to the below code and sample link for more reference. 
  
Note: We have loaded local data to the parent and remote data to the child Grid. 
  
<ejs-grid #grid [dataSource]='employeeData' (detailDataBound)='detailDataBound($event)' id='Grid'> 
        <ng-template #detailTemplate let-data> 
             <div class='custom-grid'></div> 
        </ng-template> 
        <e-columns> 
. . . . . . . . . . .  
        </e-columns> 
    </ejs-grid> 
  
 
 detailDataBound(e) { 
    this.predicate = new Predicate("EmployeeID", "equal", e.data["EmployeeID"]); 
    this.data = new DataManager({ 
      url: 
      adaptor: new ODataV4Adaptor() 
    }) 
      .executeQuery(new Query().where(this.predicate)) 
      .then(e => { 
        // you can add you data as per your needs 
        this.gridObj.dataSource = (e as any).result; 
      }); 
    let detail = new Grid({ 
      columns: [ 
        { field: "OrderID", headerText: "Order ID", width: 110 }, 
        { field: "CustomerID", headerText: "Customer Name", width: 140 }, 
        { field: "ShipCountry", headerText: "Ship Country", width: 150 } 
      ] 
    }); 
    detail.appendTo(<HTMLElement>e.detailElement.querySelector(".custom-grid")); 
    this.gridObj = e.detailElement.getElementsByClassName("e-grid" )[0].ej2_instances[0]; 
  } 
  

By default, the expand icon will be visible even if the child grid is empty. You can use rowDataBound event to hide the icon when there are no records in child grid. 

To hide the expand icon in parent row when no records in child grid, follow the given steps: 

Create CSS class with custom style to override the default style of Grid. 
 
.e-row[aria-selected="true"] .e-customizedExpandcell { 
        background-color: #e0e0e0; 
    } 
 
    .e-grid.e-gridhover tr[role='row']:hover { 
        background-color: #eee; 
    }  
 

Add the CSS class to the Grid in the rowDataBound event handler of Grid. 
 
rowDataBound(e: any) { 
    var argument: any = e; 
    this.initPredit = new Predicate("EmployeeID", "equal", e.data["EmployeeID"]); 
    this.checkdata = new DataManager({ 
      url: 
      adaptor: new ODataV4Adaptor() 
    }).executeQuery(new Query().where(this.initPredit)).then((e) => { 
        if((e as any).result.length === 0) { //if the result length is zero, we have added the class to the  
          console.log(argument);                    td for hiding the expand icon 
          argument.row.querySelector('td').innerHTML= ''; 
          argument.row.querySelector('td').className = 'e-customizedExpandcell'; 
        } 
      }); 
  } 
 


Screenshot: 

 

Regards,
Rajapandi R 



NS Neha Singh June 29, 2021 12:11 PM UTC

Hello Rajapandi,

I saw your solution but you have used data manager with an external link. Can you please suggest with the data coming from backend api as i have used in the attached query?

This way won't work for me so please suggest with the data structure used in the query code.

Regards

Neha



NS Neha Singh June 30, 2021 07:32 AM UTC

Hello Rajapandi,


Good day! I expect a response with the way it is shared in the query. Changing the entire coding for data binding won't help.

Please provide the html way for the solution as I have already mentioned the data structure in the sample code.

NOTE : If you notice there are certain condition based on which I need to add icons.

<e-column field="severity" headerText="{{ 'dashboard.alert.severity' | translate }}" textAlign="Left" width="50">
<ng-template #template let-deviceAlertRules>
<div>
<img *ngIf="deviceAlertRules.severity === 'High'" class="info" alt="info" width="2" height="16" src="assets/images/CoMo/severity-high-icon.png" /><span> {{ deviceAlertRules.severity }}span>
div>
ng-template>
e-column>


Regards

Neha



RR Rajapandi Ravi Syncfusion Team June 30, 2021 11:06 AM UTC

Hi Neha, 

Thanks for the update 

Before we start providing solution on your query, we need some information for our clarification. So please share the below details that would be helpful for us to provide better solution. 

1)     In your query you have mentioned that “Can you please suggest with the data coming from backend API as i have used in the attached query?”. So please share your code part of your data  
         coming from backend API. 

2)     Please share your complete Grid rendering code(ts and html file). 

Regards,
Rajapandi R



NS Neha Singh July 10, 2021 08:51 PM UTC

Hello Rajapandi,

Good day!

Can you please schedule a call ASAP. for this. As I can see there is lack of information and it is taking too long to respond with reply. It will be really helpful if you can find some time on MONDAY EARLY MORNING to have this call and short this out.

Regards

Neha



NS Neha Singh July 10, 2021 09:21 PM UTC

Requirement :

Below data is coming from API.

Grid with col - deviceId, Area, Battery, Country

Child grid with col - alertType, severity, threshold (if severity is 'High' add ! symbol from assest folder else no symbol)

Sample data :

  1. [{deviceId: "ABC",
    1. area: "London"
    2. battery: 100
    3. country: "BBB"
    4. deviceAlertRules:[
        1. {deviceId: "XYZ",
          1. area: "NY"
          2. battery: 100
          3. country: "MMM"
          4. deviceAlertRules:[



NS Neha Singh July 12, 2021 05:45 AM UTC

Hello Rajapandi,

Can you please schedule a call now? It is urgent?

Regards

Neha



RR Rajapandi Ravi Syncfusion Team July 12, 2021 12:11 PM UTC

Hi Neha, 

Based on your sampleData we have prepared a sample with HTML way and achieved your requirement by using rowDataBound event of Grid. Please refer the below code example, sample and documentation for more information. 

Index.html 
 
<style> 
  .e-row[aria-selected="true"] .e-customizedExpandcell { 
        background-color: #e0e0e0; 
    } 
 
    .e-grid.e-gridhover tr[role='row']:hover { 
        background-color: #eee; 
    } 
  </style> 


App.component.ts 
 
rowDataBound(args) { 
        if(args.data.deviceAlertRules.length == 0) { 
            //here hide which parent row has no child records 
            args.row.querySelector('td').innerHTML=' '; 
            args.row.querySelector('td').className = 'e-customizedExpandcell'; 
        } 
    } 
 



Screenshot: 

 

If still you are facing the issue, we can setup a web meeting to look on to the problem. Please let us know your availability for web meeting tomorrow Tuesday (13th July 2021). Based on that we can schedule a web meeting with you to look into the reported problem in your machine. 

Regards,
Rajapandi R 



NS Neha Singh July 12, 2021 12:22 PM UTC

Thank you it worked.

Regards

Neha



RR Rajapandi Ravi Syncfusion Team July 13, 2021 04:40 AM UTC

Hi Neha, 

We are happy to hear that your issue has been resolved. 

Please get back to us if you need further assistance. 

Regards, 
Rajapandi R 


Loader.
Up arrow icon