We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Expand current detail row after grid.refresh() called

Hi all,

I want to know a method, how to expand current detail row after grid.refresh() called. And is there any method to enable one detail row expanding at once?

3 Replies

PS Pavithra Subramaniyam Syncfusion Team November 7, 2019 07:02 AM UTC

Hi Neo, 
 
Thanks for contacting us. 
 
Query#1: I want to know a method, how to expand current detail row after grid.refresh() called. 
 
You can achieve this requirement by using expand method of the detailRowModule. Please refer the below code example and sample for more information. In the below code snippet we have stored the expanded row and expanding the row in dataBound event of the Grid. 
 
App.component.html 
<div class="control-section"> 
    <button ejs-button [isPrimary]="true" (click)="btnClick()">Refresh</button> 
 
    <ejs-grid #grid [dataSource]='data' (dataBound)="dataBound($event)" (created)='expand($event)' id='Grid'> 
        <ng-template #detailTemplate let-data> 
            . . . 
        </ng-template> 
        <e-columns> 
            <e-column field='EmployeeID' headerText='Employee ID' width='125' textAlign='Right'></e-column> 
            <e-column field='FirstName' headerText='Name' width='120'></e-column> 
            <e-column field='Title' headerText='Title' width='170'></e-column> 
            <e-column field='HireDate' headerText='Hire Date' width='135' textAlign='Right' format='yMd'></e-column> 
            <e-column field='ReportsTo' headerText='Reports To' width='120' textAlign='Right'></e-column> 
        </e-columns> 
 
    </ejs-grid> 
</div> 
 
App.component.ts 
 
@Component({ 
. .. 
}) 
export class AppComponent { 
  public data: any; 
  @ViewChild("grid") 
  public gridObj: GridComponent; 
  public row: any; 
  constructor() {} 
 
. . . 
 
  btnClick() { 
//here we are storing the expanded row before refresh 
    this.row = parentsUntil( 
      this.gridObj.element.querySelector(".e-detailrowexpand"), 
      "e-row" 
    ); 
    this.gridObj.refresh(); 
  } 
 
  dataBound (e) { 
//here we expanding the row again after refresh 
    if (this.row) { 
      let rowIndex = parseInt(this.row.getAttribute("aria-rowindex")); 
      this.gridObj.detailRowModule.expand(rowIndex); 
    } 
  } 
. . . 
} 
 
 
Query#2: is there any method to enable one detail row expanding at once? 
 
We do not have method for this requirement. However you can achieve your requirement by binding click event to the grid element. 
Please refer the below code example and sample for more information. 
 
App.component.html 
<div class="control-section"> 
    <button ejs-button [isPrimary]="true" (click)="btnClick()">Refresh</button> 
 
    <ejs-grid #grid [dataSource]='data' (dataBound)="dataBound($event)" (created)='expand($event)' id='Grid'> 
        <ng-template #detailTemplate let-data> 
            . . . 
        </ng-template> 
        <e-columns> 
            <e-column field='EmployeeID' headerText='Employee ID' width='125' textAlign='Right'></e-column> 
            <e-column field='FirstName' headerText='Name' width='120'></e-column> 
            <e-column field='Title' headerText='Title' width='170'></e-column> 
            <e-column field='HireDate' headerText='Hire Date' width='135' textAlign='Right' format='yMd'></e-column> 
            <e-column field='ReportsTo' headerText='Reports To' width='120' textAlign='Right'></e-column> 
        </e-columns> 
 
    </ejs-grid> 
</div> 
 
App.component.ts 
 
@Component({ 
. .. 
}) 
export class AppComponent { 
  public data: any; 
  @ViewChild("grid") 
  public gridObj: GridComponent; 
  public row: any; 
  constructor() {} 
 
. . . 
 
. . . 
 
  expand() { 
    this.gridObj.element.addEventListener("click", e => { 
      if (parentsUntil(e.target as Element"e-detailrowexpand")) { 
//collapsing all the expanding records using collapseAll method 
        this.gridObj.detailRowModule.collapseAll(); 
        let row = parentsUntil(e.target as Element"e-row"); 
        let rowIndex = parseInt(row.getAttribute("aria-rowindex")); 
// expanding the particular using expand method 
        this.gridObj.detailRowModule.expand(rowIndex); 
      } 
    }); 
  } 
  } 
. . . 
} 
 
 
Please get back to us if you need any further assistance on this. 
 
Regards, 
Pavithra S. 



WK Walter Konnerth November 16, 2020 03:25 PM UTC

Hi,

I have a scenario where grandchidren are implied (2 levels on the master grid).

I need to collapse all other 1-st level children if the user expands another child, but not when expanding a 2-nd level child (grandchild).

Can you please provide an example how to implement this?


RS Rajapandiyan Settu Syncfusion Team November 17, 2020 01:48 PM UTC

Hi Walter, 
 
Greetings from Syncfusion support. 
 
Query: I need to collapse all other 1-st level children if the user expands another child, but not when expanding a 2-nd level child (grandchild) 
 
Based on your requirement, we suspect that you need to have only one expanded child Grid (1st level child) in the master Grid. If so, you can achieve your requirement by using recordClick event of Grid. 
 
 
In that event, we collapse all the Child-Grid based on the target element using detailCollapseAll method. Refer to the below code example and sample for more information. 
 
 
 recordClick(args) { 
    if ( args.target && args.target.closest("td").classList.contains("e-detailrowcollapse")) { 
      this.grid.detailCollapseAll();  // collapse all the detailrow 
    } 
  } 
 
 
If we misunderstood your query, then explain more details on your requirement. 
 
Regards, 
Rajapandiyan S 


Loader.
Up arrow icon