nick-keller / react-datasheet-grid

An Airtable-like / Excel-like component to create beautiful spreadsheets.
MIT License
1.81k stars 171 forks source link

Add multiple rows causes blank space at the top of table #149

Open nick-keller opened 2 years ago

nick-keller commented 2 years ago

Discussed in https://github.com/Equify/react-datasheet-grid/discussions/144

Originally posted by **Richard-97** April 5, 2022 Hey, I have a problem with adding multiple rows. There is blank space at the top of the table. The same problem is happing int he demo at home page (added video). The problem is when you select more than 4 rows. Could you please look on this problem? Thank you. https://user-images.githubusercontent.com/42608419/161763345-daebffa6-9cb8-4d0b-bc35-9655c71cde4d.mov
superchow commented 2 years ago

It happen at onChange function

if (operation.type === 'CREATE') {
    const count = operation.toRowIndex - operation.fromRowIndex
    const addedRows = rows.slice(operation.fromRowIndex, operation.toRowIndex)
    if (!operation.fromRowIndex) {
      setRows([
        ...addedRows,
        ...rawRows.slice(operation.fromRowIndex),
      ])
      return
    }
   setRows([
      ...rawRows.slice(0, operation.fromRowIndex),
      ...addedRows,
      ...rawRows.slice(operation.fromRowIndex), 
   ])
}
otariterterashvili commented 1 year ago

Works fine for me.

Macbook: Firefox, Chrome