最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error: Material-UI: The data grid component requires all rows to have a unique id property. A row was provided with

programmeradmin2浏览0评论

I am getting this error:

Error: Material-UI: The data grid ponent 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 ponent 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.

I am getting this error:

Error: Material-UI: The data grid ponent 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 ponent 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.

Share Improve this question edited Nov 25, 2021 at 16:21 NearHuscarl 82.1k24 gold badges320 silver badges282 bronze badges asked Apr 27, 2021 at 15:52 ashes999ashes999 1,3242 gold badges22 silver badges48 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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}

When creating the new rows array you are missing spreading the previous array:

const handleNewJobCreation = (newRow) => {
    setRows([
        {...newRow},
        ...rows // <- missing spread operator
    ]);
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论