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

How to select row at initial rendering by record ID in React Grid?

Hi,

How to select row at initial rendering? But not by rowIndex, but by Id in record in my data.

How can i get rowIndex for my record with specified Id?
I try iterate on this.grid.dataSource in dataBound event (where this.grid is set by ref={g => this.grid = g}):

if (this.grid) {
  let rowIndex = -1
  this.grid.dataSource.forEach((row,index) => {
    if (row.Id === this.props.selectedId) {
      rowIndex = index
    }
  })
  this.grid.selectRow(rowIndex);
}

but when I load data by UrlAdapter I get error: this.grid.dataSource.forEach is not a function

1 Reply

TS Thiyagu Subramani Syncfusion Team March 30, 2020 08:35 AM UTC

Hi adgr, 

Thanks for contacting Syncfusion forum. 

We can achieve your requirement by using currentViewData instead of dataSource in dataBound event. Please refer to the below code. 

public dataBound(args: any): void { 
        let rowIndex = -1; 
            (this as any).grid.currentViewData.forEach((row, index) => { 
                if (row.OrderID === 10001) {   // required value 
                    rowIndex = index 
                } 
            }); 
        (this as any).grid.selectRow(rowIndex); 
    } 

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

Regards, 
Thiyagu S. 


Loader.
Live Chat Icon For mobile
Up arrow icon