Show Selected rows without ViewChild or databound

Hi,


I need to show selected rows in my grid. But I dont have ViewChild for that grid. I am having selected row indexes. Which property will be used for the same?
 Please let me know how is this possible without having Viewchild reference.

TIA

Regards,
Shivani

3 Replies 1 reply marked as answer

PG Praveenkumar Gajendiran Syncfusion Team October 12, 2020 12:49 PM UTC

Hi Shivani,


Greetings from Syncfusion support.


We checked your query based on that we understood that you want to select rows by row index’s without ViewChild for the Grid. We suggest to create Instances of Grid using “.e-grid” Class to achieve your requirement. This is demonstrated in the below code example.

Here we have selected the rows by Grid Instances and passing row index’s as parameters through selectRows method of Grid.

Code Example: 
btnClick() { 
       var gridInstance = (document.getElementsByClassName('e-grid')[0] as any).ej2_instances[0];  // Grid Instances 
       gridInstance.selectRows([1,3,5]); 
 
    } 

API Link:  https://ej2.syncfusion.com/angular/documentation/api/grid/#selectrows

We would like to inform you that you can select a row at initial rendering by using selectedRowIndex property of Grid. Please refer the below code example and documentation for more information.

Code Example: 
<ejs-grid [dataSource]='data' height='350' [selectedRowIndex]=2 [selectionSettings]='selectionOptions' > 
   </ejs-grid> 

Documentation Link:   https://ej2.syncfusion.com/angular/documentation/grid/selection/#select-row-at-initial-rendering


We have prepared a sample based on this for your reference,

Sample: https://stackblitz.com/edit/angular-m9utyq?file=app.component.ts

Please get back to us if you need further assistance.

Regards,
Praveenkumar G 


Marked as answer

SG shivani goyal November 5, 2020 11:47 AM UTC

Thanks for the update.


PG Praveenkumar Gajendiran Syncfusion Team November 6, 2020 03:11 PM UTC

Hi Shivani, 

You are welcome. Please get back to us if you need further assistance. 

Regards, 
Praveenkumar G 


Loader.
Up arrow icon