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. (Last updated on: June 24, 2019).
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 7,2019 07:02 AM UTC Angular - EJ 2 1
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. 


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