-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataGridPremium] Implement Clipboard import #7389
Conversation
Netlify deploy previewNetlify deploy preview: https://deploy-preview-7389--material-ui-x.netlify.app/ Updated pages
These are the results for the performance tests:
|
c529723
to
067838a
Compare
Thank you for making the prototype available; It feels quite solid, considering its early stage! A. When using Row selection(and Range selection too), I think we should paste the data to the selected rows. So instead of using the focused cell as a starting point, I'd try with the first visible cell on the top-most row (not the first selected necessarily). pasting.to.selected.rows.movB. I think the paste data should not leak out of a row or range selection. C. There's no way to copy a single selected row now that we're copying the focused cell on ctrl+v. Regarding the default copy behaviors, I think we could try the following:
p.s.: AG Grid pastes from the focused cell instead of selected rows (point A.) and leaks the pasted data out of the selection (point B.). But it doesn't feel ideal. We can try improving it. |
I missed an aspect of my suggestion: with row selection, if we identify that a single cell is going to be pasted, we paste it only to the focused cell. So regarding the default paste behaviors, I think we could try the following:
|
This comment was marked as outdated.
This comment was marked as outdated.
067838a
to
6e390e4
Compare
Otherwise, we'll not be able to paste them properly
d5bb992
to
79d0cde
Compare
To make it clear that it only affects paste operation
One more suggestions possibly to handle parsing percentages. Copying from excel value is With a mui This is my outside perspective on the issue so excuse me if this is not the correct place to comment. |
Hey @hamodey Screen.Recording.2023-05-11.at.14.42.37.movParsing different formats of numbers is very tricky - I've described this problem a bit in #7389 (comment) |
packages/grid/x-data-grid-premium/src/DataGridPremium/useDataGridPremiumProps.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
* The character used to separate cell values when copying to the clipboard. | ||
* @default '\t' | ||
*/ | ||
clipboardCopyCellDelimiter: PropTypes.string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Probably more relatable to unstable_splitClipboardPastedText
, also logically speaking we are delimiting the copied text (as a whole) not cells, right?
clipboardCopyCellDelimiter: PropTypes.string, | |
clipboardCopyTextDelimiter: PropTypes.string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this delimiter is only used for separating cell values in the row.
The rows are separated by the newline delimiter. It's not configurable at the moment, but I'm not even sure if anyone would ever want to change this.
### Format of the pasted data | ||
|
||
By default, the clipboard paste expects specific format of the clipboard content: the cell values should be separated by a tab (`\t`) character and the rows should be separated by a new line (`\n`) character. | ||
|
||
You can use the `unstable_splitClipboardPastedText` prop to support a different format: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Not sure but I'm under the impression that something like delimitClipboardCopiedText
instead of clipboardCopyCellDelimiter
would be:
- More aligned with the
unstable_splitClipboardPastedText
prop in terms of the interface - Will give slightly more control to the user to also be able to configure
row delimiter
(let's say\n
->Tab
) apart from thecell one
(like\t
->,
).
Feel free to drop the suggestion though.
Also, should we cover both aspects (copy and paste delimiters) in this section?
### Format of the pasted data | |
By default, the clipboard paste expects specific format of the clipboard content: the cell values should be separated by a tab (`\t`) character and the rows should be separated by a new line (`\n`) character. | |
You can use the `unstable_splitClipboardPastedText` prop to support a different format: | |
## Format of the clipboard data | |
By default, the clipboard copy and paste support this format for the clipboard content: the cell values will be separated by a tab (`\t`) character and the rows will be separated by a new line (`\n`) character. | |
You can use the `clipboardCopyTextDelimiter` prop to change the delimiter for clipboard copy and the `unstable_splitClipboardPastedText` prop to support a different format for clipboard paste |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm under the impression that something like delimitClipboardCopiedText instead of clipboardCopyCellDelimiter would be:
More aligned with the unstable_splitClipboardPastedText prop in terms of the interface
Initially, I wanted to add a callback prop for clipboard data serialization, but this would require deeper changes in the clipboard copy logic since it reuses the getDataAsCsv
method that returns a string, not raw data.
const data = apiRef.current.getDataAsCsv({ |
We can add it later if necessary, but I would expect that changing the row delimiter (\n
) to something else is super rare.
For the clipboard import, the main reason I decided to add the unstable_splitClipboardPastedText
callback is to potentially allow users to support both ,
and \t
as cell delimiters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we cover both aspects (copy and paste delimiters) in this section?
Good idea 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @cherniavskii 🙌 The feature looks great. I particularly like the demo showcasing what has been copied.
I see that Bilal has left a couple of suggestions but other than that I think we can release it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @cherniavskii 🙌 The feature looks great. I particularly like the demo showcasing what has been copied.
I see that Bilal has left a couple of suggestions but other than that I think we can release it.
Awesome feature 🔥 I have noticed 3 things that can be improved on the docs page:
It feels like I can act on this as a text, no I can't. Screen.Recording.2023-07-18.at.23.34.09.movI would expect |
Feedback moved to isolated GitHub issues: |
Closes #199
Preview: https://deploy-preview-7389--material-ui-x.netlify.app/x/react-data-grid/clipboard/#clipboard-paste
Changelog
🎁 Introduce clipboard paste support for
DataGridPremium
:clipboard-paste.mov
See the documentation for more information
TODO:
Reuse the same API as for editing -
processRowUpdate
formattedValue
to the clipboard - this would probably depend on the column typeThis is still unclear, because usually we want to copy formatted value, but then we have to parse it somehow 🤷🏻♂️
parseClipboardPasteValue
toGridColDef
?valueParser could be used (same as in Editing)
valueSetter
andvalueParser
in the docsdate
fields properlydateTime
fields properlypaste
not working in Firefox (TypeError: navigator.clipboard.readText is not a function
). Try usingdocument.addEventListener('paste')
instead