Select a rowin a Treegrid using the primary key

Hi,
I try to select rows in a treegrid control but I'm a bit confused..

Is there a simple way to select a treegrid row from its ID ?

Thanks !


3 Replies 1 reply marked as answer

FS Farveen Sulthana Thameeztheen Basha Syncfusion Team August 1, 2022 02:27 PM UTC

Hi Julien,


To achieve your requirement, we have get the row index value for a particular record in a TreeGrid and select it with the help of its primary key value. This can be achieved by passing the required primary key value to the getRowIndexByPrimaryKey method from Grid instance which that returns the index value of the row. With the help of this row index value the particular record can be selected by using the selectRow method.


Refer to the code below:-

App.Component.html:-

 

<button ej-button (click)="selectRow()">selectRow</button>

  <ejs-treegrid

    #treegrid

    [dataSource]="data"

    childMapping="subtasks"

    height="550"

    [treeColumnIndex]="1"

  >

    .    .     .

   </e-columns>

 

</ejs-treegrid>

 

App.Component.ts:-

 

selectRow() {

        var index = this.treegrid.grid.getRowIndexByPrimaryKey(9);

        // Select the row using the index value

        this.treegrid.selectRow(index);

    }

 


Sample link:- https://stackblitz.com/edit/angular-nykyyt-emqozv?file=app.component.html,app.component.ts


API link:- https://ej2.syncfusion.com/angular/documentation/api/grid#getrowindexbyprimarykey


Please get back to us if you need any further assistance.


Regards,

Farveen sulthana T


Marked as answer

JR Julien Regnery August 3, 2022 06:27 AM UTC

Hi,

I just tried your solution and it works.

Thanks a lot !


Best regards

Julien.



FS Farveen Sulthana Thameeztheen Basha Syncfusion Team August 4, 2022 03:01 PM UTC

Hi Julien,


Thanks for your update. Please get back to us if you need any further assistance. We are happy to assist you.


Regards,

Farveen sulthana T

(Please consider accepting the provided solution as the answer as it works for you so that other users can find it more quickly)


Loader.
Up arrow icon