Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Material-UI: The data grid component requires all rows to have a unique id property. A row was provided without id in the rows prop:

I am getting this error:

Error: Material-UI: The data grid component requires all rows to have a unique id property.
A row was provided without id in the rows prop:

When I add a new row to my rows in the DataGrid component using:

const handleNewJobCreation = (newRow) => {
    setRows([
        {...newRow},
        rows
    ]);
}

However, I can see that all my rows do have the id property inside the dataset, I was wondering how can I fix this issue to be able to get append new data to the rows.

like image 772
ashes999 Avatar asked Feb 01 '26 19:02

ashes999


1 Answers

Your row objects are missing the id property as the error message said. You need to add the id prop with a unique value to remove the error. If you have a unique field that does not have the name id, you need to add a getRowId callback to return the correct id for every row:

<DataGrid getRowId={row => row.yourUniqueField}

Codesandbox Demo

like image 157
NearHuscarl Avatar answered Feb 03 '26 07:02

NearHuscarl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!