react-data-grid icon indicating copy to clipboard operation
react-data-grid copied to clipboard

Error met when trying to make cell editable.

Open RuiRitaYang opened this issue 6 years ago • 3 comments

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. image

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

RuiRitaYang avatar Nov 15 '20 18:11 RuiRitaYang

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} />)}

Svmurvj avatar Nov 19 '20 07:11 Svmurvj

This line

import TextEditor from "react-data-grid";

should be

import { TextEditor } from "react-data-grid";

DevinMui avatar Dec 14 '20 02:12 DevinMui

As mentioned in the previous comment, import statement needs to be fixed

amanmahajan7 avatar May 21 '21 16:05 amanmahajan7