'React data table component. How to dynamically select rows

I have a DataTable with the following columns:

const columns = [
    {   name: "Matric",
        selector: "matric",
        sortable: true        
    },
    {
        name: "Forename",
        selector: "forename",
        sortable: true
    },
    {
        name: "Surname",
        selector: "surname",
        sortable: true
    }
]


    <DataTable
        pagination
        selectableRows 
        columns = {columns}
        data = {studentData}
        defaultSortField="matric"
    />

SelectableRows adds a checkbox to each row. I'm using the datatable to take attendance but I was hoping to also allow the user to upload the attendance via a .csv, or if an attendance record already exists it will display it in the datatable.

By uploading the csv or fetching the attendance record, I'm hoping that the datatable will rerender with the respective rows checked so the user can double check. But I'm not sure how to select a row on render.

Any help would be great!



Solution 1:[1]

Just pass a prop with the prop with the rows you want checked: selectedData = { studentData[0], studentData[1] }

Solution 2:[2]

This is deprecated. We have to use a row format like row => row.name.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 k-wasilewski
Solution 2 cigien