olifolkerd / tabulator

Interactive Tables and Data Grids for JavaScript
http://tabulator.info
MIT License
6.74k stars 817 forks source link

Hide columns for download (PDF, EXCEL, CSV specific) #3806

Closed hitodev closed 2 years ago

hitodev commented 2 years ago

*Is your feature request related to a problem? Please describe.** The dowload:true options is global for all download types. I need to choose columns visibility, independently for each type of download (csv, excel, pdf...)

Describe the solution you'd like hide specific cols for PDF, hide specific cols for EXCEL, CSV etc. something like download_pdf:true, download_xls:true

Describe alternatives you've considered -- I tried to hide columns just before download : doesn't work -- Tried to update the col. definition with : table.updateColumnDefinition("reference", {download:false}); //change the download option -> doesnt work despite table.updateColumnDefinition("reference", {title:"New ref"}); //change the title on the name column works works fine

hitodev commented 2 years ago

Update: the only (heavy) way I found and working is to update all columns definition with table.setColumns(newColumnsPdf); just before table.download("pdf", "data.pdf"... and to reverse column definition to the default with table.setColumns(defaultColumns)

500Foods commented 2 years ago

Just thinking out loud here, would it be quicker or more feasible to create a new Tabulator table (and maybe keep it around) with these new column definitions and just copy the data from one Tabulator table to the other? Changing columns is an expensive thing, after all.

olifolkerd commented 2 years ago

Hey @hitodev,

Thanks for your suggestion, i would not be looking to take that approach to resolving your issue as it is a bit restricted in the scope that it fixes, and also wouldn't work in the scenario where someone is using custom downloader function.

What i have done is pushed an update to the 5.3 branch (that will be released in a few weeks) that will allow you to pass a callback to the download option that will be called when a download is triggered, that should return the boolean for column visibility. That way you can decide on each download weather a column is visible or not.

Cheers

Oli :)