score:0
<DataGrid getRowId={row => row.yourUniqueField}
score:1
As per the error, Material-UI Datagrid rows must have a column named id
. Otherwise, it won't work. What you can do is map all your DT_RowId
keys to the id
key like this,
const rowsBeforeMapping = [
{
DT_RowId: "1",
color: "red",
value: "#f00"
},
{
DT_RowId: "2",
color: "green",
value: "#0f0"
},
{
DT_RowId: "3",
color: "blue",
value: "#00f"
},
{
DT_RowId: "4",
color: "cyan",
value: "#0ff"
}
];
const rows = rowsBeforeMapping.map((row) => {
const { DT_RowId, ...rest } = row;
return { id: DT_RowId, ...rest };
});
score:6
You can use getRowId
prop to return your unique id DT_RowId
.(Material-ui DataGrid doc)
But it has other cons now. If you want to know detail check this issue #1119. ( In your case, it doesn't affect, so don't worry.)
I modify your code and make it work, like:
import * as React from "react";
import { DataGrid } from "@material-ui/data-grid";
const columns = [
{ field: "DT_RowId", headerName: "DT_RowId(ID)", width: 150 },
{ field: "color", headerName: "Color", width: 100 },
{ field: "value", headerName: "Value", width: 130 }
];
const rows = [
{
DT_RowId: "1",
color: "red",
value: "#f00"
},
{
DT_RowId: "2",
color: "green",
value: "#0f0"
},
{
DT_RowId: "3",
color: "blue",
value: "#00f"
},
{
DT_RowId: "4",
color: "cyan",
value: "#0ff"
}
];
export default function DataTable() {
return (
<div style={{ height: 400, width: "100%" }}>
<DataGrid
getRowId={(r) => r.DT_RowId}
rows={rows}
columns={columns}
pageSize={5}
checkboxSelection
/>
</div>
);
}
Hope to help you :)
Source: stackoverflow.com
Related Query
- Material UI Data Grid not working on adding column other than "ID"?
- Material UI data grid filter not working when using renderCell in a field
- How to save state of column visibility in material ui data grid
- material ui select not working when a list of data to be rendered
- AG Grid table data copy to clipboard not working in react
- Material UI Data Grid first column fixed
- Material UI Grid not working properly with Paper Component for nested Grid
- React Material UI Nested Grid - Not working
- Slide effect is not working in react-owl-carousel after adding data dynamically to carousel
- Why is my custom sort not working with Material-UI Data Grid component?
- React Material UI Table/ Data Grid show only rows but not columns
- Adding dynamic style to material ui Menu with makeStyles not working
- Full Width Material-UI Grid not working as it should
- how to make material data grid width to fill the parent component in react js
- react-hook-form's setValue method is not working if input is in material ui dialog
- Adding multiple data to a column in react-table
- Material UI v5 server side rendering css order not working with gatsby
- Select is not working onClick IconComponent(dropdown-arrow) in react material ui
- Search not working with React material-table using remote data
- Why is my min value not working in my Material UI date textfield?
- Limiting table selects not working - material UI table - react
- 100% height not working for Drawer, Material Design React
- Material ui tooltip is not working on mobile
- Adding a package immediately after created by create-react-app is not working
- How to pass percentage value to width to React data grid column
- Material UI modal not working (React JS)
- Extending Material UI theme via Module Augmentation not working correctly
- 'outlined' not working in Material UI Select
- Adding data labels inside charts in ReactJS is not working?
- Adding active class with styled component not working
More Query from same tag
- React pass onMouseHover to Children component
- NextJS app temporarily shows restricted route component
- 2 column layout for Highcharts legend categorized by type - React highcharts
- React - state doesn't update in class component even though the message printed on the screen changes
- React router render causing unmount
- Can not read properties of null (reading '0'). React
- Loading files on client-side react application
- How does the override for the default.props occur
- Need to get the last value of onChange for a slider React
- Load ReactJS App from another server and execute
- react datepicker default start date
- why i am getting this error on using Link tag from next/link? Error: React.Children.only expected to receive a single React element child
- How do i import my file to app,js using javascript?
- axios.post is displaying user inputs in search bar
- Is there an option to show all test descriptions when I run jest tests?
- How to stop client error with redux saga?
- mapStateToprops is getting called twice and returning an empty array at the end
- React: unique "key" prop
- React getting access to properties of list component on click
- Rendering Modal Popup
- Cannot find module 'react-dom/client' from 'node_modules/@testing-library/react/dist/pure.js'
- How to maintain previous changed state in REACT JS as when new item is updated, previous is set to default?
- React Native Phone Number Input
- setState is not working with multiple onClick function
- TypeError: Cannot read property 'setTransform' of null when using Openlayers and Jest + Enzyme
- combine sort by high and low into one function react
- How to avoid .then() hell in javascript?
- multiple input elements in form - React
- React.js start a new line after every number
- Empty the state of parent component from button in child component