reactdatagrid icon indicating copy to clipboard operation
reactdatagrid copied to clipboard

💡 Wrong dragRowIndex and insertRowIndex are provided when reordering a grouped Table

Open marlonpp opened this issue 3 years ago • 6 comments

  • what edition are you using: enterprise
  • version for @inovua/reactdatagrid-enterprise: 4.1.27

What you did: Trying to reorder a grouped Table.

What happened: Wrong dragRowIndex and insertRowIndex are provided by the callback

Reproduction codesandbox: https://codesandbox.io/s/reactdatagrid-forked-nejhg?file=/src/App.js

Suggested solution: Provide the correct indexes or also provide the data for the element where it's being inserted.

marlonpp avatar Oct 01 '21 19:10 marlonpp

The documentation clearly says:

image

yurigenin avatar Oct 01 '21 19:10 yurigenin

confusing for whom? I believe this is a pretty valid use case. I would agree that the default reorder shouldn't work, but if I'm providing a function that will handle the reordering it should return the correct indexes.

marlonpp avatar Oct 01 '21 19:10 marlonpp

I'm not an author but a developer like you. I'm just referring you to the documentation. Instead of filing a bug report you probably need to file an enhancement request since the current implementation is by design (whether you like it or not).

yurigenin avatar Oct 01 '21 20:10 yurigenin

I'm not an author but a developer like you. I'm just referring you to the documentation. Instead of filing a bug report you probably need to file an enhancement request since the current implementation is by design (whether you like it or not).

done!

marlonpp avatar Oct 01 '21 20:10 marlonpp

found a workaround using the gridRef to grab the dropRow and from there get the correct index.

const onRowReorder = React.useCallback(
    ({ data: dragRow, insertRowIndex }) => {
      const dropRow = gridRef?.current?.getItemAt(insertRowIndex);
      const dropRowIndex = tableData.indexOf(dropRow);
      const dragRowIndex = tableData.indexOf(dragRow);

      if (dragRowIndex === dropRowIndex || dragRow.role !== dropRow.role) {
        // return in case it's a different group
        return;
      }
      reorderRows([...tableData], dragRowIndex, dropRowIndex)
    },
    [tableData]
  );

marlonpp avatar Oct 01 '21 23:10 marlonpp

another issue happens here: https://github.com/inovua/reactdatagrid/blob/master/enterprise-edition/EnterpriseColumnLayout.js#L391 where box could be undefined if there are groups since the index will be greater than the number of items in the array.

image

marlonpp avatar Oct 04 '21 21:10 marlonpp

Fixed in version 5.3.1.

inovua-admin avatar Oct 19 '22 07:10 inovua-admin