Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

v1.1.0 datatable hidden_columns/exporting loses hidden headers when export_header='names' #546

Closed
laoxu0212 opened this issue Aug 14, 2019 · 3 comments · Fixed by #592
Closed
Assignees
Labels
dash-type-bug Something isn't working as intended dash-type-enhancement New feature or request size: 1
Milestone

Comments

@laoxu0212
Copy link

Hi there,

hidden_columns in 1.1.0 has really helped me a lot, however, here comes the question with exporting:

After using hidden_columns to hide some of the columns, I need to export data(no matter what is displayed after hiding several columns or the whole table).

It seems that the data of hidden columns will be exported anyway but the headers of them will not if I set export_headers='names'. It just leaves several data without headers.

I think the "ids" or the "names" should be same for the headers but the content, therefore, could I believe that there might be something wrong?

Here is a demo code to show that problem:

`import dash
import dash_table

app = dash.Dash(name)

app.layout = dash_table.DataTable(
id='table',
columns=[{"name": i, "id": i} for i in ['a', 'b', 'c', 'd']],
data=[{'a':1, 'b':1, 'c':1, 'd':1}, {'a':1, 'b':1, 'c':1, 'd':1},{'a':1, 'b':1, 'c':1, 'd':1},{'a':1, 'b':1, 'c':1, 'd':1}],
hidden_columns=['d'],
export_format='csv',
export_headers='names'
)

if name == 'main':
app.run_server(debug=True)`

And the csv looks like:
image

@Marc-Andre-Rivet
Copy link
Contributor

Fixing the default behavior to use visible columns for both data / headers.

A new prop export_columns will be added to allow exporting all the columns if desired. Value can be all or visible.

@laoxu0212
Copy link
Author

Thanks for your enhancement on #592
I think I might not have clarified the bug:

Currently all the columns will be exported.
If you choose export_headers='names' , only visible columns' headers will be shown.
This leaves some columns in CSV without headers.

If you choose export_headers='ids', all columns' headers will be shown.

"export_columns" mentioned in #592 (comment) is a great enhancement. But I'm afraid that if we don't set this property, we may still see some data columns without headers.

Here we got:
columns=[{"name": 'column-' + i, "id": 'column-' + i} for i in ['a', 'b', 'c', 'd']],
data=[{'column-a': 'a', 'column-b': 'b', 'column-c': 'c', 'column-d': 'd'}] * 3,
hidden_columns=['column-c'],
export_format='csv',
export_headers='names'

image

But here we got:
columns=[{"name": 'column-' + i, "id": 'column-' + i} for i in ['a', 'b', 'c', 'd']],
data=[{'column-a': 'a', 'column-b': 'b', 'column-c': 'c', 'column-d': 'd'}] * 3,
hidden_columns=['column-c'],
export_format='csv',
export_headers='ids'

image

At least I believe leaving columns without hears in exported file is not correct.

@Marc-Andre-Rivet
Copy link
Contributor

Marc-Andre-Rivet commented Sep 20, 2019

@laoxu0212 The changes in #592 should cover your current use case and be available in the v1.4.0 release. Sorry for not making that clear in my previous comment. With the fix, the columns and headers will match as expected, whether there are hidden columns or not. The additional prop is there to decide whether you want to export the hidden columns or not as both scenarios are considered valid.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dash-type-bug Something isn't working as intended dash-type-enhancement New feature or request size: 1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants