reactdatagrid
reactdatagrid copied to clipboard
💡 Wrong dragRowIndex and insertRowIndex are provided when reordering a grouped Table
- 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.
The documentation clearly says:
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.
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).
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!
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]
);
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.
Fixed in version 5.3.1
.