Programatically expand tree grid using PrimaryKey

I have a tree which has this column defined:


<e-column field='functionalHierarchyId' textAlign='Left' [isPrimaryKey]='true' [visible]='false' [showInColumnChooser]='false'>


Is there a way to use primaryKey (in this example it is hierarchyId) to expand this row? ie:

this.treegrid.expand(hierarchyId)

I can use hierarchyId to change cell value, ie:

this.treegrid.setCellValue(hierarchyId, 'column name ', 'new value'); 


 but cannot use it to expand tree at given row.

5 Replies 1 reply marked as answer

JR Jagadesh Ram Raajkumar Syncfusion Team August 6, 2021 10:51 AM UTC

Hi Michal, 

Greetings from Syncfusion Support. 

Query: Is there a way to use primaryKey to expand a row 

We have achieved your requirement by using getRowIndexByPrimaryKey method. When passing the required primary key value to the getRowIndexByPrimaryKey method which that returns the index value of the row. With the help of this row index value, the particular record can be expanded by using the expandRow method with the row element as its parameter. To get the row element, we need to pass the index to getRows method. 

Please refer to the below sample and documentation,
Sample: https://stackblitz.com/edit/angular-f167875?file=app.component.ts 

Regards,
Jagadesh Ram 



MS Michal Szkudlarek August 6, 2021 12:28 PM UTC

Thanks, but this solution does not work for nodes which are not displayed. In your example we see only 3 rows


What if I want to expand row with id 14 from this initial state?




In your sample, please change
1 to 14, like that:

treegrid.getRows()[treegrid.grid.getRowIndexByPrimaryKey(14)]


it throws errors.



JR Jagadesh Ram Raajkumar Syncfusion Team August 9, 2021 10:40 AM UTC

Hi Michal, 

Thanks for the update. 

Query: What if I want to expand row with id 14 from this initial state? 

The mentioned issue occurs because the given row is not present in the DOM. We cannot access the row element which is not rendered in the DOM. So, if you want to expand the inner level parent records we suggest you to use the expandAtLevel method which expands the records of the given level. 

Refer the below documentation for more details. 

  
Kindly get back to us for further assistance. 


Regards,
Jagadesh Ram 



MS Michal Szkudlarek August 9, 2021 10:45 AM UTC

expandAtLevel will expand all nodes on that level (regardless if they are in the branch with item with id 14, or not) , I do not want that.

So, in other words, there is no easy/simple way to expand a node which is not yet rendered (as the node 14 in the example).

Technically, I would need to find all parents of node with id 14, and then expand each of them?

Seems like an obvious missing feature here.



JR Jagadesh Ram Raajkumar Syncfusion Team August 10, 2021 12:41 PM UTC

Hi Michal, 
 
 
Currently, we do not have support for expanding rows that are not present in the current view. We have logged it as feature improvement and support for this improvement will be rolled out in any of our future releases. 
 
You can track the current status of your request, review the proposed resolution timeline, and contact us for any further queries through this link, 
  
Note: To view the above feedback, kindly login into your account. 

Kindly get back to us for further assistance. 
Regards,
Jagadesh Ram 


Marked as answer
Loader.
Up arrow icon