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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Expand current detail row after grid.refresh() called

Thread ID:

Created:

Updated:

Platform:

Replies:

148850 Nov 6,2019 11:42 AM UTC Nov 17,2020 01:48 PM UTC Angular - EJ 2 3
loading
Tags: Grid
Neo
Asked On November 6, 2019 11:42 AM UTC

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?

Pavithra Subramaniyam [Syncfusion]
Replied On 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. 


Walter Konnerth
Replied On 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?

Rajapandiyan Settu [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon