nick-keller / react-datasheet-grid

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

Unable to paste on disabled cells #315

Open akshaytanikatech opened 1 year ago

akshaytanikatech commented 1 year ago

Yes i know you cannot paste on disabled cells, but in my scenario i've set up that "B column" should be disable until "A column" has any value in it, so whenever user pastes a row which includes both values, only "A column" value gets pasted.

Does any know any work way around?

hussamkhatib commented 1 year ago

It already works as you mentioned. Focus on a column A cell and paste the 2 values. Column A is changed to the first value of the pasted word, while Column B, the disabled column remains unchanged.

You can conditionall disable or enable columns based on the whether the value is present in Column A or not. https://react-datasheet-grid.netlify.app/docs/api-reference/columns/#disabled

akshaytanikatech commented 1 year ago

Thanks for reply,

I've a lot of columns in my sheet, In which there are some columns depends on other columns, until if they have any values in it will stays disable, So as specified in above example if user puts any value in "A column" the "B column" will become visible. But when i paste whole row, only visible columns the data gets pasted, and the disabled values don't, (they gets visible though because their depend column now has values).

Here is an example, try to copy first row and paste it on second, only visible cells will get pasted not the last name because it was disabled earlier

https://codesandbox.io/s/xenodochial-borg-yjp72c?file=/src/App.tsx

hussamkhatib commented 1 year ago

You can make use of pasteValue callback in that column https://react-datasheet-grid.netlify.app/docs/api-reference/columns/#pastevalue

https://codesandbox.io/s/romantic-ardinghelli-k843sk?file=/src/App.tsx

I am not sure why it takes two attemps of pasting to get the desired result. i.e pasteValue is getting called when I paste it twice on Column A. Hope that helps