How to access column values using rowSelected

I have a data grid and I would like to know how to access the columns and their values from the grid events. In this case, the rowSelected event.

I debugged the function and it returns row 0 for the selected row index which is correct since there was only one result. However, I now need to access the other fields like ReportNumber, CustomerName, etc.
 What is the proper syntax to parse the selectedrecords object returned from the getSelectedRecords() method?

<ejs-grid id="reportGrid" dataSource="@Model.CreditReports" allowPaging="false" allowSelection="true" rowSelected="rowSelected" row>

                    <e-grid-selectionsettings enableSimpleMultiRowSelection="true" type="Multiple"></e-grid-selectionsettings>

                    <e-grid-columns>

                        <e-grid-column field="Id" visible="false" isPrimaryKey="true"></e-grid-column>

                        <e-grid-column field="ReportNumber" headerText="Report #" textAlign="Left"></e-grid-column>

                        <e-grid-column field="CustomerName" headerText="Customer" textAlign="Left"></e-grid-column>

                        <e-grid-column field="JointCustomerName" headerText="Joint Customer" textAlign="Left"></e-grid-column>

                        <e-grid-column field="Imported" headerText="Imported" headerTextAlign="Center" displayAsCheckBox="true" textAlign="Center"></e-grid-column>

                        <e-grid-column field="ImportedDate" headerText="Imported Date" format="dd/MM/yyyy"></e-grid-column>

                    </e-grid-columns>

                </ejs-grid>

'



function rowSelected(args) {

            var selectedrowindex = this.getSelectedRowIndexes();  // get the selected row indexes.

            alert(selectedrowindex); // to alert the selected row indexes.

            alert("Row " + selectedrowindex + " was selected."); // to alert the selected row indexes.

            var selectedrecords = this.getSelectedRecords();  // get the selected records.

            

        }


1 Reply 1 reply marked as answer

MS Manivel Sellamuthu Syncfusion Team July 24, 2020 08:28 AM UTC

Hi Ron, 

Greetings from Syncfusion support. 

From your query we can understand that you want to access the selected row’s data. You can get them from the getSelectedRecords method. Which will return the selected row’s data in array of Objects. 

function rowSelected (args) { 
// here you can get the data of currently selected row 
  console.log(args.data); 
  alert(JSON.stringify(args.data)); 
// here you can get the array of selected records. 
var selectedrecords = this.getSelectedRecords();  // get the selected records. 
  console.log(selectedrecords); 
} 

If we misunderstood your query or if you need further details, please get back to us for further assitance. 

Regards, 
Manivel 


Marked as answer
Loader.
Up arrow icon