inovua / reactdatagrid

Empower Your Data with the best React Data Grid there is
https://reactdatagrid.io
Other
3.44k stars 57 forks source link

onEditComplete - rowid undefined #333

Closed bharathitm closed 1 year ago

bharathitm commented 1 year ago

Hi @inovua-admin and all, I'm using the community version of reactdatagrid and find that the rowId parameter is coming thro as undefined. Please see my code below. The value, columnId are returning correct values, just the rowId is undefined. Because of this onEditComplete is not working. Not sure what I'm missing, please help.

import React, { useCallback } from 'react';
import ReactDataGrid from '@inovua/reactdatagrid-community';
import '@inovua/reactdatagrid-community/index.css';
import BoolEditor from '@inovua/reactdatagrid-community/BoolEditor';

const columns = [
  { name: 'id', header: 'Id', defaultVisible: false, type: 'number', maxWidth: 40 },
  { name: 'guest_name', defaultFlex: 1, header: 'Name' },
  { name: 'is_passport_verified', groupBy: false, defaultFlex: 1, textAlign: 'center', header: 'Passport', 
          editable:true, render: ({ value }) => value? 'Yes':'No', editor: BoolEditor
  }
];

const gridStyle = { minHeight: 550, marginTop: 10 };

const dataSource = [
  { id: 1, guest_name: 'Mary Poppins', is_passport_verified: true },
  { id: 2, guest_name: 'Mary Stones', is_passport_verified: false },
  { id: 3, guest_name: 'Robert Fil', is_passport_verified: false }
];

  const ExamplePage = () => {

    const setDataSource = dataSource;

    const onEditComplete = useCallback(({ value, columnId, rowId }) => {

      **alert(rowId);**

      const data = [...dataSource];      
      data[rowId][columnId] = value;

      setDataSource(data);
    }, [dataSource])

      return (
        <div className="App">
            <ReactDataGrid
                    idProperty="id"
                    style={gridStyle}
                    columns={columns}
                    onEditComplete={onEditComplete}
                    pagination 
                    defaultLimit={15}
                    defaultSkip={15}
                    pageSizes={[10, 15, 30]}
                    dataSource={dataSource}
                  />
        </div>
      );
  }

export default () => <ExamplePage />