mui-x icon indicating copy to clipboard operation
mui-x copied to clipboard

[data grid] Commas in exported files are not handled correctly if value is in array

Open z0d14c opened this issue 2 years ago • 1 comments

Steps to reproduce

(Note: we are still on 6.x but as per the sandbox here it appears to happen in 7.x as well)

Link to live example: https://codesandbox.io/p/sandbox/cocky-haslett-kmw4hv?file=%2Fsrc%2FDemo.tsx%3A8%2C18

Steps:

  1. Have data that is in an array and has commas -- e.g. the value is ["Test1, Test2"]
  2. Use CSV export
  3. Notice that the outputted value takes up more columns than expected, messing up that row's column alignment

This is a case not handled by #1143

Current behavior

The outputted value takes up more columns than expected, messing up that row's column alignment

What you can do right now as a workaround is use the valueFormatter -- although this somewhat bothers me as it seems to potentially affect more than just the csv export functionaltiy e.g. you can do this:

            valueFormatter: ({ value, ...rest }) => {
              if (Array.isArray(value)) {
                return value.reduce((prev, curr) => {
                  return prev + curr
                }, '')
              }
              return value
            },

Expected behavior

Would be great if this worked as expected without the workaround of using valueFormatter

Context

We have values for our grid that are in arrays. These values can have strings with commas in them. We need to be able to export this data in a way that doesn't break columns.

Your environment

I don't know that this matters -- you can see that it occurs in the sandbox shared above.

Search keywords: commas, csv, export, arrays Order ID: 77204

z0d14c avatar Apr 29 '24 19:04 z0d14c

There is an option to use a different delimiter with the CSV export. Here is an updated example to showcase that: Delimiter change on CSV export

Does that help you?

michelengelen avatar Apr 30 '24 08:04 michelengelen

The issue has been inactive for 7 days and has been automatically closed.

github-actions[bot] avatar May 07 '24 15:05 github-actions[bot]

This "auto-close when inactive for 7 days" behavior seems a little odd... anyway, this is still an issue, but I've made a PR that fixes it.

See #13560

joeycumines-scw avatar Jun 20 '24 07:06 joeycumines-scw

The behavior of the auto-close is correct, it does that when there is no comment being added although we are waiting for the author of the ticket to answer.

It's that way because I did provide a solution, but no answer came back.

Thanks for opening a PR for this. I will assign a reviewer for that

michelengelen avatar Jun 20 '24 08:06 michelengelen

@michelengelen Your proposed solution isn't what I'm looking for, no. I haven't given it a deep review but I believe @joeycumines-scw's PR is what I had in mind as a solution

z0d14c avatar Jun 20 '24 08:06 z0d14c

In that case please say so ... how should we know otherwise? 🤷🏼

michelengelen avatar Jun 20 '24 08:06 michelengelen

:warning: This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue. Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@z0d14c: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

github-actions[bot] avatar Jun 20 '24 10:06 github-actions[bot]