Error met when trying to make cell editable.
Hi group,
I've recently started to learn and use react-data-grid in JS. However, I have some questions about how to use it.
Codesandbox version error: https://codesandbox.io/s/awesome-gates-0t9y6?file=/src/App.js
I'm trying to make the editable, but it prompted the error below after I double-clicked the cell.

Here is my code:
import DataGrid from "react-data-grid";
import React, {useState} from "react";
import {cr_columns, cr_dataSource} from "./CareReminderData";
import 'react-data-grid/dist/react-data-grid.css';
export function CareReminderSettings() {
const [rows, setRows] = useState(() => cr_dataSource);
return (
<DataGrid
columns={cr_columns}
rows={rows}
onRowsChange={setRows}
/>
);
}
export default CareReminderSettings;
Here is the column & row data:
import fs from "fs";
import TextEditor from "react-data-grid";
export const cr_columns = [
{ key: 'id',
name: 'ID',
resizable: true
},
{ key: 'project',
name: 'Project',
resizable: true,
editor: TextEditor
},
{ key: 'plant',
name: 'Plant',
resizable: true,
editor: TextEditor
},
{ key: 'water',
name: 'Water (every N days)',
resizable: true,
editor: TextEditor
},
{ key: 'fertilize',
name: 'Fertilize (every N days)',
resizable: true,
editor: TextEditor
},
{ key: 'dust',
name: 'Dust (every N days)',
resizable: true,
editor: TextEditor
}
]
export const cr_dataSource = [
{ id: 1, project: 'Bedroom Bonsai', plant: 'Bonsai', water: 2, fertilize: 7, dust: 30},
{ id: 2, project: 'Office Desk', plant: 'Bonsai', water: 2, fertilize: 7, dust: 30},
{ id: 3, project: 'Office Desk', plant: 'Bonsai', water: 2, fertilize: 7, dust: 30},
{ id: 4, project: 'Kitchen Sill', plant: 'Sill', water: 2, fertilize: 7, dust: 30},
];
Could I know what I did wrong with it? Also, is there any Javascript code for the demos? That might be super helpful.
Thanks a lot in advance.
Regards, -Rui
I had similar error, because data was not present yet, checking if data available first solve it:
{ rows && (<DataGrid columns={columns} rows={rows} onRowsChange={setRows} />)}
This line
import TextEditor from "react-data-grid";
should be
import { TextEditor } from "react-data-grid";
As mentioned in the previous comment, import statement needs to be fixed