Inserting data into failed Datagrid for unique ID not found React Material-UI

Asked

Viewed 144 times

1

the error that presents me: 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 build my table according to the data I get from an API. Here is my table:

for(var i = 0; response.data.length > i ; i++)
{   
 field = Object.keys(response.data[i]) 
 headerName = Object.keys(response.data[i])
} 
for(var i = 0; field.length > i; i++)
{
  colunas.push({field:field[i],headerName:headerName[i],width:150}) 
}
for (var i = 0; response.data.length > i; i++){
  linha.push(response.data[i])
}

example of column return:

{field: "IdChamada", headerName: "IdChamada", widht: 150}
{field: "Campanha", headerName: "Campanha", widht: 150}
{field: "Tabulacao", headerName: "Tabulacao", widht: 150}

example of line return:

 {IdChamada: 5035737, Campanha: Empresa_Update, Tabulacao: Concluido}

My Datagrid:

    <div style={{ height: 400, width: '100%' }}>
       <DataGrid 
        rows={rows} 
        columns={columns} 
        pageSize={10}  
        checkboxSelection
        id = "IdChamada"/>
    </div>

1 answer

1


According to the error shown, one or more lines are missing the attribute id.

The structure must be something like this:

{ id: 1, lastname: 'Snow', firstName: 'Jon', age: 35 }.

I suppose the linha.push(response.data[i]) wherever you "ride" the rows. If the date does not contain the ID, you can enter one like this: linha.push({id: 1, ...response.data[i]})

Remembering that the ID should be unique.

  • It worked, thank you very much :)

  • it was a pleasure :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.