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] Control rendered field in CSV export #1145

Closed
2 tasks done
fanavarro opened this issue Mar 2, 2021 · 9 comments
Closed
2 tasks done

[DataGrid] Control rendered field in CSV export #1145

fanavarro opened this issue Mar 2, 2021 · 9 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@fanavarro
Copy link

Hi and thanks for your work, it is very useful.

I have been using the DataGrid component in an application for the last months. Now, I am trying to use the recently added CSV export functionality, but I am not sure about how to specify the render method for creating the CSV file.

Concretely, my data is formed by JSON objects, so I have to specify the 'valueGetter' prop when defining the columns in order to print a concrete field of my data in the DataGrid, and this works perfectly well. Now, I included the CSV export functionality as the documentation shows, and this adds the button for the CSV download. However, when I download the CSV, the cells contain the string "[object Object]".

I think there should be a property or something to specify a function to convert JSON object to the final CSV cell value, as someone recommended here, but I have been searching in the documentation and I have not found nothing relevant. What is the way to do this?

Thanks beforehand.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.
@oliviertassinari oliviertassinari transferred this issue from mui/material-ui Mar 2, 2021
@oliviertassinari oliviertassinari added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Mar 2, 2021
@dtassone dtassone added the bug 🐛 Something doesn't work label Mar 2, 2021
@oliviertassinari oliviertassinari added component: data grid This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information and removed bug 🐛 Something doesn't work status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 2, 2021
@oliviertassinari

This comment has been minimized.

@fanavarro
Copy link
Author

fanavarro commented Mar 2, 2021

Hi @oliviertassinari, thanks for your quick response! Sorry for not following the issue template, but I though this was a question more than a bug.
I have created a live example https://codesandbox.io/s/material-ui-issue-forked-d63me?file=/src/Demo.js. I've never used codesanbox before, I hope I created it well. In that code you have json objects as data, particularly brands, which have a name and a founder, and models, which have a name and a stock. I used the valueGetter prop when defining columns to select the name as the property to be printed in the table; however, if you export the CSV file, you will see [object Object] in all cells. I think this is due to it is trying to print the JSON object directly without applying the valueGetter function. My question is if there is a way to customize how the data is printed in the CSV file.

Thanks!

@oliviertassinari oliviertassinari removed the status: waiting for author Issue with insufficient information label Mar 2, 2021
@oliviertassinari oliviertassinari changed the title [DataGrid] how to render data when CSV export? [DataGrid] Control rendered field in CSV export Mar 2, 2021
@oliviertassinari
Copy link
Member

oliviertassinari commented Mar 2, 2021

@fanavarro Perfect, thanks for the reproduction.

@DanailH I think that it's a follow-up on the CSV work you have started. (1.) It does seem wrong that we are not using the output of valueGetter. I think that we could start there. It seems to be an easy win.

Regarding pushing the solution further. I didn't benchmark what the other data grid is doing regarding this matter. I imagine there is an opportunity to add many more options. I would be cautious, it might be best to move slowly here. It seems that (1.) is enough for this very problem.

@stevieg2123
Copy link

Somewhat on-topic with this: It would be great for the CSV export to respect valueFormatter in the output. We do some EPOCH conversions, as well as bool to Yes/No - CSV export is dumping the raw input (and encountering the comma issue, which massive +1 to the work on. #1143)

Let me know if you want me to punt this to a separate issue for tracking

@DanailH
Copy link
Member

DanailH commented Mar 5, 2021

@stevieg2123 thanks for raising this.

@oliviertassinari yes we need to address the problem with the valueGetter.

@oliviertassinari oliviertassinari added the new feature New feature or request label Mar 6, 2021
@fanavarro
Copy link
Author

I would suggest not only to apply the valueGetter but also to provide a way to control how the raw data is rendered in the final CSV file. For example, a developer could want to show the main aspects of the data in the online table, but he or she could want to include other things that are hidden in this table when exporting to CSV.

@oliviertassinari
Copy link
Member

@fanavarro I don't follow, this is exactly what this issue is about since it was opened. Why reinforce this point?

@fanavarro
Copy link
Author

Hi @oliviertassinari. Sorry, I though the planned solution would be to simply apply the valueGetter when exporting the CSV. Misunderstanding from my part, my apologies.

@m4theushw
Copy link
Member

m4theushw commented Jun 2, 2021

This was fixed in #1154 which is already included in the latest release.

I'll close this issue and move the discussion about #1145 (comment) to #1814 because it's the same use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants