reactgrid icon indicating copy to clipboard operation
reactgrid copied to clipboard

copy-paste of numbers in numeric cells pastes a different number than the copied one.

Open Sturez opened this issue 11 months ago • 5 comments

Describe the bug When I copy-paste a number such as 990.06 from a notepad to a numeric cell, the number is very different. If I copy-paste from the grid itself, it works. I've tested also using the current development branch (column 0 - 3). Tested with version 4.1.13 and the problem is not there, it must be something specific of version 4.1.14.

Current behavior When we paste 990.06 we get -30 912 713 608 000,00 

Expected behavior A clear and concise description of what you expected to happen.

Screenshots or gifs

Image

Your environment details

  • Device: desktop
  • OS: Windows
  • Browser: chrome, edge

Sturez avatar Feb 20 '25 13:02 Sturez

I'm almost sure it's something with parseLocaleNumber function but I didn't quite nailed it. funny thing is that I have the very same issue when I'm pasting with ctrl+v, but context menu paste works fine. I am suspicious of locale parsing as I copied values from an excel that came from a customer from new Zealand, cause when I created an excel it works fine. but pasting to notepad or via context menu works as expected. Just ctrl + v behaves like OP described. also! as you can see in the video - my issue only occurs when a number is less than 1000 https://github.com/user-attachments/assets/c7d43ed2-7cba-451e-9639-cc6631a7c83d

https://github.com/user-attachments/assets/86f201de-3846-4c42-bd40-ccd12d103c5c

MateuszTrN avatar Mar 19 '25 07:03 MateuszTrN

@Sturez I confirm this bug too. Only works up to v 4.1.13. I have same behavior and hope the develops of this lib will fix this bug!

Morozov-it avatar Apr 09 '25 08:04 Morozov-it

ok, I have some new discovering regarding this. My suspicion is that if a pasted number can be interpreted as a Date - it will be somehow transformed to date number. I've created a small proof of this. this app has two inputs that if you copy one 4.31 - the paste will fail and will set some ridiculous number in the cell value, cause for some reason it will be interpreted as "31st of April" (which is already incorrect, and will return May 1st, but it is parsable) however anything that could not be interpreted as a Date it will work fine - so 4.32 could not be treated as date because no month has 32 days - so it will be interpreted as a number (as expected).

@webloopbox sorry if I'm mistaken but I'm guessing you're a maintainer of this repo? is there any doc/md how do you set up development env? so I could run it locally and debug some more maybe even do a fix? I'm pretty in hurry with this one

https://stackblitz.com/edit/vitejs-vite-mckpxusj?file=src%2FApp.tsx

EDIT: I think I found the issue: https://github.com/silevis/reactgrid/blob/eeef7ba9717bc9cd5781be592bfb8871810355dc/src/lib/Functions/handlePaste.ts#L44-L47

I'm not sure how to approach it though - to be honest the only thing that would cover probably most of use cases (but wouldn't be 100% bulletproof) - is to check if the pasted string has at least two "." - then try to parse it as excel date, if it's only one - prioritize parsing as a number.

MateuszTrN avatar Apr 14 '25 09:04 MateuszTrN

@MateuszTrN I will try to deal with this issue as quickly as possible. If you need to run version 4 of reactgrid locally, you should switch to the develop branch. Starting it is pretty simple, there are no extra steps needed.

webloopbox avatar Apr 14 '25 14:04 webloopbox

@MateuszTrN I will try to deal with this issue as quickly as possible. If you need to run version 4 of reactgrid locally, you should switch to the develop branch. Starting it is pretty simple, there are no extra steps needed.

yup,i figure the running part out, I just wasnt expecting it was THAT easy 🤣 anyway, I've set up a PR, it is A solution, but i'm not 100% it is THE solution. thanks for quick reply. let me know if i coule help.

MateuszTrN avatar Apr 14 '25 15:04 MateuszTrN