Skip to content
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

[DataGrid] Handle special chars when doing CSV export #1154

Merged
merged 7 commits into from
Mar 8, 2021

Conversation

DanailH
Copy link
Member

@DanailH DanailH commented Mar 3, 2021

Fixes #1143

@DanailH DanailH added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! labels Mar 3, 2021
@DanailH DanailH self-assigned this Mar 3, 2021
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • How about we add a test case that reproduce the issue? I think that we can test the function in isolatation. No need to mount the grid component.
  • What happens if there a double quote in the cell we are exporting? See http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm#FileFormat
  • Should we only add the " if there is a comma in order to save space in the CSV export?

@DanailH DanailH force-pushed the fix/DataGrid-1143-wrong-csv-parcer branch from 899537a to 2f067a1 Compare March 5, 2021 13:49
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the tests, I think that we can improve them:

  1. Only test the CSV exporter without the data grid. We will need to the same for the Excel exported.
  2. Cover edge cases you have considered but aren't tested. e.g. " inside the value of one cell.

What do you think?

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things I would have done differently if I was working on this:

  • In the tests, I would have used 2-dimensional data. Note one row, nor one column, but at least two columns and rows.
  • I would have split the problem into two phases. One phase about constructing the 2d data structure for export. And a second phase to convert this 2d structure into a CSV. Hopefully, this would bring two values. I suspect that the first phase would be shared with the Excel export. I also assume that it would allow, in the future to write unit tests that run much faster for covering more formatting edge-cases and more formating options, like custom delimiters.

@DanailH DanailH requested a review from dtassone March 8, 2021 10:06
@DanailH DanailH requested a review from dtassone March 8, 2021 15:16
@z0d14c
Copy link

z0d14c commented Apr 29, 2024

I started using mui x datagrid well after this was merged (end of 2023) and I still see the issue... I'm just curious what is the best way to check if the commit is in the version of mui x I'm using?

@z0d14c
Copy link

z0d14c commented Apr 29, 2024

On v6.16.0, I'm not seeing anything when I search git log --all --grep="82f3d84" ...

@z0d14c
Copy link

z0d14c commented Apr 29, 2024

hmm, nevermind, I found it by searching for the content of the commit:

commit 82f3d84
Author: Danail Hadjiatanasov [email protected]
Date: Mon Mar 8 17:14:56 2021 +0100

[DataGrid] Handle special chars when doing CSV export (#1154)

wonder why it isn't working -- we're still seeing screwed up exports when we have values with commas in them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] CSV export incorrect if cell data contains comma
4 participants