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] Allow to remove column from CSV export #1435

Closed
1 task done
Neonin opened this issue Apr 19, 2021 · 12 comments · Fixed by #2008
Closed
1 task done

[DataGrid] Allow to remove column from CSV export #1435

Neonin opened this issue Apr 19, 2021 · 12 comments · Fixed by #2008
Assignees
Labels
component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@Neonin
Copy link
Contributor

Neonin commented Apr 19, 2021

  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

I would like to be able to customize whether I need to export some columns.

Examples 🌈

https://codesandbox.io/s/github/gregnb/mui-datatables?file=/examples/csv-export/index.js:678-686

Motivation 🔦

For example with action columns.

Order id 💳

19652

@Neonin Neonin added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 19, 2021
@dtassone dtassone added new feature New feature or request waiting for 👍 Waiting for upvotes and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Apr 19, 2021
@dtassone
Copy link
Member

dtassone commented Apr 19, 2021

As a workaround, you can already hide the columns you don't want to export.

We could add an exportable flag in the column definition 🤔

@Neonin
Copy link
Contributor Author

Neonin commented Apr 19, 2021

Thanks for the answer.
I think I misinterpreted the problem, the workaround doesn't work as I need to see this column, but not in the export file.

I will be grateful if you take this to work.

Снимок экрана от 2021-04-19 12-31-10

@DanailH
Copy link
Member

DanailH commented Apr 19, 2021

As a workaround, you can already hide the columns you don't want to export.

We could add an exportable flag in the column definition 🤔

That seems like the easiest solution with the least overhead.

@dtassone dtassone changed the title [DataGrid] Display column in download file. [DataGrid] Allow to mark a column as exportable Apr 19, 2021
@oliviertassinari
Copy link
Member

That seems like the easiest solution with the least overhead.

Is the pain frequent/important enough to have a dedicated prop? I don't think that have this information yet.

How about we aim for the most generic solution instead? Something that allows to gain full control of the exported content of the CSV? If we could also benchmark how the other grid are solving this problem, it could also yield information.

@Neonin
Copy link
Contributor Author

Neonin commented Apr 19, 2021

Also, I think that it would be more convenient to get a prop callback that would configure the export itself, the name of the export file, change the displayed data.

An example of the same library that I am using for this - mui-datatables with prop onDownload.

@oliviertassinari
Copy link
Member

@Neonin Agree, in the first iteration of the CSV feature, we went for the simplest solution with the smallest possible API surface, as we should have. This is what allows us to have conversions like this one, where developers report specific use cases.

@oliviertassinari oliviertassinari changed the title [DataGrid] Allow to mark a column as exportable [DataGrid] Allow to remove column from CSV export Apr 19, 2021
@dtassone
Copy link
Member

AgGrid just allows few options in their api. No panel.
https://www.ag-grid.com/react-grid/export/

Kendo has a component for export that can takes some columns and data
https://www.telerik.com/kendo-react-ui/components/grid/excel-export/

The aim of my solution was to take a pragmatic approach in order to fix the issue and unblock our users in brief delays. Then we could revisit this feature, and improve it slowly, incremental design.

IMO, we should fix the following for the first version.

  • unicode for export
  • allow users to customize the csv separator
  • allow users to choose which column to export

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 20, 2021

@dtassone So in the benchmark:

  1. AG Grid has a params for its export feature. Developers can, for instance, provide a list of columns they want to export.
  2. Kendo UI React use a save() method, with horrible documentation, wtf. But still, it shows that the configuration of the columns is important for them.
  3. material-table has a boolean on the column definition to exclude columns in the export and a transformation function.

I agree with the 3 pains you have listed. It sounds great to solve them.

Regarding the solution, 👍 for the solution of AG Grid. Have the export feature accept params. It could be both an argument in the apiRef and props in the toolbar export button.

@DanailH
Copy link
Member

DanailH commented Apr 23, 2021

Regarding the solution, 👍 for the solution of AG Grid. Have the export feature accept params. It could be both an argument in the apiRef and props in the toolbar export button.

I agree with this. That was always part of the initial discussion. Seems that there is a demand for it now. Also if we are to go with this we should add an option for devs to pass in their own delimiter.

@oliviertassinari oliviertassinari added the component: data grid This is the name of the generic UI component, not the React module! label Apr 27, 2021
@joziahg
Copy link

joziahg commented May 20, 2021

Chiming in, I would love to use the formatted value in exports. Maybe resolve it like column rendering:
valueFormatter() => string
valueGetter() => string
row[field]

@flaviendelangle
Copy link
Member

@DanailH you can already pass your own delimiter

If you call manually exportDataAsCsv :

apiRef!.current.exportDataAsCsv({ delimiter: ';' })

If you use GridToolbarExport :

return (
  <GridToolbarExport
    csvOptions={{ delimiter: ';' }}
  />
) 

But this is not correctly documented.

@flaviendelangle flaviendelangle removed the waiting for 👍 Waiting for upvotes label Jul 7, 2021
@manoharreddyporeddy
Copy link

Solution is to use:

disableExport: true

Example:

<DataGrid columns={[{ field: 'name', disableExport: true }, { field: 'brand' }]} />

More details at:

https://mui.com/x/react-data-grid/export/

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

Successfully merging a pull request may close this issue.

7 participants