Hi everyone,
I'm trying to implement a Copy / Duplicate row feature in Data Grid Reactive.
I followed the solution from this forum post: https://www.outsystems.com/forums/discussion/72829/how-to-duplicate-data-grid-reactive-rows/
The functionality works partially:
If I manually drag and select the row (not using the checkbox), the copy happens correctly.
When I select the row using the checkbox, on selecting the first row, and then click the duplicate button, it adds just 1 row at the top, but if I select the ones below the first row, and duplicate, the grid always inserts two rows:
Here is my setup:
I use GetSelectedRowsData → JSON Deserialize → AddNewRows(1) → SetCellData for each column.
Debugging shows:
But visually the grid inserts two rows only when a checkbox is used.Has anyone seen this behavior before?
Thanks in advance!
Hi,
I figured out the cause of the bug: it happens when the focused row is different from the row selected via the checkbox.
The issue seems to come from the AddNewRows client action. I couldn’t determine the exact underlying reason, but I found a reliable workaround by adding the new row through JavaScript instead.
Instead of the client action you can use the following JS snippet:
Thank you @Mihai Melencu, works perfectly fine!Is there a way I can handle the same while sorting? If sort is enabled and then the row is duplicated, row might visually jump to a different position immediately after being added. Is there a way to handle it in a way that the added/duplicated row stays at the top of the Grid no matter what?
I tried several approaches, but none worked reliably.
If you use the AddNewRows client action, you won’t be able to add rows while the grid is sorted or filtered. My recommendation is to either prevent this situation by showing an error message, or prompt the user to clear sorting/filtering before adding a new row.